kpn-iot / thingsml-c-library

C library for ThingsML on your device
https://kpn-iot.github.io/thingsml-c-library/
MIT License
6 stars 4 forks source link

ESP8266 - unexpected behaviour when parsing to JSON. #6

Closed FlorSanders closed 3 years ago

FlorSanders commented 4 years ago

Compiling the sketch below for the ESP8266-based NodeMCU 1.0, the output on the serial output looks as follows:

[{"i_":-24, "v":24.0}]

I'm guessing something goes wrong when parsing the name, because what I'd expect to see was:

[{"n":"temperature", "v":24.0}]

Or some output more along those lines.

#include <thingsml.h>

SenMLPack device;

SenMLDoubleRecord temperature(THINGSML_TEMPERATURE);

void setup() {
    Serial.begin(9600);
    device.add(temperature);
}

void loop(){
  delay(1000);
    int val = 24;  
    temperature.set(val);
    device.toJson(Serial);        //print to screen
    Serial.println();
}
josephverburg commented 3 years ago

You are using the THINGSML value, this uses the more space efficient "i_" notation. Also see here: https://docs.kpnthings.com/dm/processing/thingsml

To use a name you can use SENML_NAME_TEMPERATURE instead, see all options here: https://github.com/kpn-iot/thingsml-c-library/blob/master/src/senml/senml_enums.h#L156

FlorSanders commented 3 years ago

Oh okay, my bad. Maybe this could be mentioned a bit more clearly in the documentation. Anyways, thanks for the reply!