Hello,

 

I was curious as to how can I achieve the following task:

1. I am trying to send data in SenML format  where I would like to send sensor information every 2 seconds. Within the two seconds the different sensors (temperature, humidity) keep collecting infomration and store it in an array and then at two seconds this array is sent to a MQTT Broker.

[
    {
       "bn": "urn:dev:ow:MACAddressOfNode,
       "n": "temperature",
       "u": "C",
       "v": 23.4
    },
    {
       "n": "humidity",
        "u": "bar",
        "v": 1.0
    }
]

I currently can only hardcode a single JSON structure in the AppController.c (AppControllerFire)

0 (0 Votes)
RE: Send an Array of information in SendDataOverMQTT Example
Answer
12/18/18 3:57 PM as a reply to Shantanoo Desai.
Hello Shantanoo,

First of all, I would like to welcome you to the XDK community.

It is indeed possible to send sensor data in with the SendDataOverMQTT example in the SenML data format. For that, you simply need to adapt the format set in the variable publishDataFormat in line 300 in AppController.c as below:
 
const char *publishDataFormat = "[{ "bn": "urn:dev:ow:MACAddressOfNode, "n": "temperature", "u": "C", "v": %ld },{ "n": "humidity", "u": "bar", "v": %ld }]";
Please note every quotation mark " needs an additional to be recognized as part of the string instead of beeing recognized as beginning and ending tag of the string.

The temperature and humidity data can than be added in line 364 in AppController.c as below:
 
int32_t length = snprintf((char *) publishBuffer, APP_MQTT_DATA_BUFFER_SIZE, publishDataFormat,
(sensorValue.Temp /= 1000),(long int) sensorValue.RH);

Furthermore, the sending interval of the MQTT message can be altered within the variable APP_MQTT_DATA_PUBLISH_PERIODICITY in AppController.h . Please note that the variable takes the time in milliseconds as such are two seconds represented as 2000 milliseconds.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Send an Array of information in SendDataOverMQTT Example
Answer
1/11/19 9:10 AM as a reply to Franjo Stjepandic.

Hello Franjo,

Thank you I was able to send the desired format to the Broker with your suggestions. I am just curious as to if I can push this information in an array i.e. every second I push the temperature and humidity values into an array and then send this array to the Broker every 1 minute.

 

Will this require a substantial amount of change in the code?

 

Thanks

0 (0 Votes)
RE: Send an Array of information in SendDataOverMQTT Example
Answer
1/11/19 3:24 PM as a reply to Shantanoo Desai.
Hello Shantanoo,

This is certainly possible and can be achieved in multiple ways,

Collection of the data can simply be achieved by appending them into an array.
You could then either have a different task firing every minute, that sends the array over MQTT and empties the array.
Alternatively, you can simply run a counter in one task that fires every second,
appending the data and once a counter of 60 is reached going into a loop that is
sending the data and resetting the counter and array.

With bigger datasets being stored you may want to also increase the tasks buffer

Kind regards,
Franjo
+1 (1 Vote)