@@ -12,8 +12,8 @@ uint32_t messageRate = 5000; // stores the current data message rate in Millis
1212unsigned long lastMessageTime = 0 ; // stores the time when last data message was sent
1313
1414VL6180x sensor (VL6180X_ADDRESS);
15- char ambient_light[20 ]; // ambient light level [lx]
1615u_int8_t distance; // distance from obstruction [mm]
16+ float ambient_light; // ambient light [lx]
1717
1818/* *****************************************************************************
1919 USER PROGRAM
@@ -27,7 +27,7 @@ void setup() {
2727 Serial.print (SW_REVISION);
2828 Serial.println (" ***" );
2929 lo.setSecurity (TLS);
30- lo.begin (MQTT, TEXT , true );
30+ lo.begin (MQTT, BINARY , true );
3131 lo.connect (); // connects to the network + Live Objects
3232}
3333
@@ -37,10 +37,10 @@ void loop() {
3737 Serial.println (" Sampling data" );
3838
3939 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-
40+ lo.addToPayload (distance); // adding 'distance' value to the current payload
41+ ambient_light = ( static_cast < int >( sensor.getAmbientLight (GAIN_1) * 100.0 )) / 100.0 ;
42+ lo.addToPayload (ambient_light);
43+
4444 Serial.println (" Sending data to Live Objects" );
4545 lo.sendData (); // send the data to Live Objects
4646 lastMessageTime = millis ();
0 commit comments