Skip to content

Commit ac0c1c7

Browse files
Merge pull request #20 from DatavenueLiveObjects/update
Update package
2 parents 919d489 + 65698f0 commit ac0c1c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+954
-53
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# Prototype with Orange using Live Objects and Arduino MKR Boards
1+
# Quickly prototype IoT solutions with Orange using Live Objects and Arduino compatible boards
22

3-
### Discover Orange [**Live Objects**](https://liveobjects.orange-business.com) using dedicated SDK for [**Arduino MKR family boards**](https://store.arduino.cc/arduino-genuino/arduino-genuino-mkr-family).
3+
### Discover [**Live Objects**](https://liveobjects.orange-business.com), the IoT platform from Orange using this dedicated SDK for [**Arduino**](https://store.arduino.cc/arduino-genuino/arduino-genuino-mkr-family) and compatible boards.
44

5-
This code wraps all the functions necessary to make your object work with Live Objects.
5+
This dedicated SDK simplifies connecting your MKR board to the Live Objects platform. It manages LTE-M, GSM, and WiFi connections (depending on your board) and handle MQTT(S) and SMS communication behind the scenes. Easily define parameters you can update remotely and create commands to trigger actions on your device.
66

7-
You can declare parameters, which you can later update OTA from Live objects. You can also create commands to trigger actions remotely.
8-
9-
The code will manage the LTE-M, GSM and WiFi connection (depending on currently used board), as well MQTT(S) and SMS exchanges with Live objects under the hood to keep your parameters up to date or execute the commands received without you having to take care of them (apart from writing the code of these commands, of course).
7+
Focus on your application logic – this library handles the communication with the Live Objects platform, keeping your parameters synchronized and executing received commands.
108

119
## Compatibility ##
1210
| Board | MQTT | MQTTS | SMS |
@@ -36,7 +34,8 @@ This code needs external libraries to run, that you can install using the built-
3634
- [PubSubClient](https://pubsubclient.knolleary.net/) library provides a client for doing simple publish/subscribe messaging with a server that supports MQTT
3735

3836
#### Library developed by Benoît Blanchon (mandatory for both Arduino, ESP and Adafruit boards)
39-
- [ArduinoJson](https://arduinojson.org/), a powerful library used to parse, store and handle JSON easily
37+
- [ArduinoJson](https://arduinojson.org/), a powerful library used to parse, store and handle JSON easily.
38+
The default installation includes ArduinoJSON v6.21.5, optimized for the architectures supported by this SDK. While later versions of ArduinoJSON are compatible, they will consume more flash memory (see [here](https://arduinojson.org/news/2024/01/03/arduinojson-7/)).
4039

4140
#### SAMD21 Arduino core
4241
- You also need to install the Arduino core for Atmel SAMD21 processor, used on the boards of the MKR family. Open the [Boards Manager](https://www.arduino.cc/en/guide/cores) and install the package called "Arduino SAMD Boards (32-bit ARM Cortex-M0+)".
@@ -47,7 +46,7 @@ This code needs external libraries to run, that you can install using the built-
4746
2. Create an [API key](https://liveobjects.orange-business.com/#/administration/apikeys) for your device. Give it a name, select the *Device access* role and validate. Copy the key.
4847
3. Clone or download the directory from Github.
4948
4. In the **'src/arduino_secrets.h'** file :
50-
- Paste it as initialization value for the `SECRET_LIVEOBJECTS_API_KEY` variable in the 'arduino_secrets.h' file -keep the double quotes!
49+
- Paste it as initialization value for the `SECRET_LIVEOBJECTS_API_KEY` variable in the 'arduino_secrets.h' file keep the double quotes!
5150

5251
- In case of feather 32u4 you have to change type of this variable to *char** from *String*.
5352
- Fill in the connection(WIFI or GSM) credentials if needed (pin code, APN information, etc). In case of GSM connection, most of the time, APN will set up automatically. Your SIM card may have a default pin code (like "0000"), unless you deactivated it using the [Pin management](https://github.com/arduino-libraries/MKRNB/blob/master/examples/Tools/PinManagement/PinManagement.ino) sketch, provided with the MKRNB library.

keywords.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,33 @@ enableDebug KEYWORD2
1414
setClientID KEYWORD2
1515
setDecoder KEYWORD2
1616
setModel KEYWORD2
17-
debugEnabled KEYWORD2
17+
debugEnabled KEYWORD2
1818
addTimestamp KEYWORD2
1919
addLocation KEYWORD2
2020
addNetworkInfo KEYWORD2
21+
addTags KEYWORD2
2122
addPowerStatus KEYWORD2
2223
clearPayload KEYWORD2
2324
publishMessage KEYWORD2
2425
networkCheck KEYWORD2
2526
addCommand KEYWORD2
26-
addParameter KEYWORD2
27-
addToPayload KEYWORD2
28-
addObjectToPayload KEYWORD2
29-
connect KEYWORD2
27+
addParameter KEYWORD2
28+
addToPayload KEYWORD2
29+
addObjectToPayload KEYWORD2
30+
connect KEYWORD2
3031
disconnect KEYWORD2
3132
sendData KEYWORD2
32-
loop KEYWORD2
33-
begin KEYWORD2
34-
changeConfiguration KEYWORD2
33+
loop KEYWORD2
34+
begin KEYWORD2
35+
changeConfiguration KEYWORD2
3536

3637

3738
######################################
3839
# Constants (LITERAL1)
3940
######################################
40-
NONE LITERAL1
41-
TLS LITERAL1
42-
SMS LITERAL1
43-
MQTT LITERAL1
44-
BINARY LITERAL1
45-
TEXT LITERAL1
41+
NONE LITERAL1
42+
TLS LITERAL1
43+
SMS LITERAL1
44+
MQTT LITERAL1
45+
BINARY LITERAL1
46+
TEXT LITERAL1

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name=LiveObjectsSDK
2-
version=2.1.1
2+
version=2.1.2
33
author=Orange
44
maintainer=Marc Delain <[email protected]>, Krzysztof Krzeslak <[email protected]>, Tomasz Malek <[email protected]>
5-
sentence=A library that makes connection with Orange LiveObjects platform a breeze.
6-
paragraph=Supports connection with LiveObjects platform in device mode, with the use of LTE, GSM or WifI connectivity.
5+
sentence=A library that simplifies the integration of Arduino boards with Live Objects, the IoT platform from Orange.
6+
paragraph=Upgrade your Arduino projects to IoT with this library, which allows you to easily connect your board to the Live Objects platform: send data, remotely modify execution parameters, or send commands to interact with your board.
77
category=Communication
88
url=https://github.com/DatavenueLiveObjects/LiveObjects_SDK_for_Arduino
99
architectures=*
1010
includes=LiveObjects.h
11-
depends=WiFiNINA,MKRNB,ArduinoJson,MKRGSM,WiFi101,PubSubClient,ArduinoMqttClient,SparkFun VL6180 Sensor
11+
depends=WiFiNINA,MKRNB,ArduinoJson(=6.21.5),MKRGSM,WiFi101,PubSubClient,ArduinoMqttClient,SparkFun VL6180 Sensor

src/LiveObjectsBase.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LiveObjectsBase::LiveObjectsBase()
1111
lastKeepAliveNetwork(5000)
1212
,m_sPayload()
1313
,m_sDecoder()
14-
,m_sModel("Orange")
14+
,m_sModel(F(SW_MODEL))
1515
,m_Security(NONE)
1616
,m_bDebug(false)
1717
,m_bInitialized(false)
@@ -31,12 +31,12 @@ void LiveObjectsBase::paramTyper(const String& name, bool* variable, LiveObjects
3131
else
3232
addTypedParam(name, variable, type, T_BOOL, callback);
3333
}
34-
void LiveObjectsBase::paramTyper(const String& name, char* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback) {
34+
/*void LiveObjectsBase::paramTyper(const String& name, char* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback) {
3535
if (type == IMPLICIT)
3636
addTypedParam(name, variable, INTEGER, T_CHAR, callback);
3737
else
3838
addTypedParam(name, variable, type, T_CHAR, callback);
39-
}
39+
}*/
4040
#if not defined ESP8266 && not defined ESP32 && not defined ARDUINO_AVR_FEATHER32U4
4141
void LiveObjectsBase::paramTyper(const String& name, int* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback) {
4242
if (type == IMPLICIT)
@@ -111,9 +111,9 @@ void LiveObjectsBase::ptrTyper(const LiveObjects_parameter param, const JsonDocu
111111
case T_BOOL:
112112
updateParameter(param, (bool*)param.value, configIn, configOut);
113113
break;
114-
case T_CHAR:
114+
/* case T_CHAR:
115115
updateParameter(param, (char*)param.value, configIn, configOut);
116-
break;
116+
break;*/
117117
#ifndef ESP8266
118118
case T_INT:
119119
updateParameter(param, (int*)param.value, configIn, configOut);
@@ -301,7 +301,7 @@ void LiveObjectsBase::sendData(const String customPayload) {
301301
{
302302
StaticJsonDocument<PAYLOAD_DATA_SIZE> payload;
303303
deserializeJson(payload, customPayload);
304-
if (!payload.containsKey(JSONMODEL)) payload[JSONMODEL] = m_sModel;
304+
if (!payload[JSONMODEL].is<const char*>()) payload[JSONMODEL] = m_sModel;
305305
publishMessage(m_sTopic, payload);
306306
}
307307
else publishMessage(m_sTopic, const_cast<String&>(customPayload));
@@ -425,6 +425,13 @@ void LiveObjectsBase::addLocation(double lat, double lon, double alt)
425425
else addToStringPayload(lat,lon,alt);
426426
}
427427

428+
void LiveObjectsBase::addTag(const char* tag)
429+
{
430+
if (!easyDataPayload[JSONTAGS].is<JsonArray>())
431+
tags = easyDataPayload.createNestedArray(JSONTAGS);
432+
tags.add(tag);
433+
}
434+
428435
void LiveObjectsBase::clearPayload()
429436
{
430437
easyDataPayload.clear();

src/LiveObjectsBase.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
******************************************************************************/
1313
#define PAYLOAD_DATA_SIZE 1024
1414
#define KEEP_ALIVE_NETWORK 1000
15-
#define SW_REVISION "2.1.1"
16-
15+
#define SW_MODEL "LO_SDK_Arduino"
16+
#define SW_REVISION "2.1.2"
1717

1818
/******************************************************************************
1919
LiveObjects MQTT constants
@@ -24,7 +24,7 @@
2424
#else
2525
#define MQTT_BROKER "liveobjects.orange-business.com"
2626
#endif
27-
#define SDK_PREFIX "urn:lo:nsid:Arduino:"
27+
#define SDK_PREFIX SW_MODEL ":"
2828
#define MQTT_USER "json+device"
2929
#define MQTT_PUBDATA "dev/data"
3030
#define MQTT_PUBDATA_BINARY "dev/v1/data/binary"
@@ -42,6 +42,8 @@
4242
#define JSONCFGTYPE "t"
4343
#define JSONMODEL "model"
4444
#define JSONVALUE "value"
45+
#define JSONTAGS "tags"
46+
4547
/******************************************************************************
4648
INCLUDES
4749
******************************************************************************/
@@ -176,6 +178,7 @@ class LiveObjectsBase
176178
public:
177179
void addTimestamp(time_t timestamp);
178180
void addLocation(double lat, double lon, double alt);
181+
void addTag(const char* tag);
179182
virtual void addPowerStatus()=0;
180183
virtual void addNetworkInfo()=0;
181184
void clearPayload();
@@ -215,7 +218,6 @@ class LiveObjectsBase
215218
virtual void sendMQTT(String& topic, String& doc)=0;
216219
virtual void deserializeMessage(JsonDocument& doc)=0;
217220

218-
219221
protected:
220222
/******************************************************************************
221223
CONFIGURATION MANAGER
@@ -260,6 +262,8 @@ class LiveObjectsBase
260262
LinkedList<LiveObjects_parameter> parameters;
261263
LiveObjects_networkStatus networkStatus = DISCONNECTED;
262264
StaticJsonDocument<PAYLOAD_DATA_SIZE> easyDataPayload;
265+
JsonArray tags;
266+
263267
/******************************************************************************
264268
VARIABLES
265269
******************************************************************************/
@@ -285,12 +289,12 @@ class LiveObjectsBase
285289
PARAM TYPERS
286290
******************************************************************************/
287291
void paramTyper(const String& name, bool* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
288-
void paramTyper(const String& name, char* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
292+
// void paramTyper(const String& name, char* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
289293
#if not defined ESP8266 && not defined ESP32 && not defined ARDUINO_AVR_FEATHER32U4
290294
void paramTyper(const String& name, int* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
291295
void paramTyper(const String& name, unsigned int* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
292296
#endif
293-
void paramTyper(const String& name, int8_t*variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
297+
void paramTyper(const String& name, int8_t* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
294298
void paramTyper(const String& name, int32_t* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
295299
void paramTyper(const String& name, int16_t* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);
296300
void paramTyper(const String& name, uint8_t* variable, LiveObjects_parameterType type, onParameterUpdateCallback callback);

src/LiveObjectsCellular.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void LiveObjectsCellular::connectNetwork()
102102
#endif
103103
if(modem.begin())
104104
{
105-
String imei="";
105+
String imei="imei:";
106106
for(int i=1;i<=3;i++)
107107
{
108108
imei=modem.getIMEI();

src/LiveObjectsWiFi.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void LiveObjectsWiFi::begin(Protocol p, Encoding s, bool bDebug)
5353
void LiveObjectsWiFi::connectNetwork()
5454
{
5555
#ifdef ADAFRUIT_FEATHER_M0
56-
WiFi.setPins(8,7,4,2);
56+
WiFi.setPins(8,7,4,2);
5757
#endif
5858
if(!m_bInitialized)
5959
{
@@ -81,15 +81,17 @@ void LiveObjectsWiFi::connectNetwork()
8181
outputDebug(TXT,".");
8282
delay(1000);
8383
}
84-
outputDebug();
84+
outputDebug();
8585
IPAddress ip = WiFi.localIP();
8686
for(int i=0;i<4;++i)
8787
{
8888
m_sIP+=ip[i];
8989
if(i!=3) m_sIP+='.';
9090
}
9191

92-
uint8_t mac[6];
92+
m_sMqttid+= "mac:";
93+
94+
uint8_t mac[6];
9395
char buff[10];
9496
WiFi.macAddress(mac);
9597

@@ -107,37 +109,35 @@ void LiveObjectsWiFi::connectNetwork()
107109
m_sMac += (char)toupper(buff[j]);
108110
m_sMqttid += (char)toupper(buff[j]);
109111
}
110-
if(i!=0) m_sMac += ':';
112+
if(i!=0) m_sMac += ':';
111113
}
112-
m_sModel = m_sMqttid;
113114
}
115+
114116
void LiveObjectsWiFi::checkNetwork()
115117
{
116118
if(WiFi.status()== WL_DISCONNECTED)
117119
connectNetwork();
118120
}
121+
119122
void LiveObjectsWiFi::disconnectNetwork()
120123
{
121124
outputDebug(INFO,"Disconnecting WiFi");
122125
WiFi.disconnect();
123126
}
127+
124128
void LiveObjectsWiFi::messageCallback(int msg)
125129
{
126130
LiveObjects::get().onMQTTmessage(msg);
127131
}
128132

129-
130-
131-
132-
133-
134-
135133
void LiveObjectsWiFi::addNetworkInfo()
136134
{
137135
String tmp;
138-
tmp = WiFi.RSSI();
136+
tmp = String(WiFi.RSSI());
139137
tmp += " dbm";
140-
if(m_Protocol == MQTT && m_Encoding==TEXT) addToPayload(easyDataPayload[JSONVALUE].createNestedObject("networkInfo"),"mac",m_sMac,"ssid",SECRET_SSID,"ip",m_sIP,"strength",tmp);
141-
else addToPayload(m_sMac,SECRET_SSID,m_sIP,tmp);
138+
if(m_Protocol == MQTT && m_Encoding==TEXT)
139+
addToPayload(easyDataPayload[JSONVALUE].createNestedObject("networkInfo"),"mac",m_sMac,"ssid",SECRET_SSID,"ip",m_sIP,"rssi",tmp);
140+
else
141+
addToPayload(m_sMac,SECRET_SSID,m_sIP,tmp);
142142
}
143143
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/******************************************************************************
2+
INCLUDES
3+
******************************************************************************/
4+
#include "arduino_secrets.h"
5+
#include <LiveObjects.h>
6+
/******************************************************************************
7+
USER VARIABLES
8+
******************************************************************************/
9+
uint32_t messageRate = 15000; // stores the current data message rate in Milliseconds
10+
unsigned long uptime; // stores the device uptime (sent as fake sensor data)
11+
unsigned long lastMessageTime = 0; // stores the time when last data message was sent
12+
13+
/******************************************************************************
14+
USER PROGRAM
15+
******************************************************************************/
16+
void setup() {
17+
delay(2000);
18+
Serial.begin(9600);
19+
Serial.print("\n*** Live Objects SDK for Arduino, revision ");
20+
Serial.print(SW_REVISION);
21+
Serial.println(" ***\n");
22+
lo.setSecurity(TLS);
23+
lo.begin(MQTT, TEXT, true);
24+
lo.connect(); // connects to the network + Live Objects
25+
}
26+
27+
void loop() {
28+
if (millis() - lastMessageTime > messageRate) {
29+
// collect data periodically
30+
Serial.println("Sampling data");
31+
uptime = millis();
32+
lo.addToPayload("uptime", uptime); // adding 'uptime' value to the current payload
33+
Serial.println("Sending data to Live Objects");
34+
lo.sendData(); // send the data to Live Objects
35+
lastMessageTime = millis();
36+
}
37+
lo.loop(); // don't forget to keep this in your main loop
38+
}

src/examples/1_send_data/README.md

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 = "";

0 commit comments

Comments
 (0)