Skip to content

Commit d43bbf5

Browse files
committed
Initial code
1 parent 9dbc535 commit d43bbf5

File tree

6 files changed

+165
-1
lines changed

6 files changed

+165
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/******************************************************************************
2+
INCLUDES
3+
******************************************************************************/
4+
#include "arduino_secrets.h"
5+
#include <LiveObjects.h>
6+
#include "ExtDevices.h"
7+
8+
/******************************************************************************
9+
USER VARIABLES
10+
******************************************************************************/
11+
uint32_t messageRate = 5000; // stores the current data message rate in Milliseconds
12+
unsigned long lastMessageTime = 0; // stores the time when last data message was sent
13+
14+
VL6180x sensor(VL6180X_ADDRESS);
15+
char ambient_light[20]; // ambient light level [lx]
16+
u_int8_t distance; // distance from obstruction [mm]
17+
18+
/******************************************************************************
19+
USER PROGRAM
20+
******************************************************************************/
21+
void setup() {
22+
Serial.begin(115200);
23+
24+
VL6180XInit(); // initialization of VL6180X sensor
25+
26+
Serial.print("\n*** Live Objects for Arduino MKR boards, revision ");
27+
Serial.print(SW_REVISION);
28+
Serial.println(" ***");
29+
lo.setSecurity(TLS);
30+
lo.begin(MQTT, TEXT, true);
31+
lo.connect(); // connects to the network + Live Objects
32+
}
33+
34+
void loop() {
35+
if (millis() - lastMessageTime > messageRate) {
36+
// collect data periodically
37+
Serial.println("Sampling data");
38+
39+
distance = sensor.getDistance();
40+
lo.addToPayload("distance", distance); // adding 'distance' value to the current payload
41+
sprintf(ambient_light, "%.2f", sensor.getAmbientLight(GAIN_1));
42+
lo.addToPayload("ambient_light", ambient_light); // adding 'ambient_light' value to the current payload
43+
44+
Serial.println("Sending data to Live Objects");
45+
lo.sendData(); // send the data to Live Objects
46+
lastMessageTime = millis();
47+
}
48+
lo.loop(); // don't forget to keep this in your main loop
49+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Send data to Live Objects
2+
3+
This example shows how to send some sample data (device uptime) to Live Objects using Arduino MKR NB 1500.
4+
![diagram](img/send_data_diagram.png)
5+
6+
## Running
7+
First of all, be sure that you installed the required libraries and generated an API key mentioned in the main README file, then:
8+
1. Open "1_send_data.ino" sketch using Arduino IDE
9+
2. Replace ```const char SECRET_LIVEOBJECTS_API_KEY[]="...";``` in arduino_secrets.h with API key you generated
10+
3. In ```lo.setSecurity()``` select security mode using ```TLS``` or ```NONE``` according to board abilities shown in **Compatibility** point in main **README.md**
11+
4. Upload *1_send_data.ino* sketch to your Arduino MKR NB 1500 board
12+
13+
14+
## Verify
15+
**Is device online:**<br>
16+
If all went fine under **devices** tab on Live Live Objects portal you should see online your device identified by its modem IMEI:
17+
18+
![device_online](img/device_online.png)
19+
20+
**Is device sending data:**<br>
21+
Under data tab on Live Objects portal you should see messages sent by your device, along with values *{ "uptime": xxxxx }*
22+
23+
![data_portal](img/data_portal.png)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Cellular connection cerdentials, used only for GSM boards
2+
extern const String SECRET_PINNUMBER = ""; // unless PIN is deactivated, specify your SIM card PIN number
3+
extern const String SECRET_APN = ""; // specify the APN name (if needed)
4+
extern const String SECRET_APN_USER = ""; // specify the username for your APN (if needed)
5+
extern const String SECRET_APN_PASS = ""; // specify the password for your APN (if needed)
6+
extern const String SECRET_SERVER_MSISDN = ""; // specify the number of server(gate)
7+
8+
// WIFI connection credentials, used only for WiFi boards
9+
extern const String SECRET_SSID = ""; // unless PIN is deactivated, specify your SIM card PIN number
10+
extern const String SECRET_WIFI_PASS = ""; // specify the APN name (if needed)
11+
12+
// Live Objects credential: paste below your API key (see Configuration > API keys on the portal).
13+
// You API key must have at least the predefined 'MQTT Device' rights profile
14+
// (alternatively: 'Device Access' read + write rights if need to customise the rights).
15+
// Please note that you *must* use a TLS connection (MQTTS) if you grant more rights to the API key.
16+
extern const String SECRET_LIVEOBJECTS_API_KEY = "...";

src/ExtDevices.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) Orange
3+
*
4+
* This software is distributed under the terms and conditions of the 'MIT'
5+
* license which can be found in the file 'LICENSE.md' in this package distribution
6+
*/
7+
8+
#include "ExtDevices.h"
9+
10+
VL6180xIdentification identification;
11+
12+
13+
void VL6180XInit()
14+
{
15+
VL6180x sensor(VL6180X_ADDRESS);
16+
Wire.begin(); // Start I2C library
17+
delay(1500); // delay 1.5s
18+
19+
sensor.getIdentification(&identification); // Retrieve manufacture info from device memory
20+
printVL6180xIdentification(&identification); // Helper function to print all the Module information
21+
22+
if (sensor.VL6180xInit() != 0)
23+
{
24+
Serial.println("Failed to initialize VL6180X sensor. Freezing..."); // Initialize device and check for errors
25+
while (1)
26+
;
27+
}
28+
sensor.VL6180xDefautSettings(); // Load default settings to get started.
29+
delay(1000); // delay 1s
30+
}
31+
32+
void printVL6180xIdentification(struct VL6180xIdentification *temp)
33+
{
34+
Serial.println("VL6180X sensor");
35+
36+
Serial.print("Model ID = ");
37+
Serial.println(temp->idModel);
38+
39+
Serial.print("Model Rev = ");
40+
Serial.print(temp->idModelRevMajor);
41+
42+
Serial.println(temp->idModelRevMinor);
43+
44+
Serial.print("Module Rev = ");
45+
Serial.print(temp->idModuleRevMajor);
46+
47+
Serial.println(temp->idModuleRevMinor);
48+
49+
Serial.print("Manufacture Date = ");
50+
Serial.print((temp->idDate >> 3) & 0x001F);
51+
Serial.print("/");
52+
Serial.print((temp->idDate >> 8) & 0x000F);
53+
Serial.print("/1");
54+
Serial.print((temp->idDate >> 12) & 0x000F);
55+
Serial.print(" Phase: ");
56+
Serial.println(temp->idDate & 0x0007);
57+
58+
Serial.print("Manufacture Time (s)= ");
59+
Serial.println(temp->idTime * 2);
60+
Serial.println();
61+
// Serial.println();
62+
}

src/ExtDevices.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) Orange
3+
*
4+
* This software is distributed under the terms and conditions of the 'MIT'
5+
* license which can be found in the file 'LICENSE.md' in this package distribution
6+
*/
7+
8+
#include <Wire.h>
9+
#include <SparkFun_VL6180X.h>
10+
11+
#define VL6180X_ADDRESS 0x29
12+
13+
void VL6180XInit();
14+
void printVL6180xIdentification(struct VL6180xIdentification *temp);

src/LiveObjectsBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
******************************************************************************/
1313
#define PAYLOAD_DATA_SIZE 1024
1414
#define KEEP_ALIVE_NETWORK 1000
15-
#define SW_REVISION "2.0.4"
15+
#define SW_REVISION "2.1.0"
1616

1717

1818
/******************************************************************************

0 commit comments

Comments
 (0)