[Solved] How do I convert a Sigfox temp data value correctly

Hi, Can anyone please help, I’m a newbie to Losant and IOT

I’m having a problem trying to calculate the correct temperature using Sigfox and a thinxtra dev kit.

Using a function in Losant I use the following code to convert the incoming data to centigrade:

payload.data.body.Temp = (parseInt(payload.data.body.data.substring(6, 10), 16) - 1000)/10; // -1000 because device add 1000 to manage negative temperatures, divide 10 to get one decimal

The temperature should be held in the first two bytes of payload.data.body.data when it is returned by Sigfox

The temperature returned from the function is 3,225. The temperature output should be around 26 Degrees C

I copied the function from an example so not really sure how it works.

Thank you

Can you paste some raw data from the sigfox device with the expected temperature output?

Hi Brandon,

Thanks for looking at this:

Output from Webhook

{
“time”: “2017-08-16T02:14:53.673Z”,
“data”: {
“path”: “/”,
“method”: “post”,
“headers”: {
“content-length”: “291”,
“accept-language”: “fr”,
“content-type”: “application/json”,
“accept-encoding”: “gzip,deflate”,
“user-agent”: “SIGFOX”,
“accept-charset”: “UTF-8;q=0.9,*;q=0.7”,
“x-forwarded-proto”: “https”,
“x-forwarded-for”: “185.110.97.11”
},
“query”: {},
“body”: {
“device”: “2BF177”,
“time”: “1502849692”,
“duplicate”: “false”,
“snr”: “29.60”,
“station”: “35F9”,
“data”: “43090c840502f7fff4ff0201”,
“avgSnr”: “38.59”,
“lat”: “-37.0”,
“lng”: “175.0”,
“rssi”: “-114.00”,
“seqNumber”: “2395”,
“ack”: false
},
“replyId”: “59938952269684000617403e.BkpLdXE8W.By8i9XbuWW”
},
“applicationId”: “598d41e8bc99f30006dd1fd6”,
“triggerId”: “59938952269684000617403e”,
“triggerType”: “webhook”,
“relayId”: “000000000000000000000000”,
“relayType”: “public”,
“flowVersion”: “develop”,
“flowId”: “59939dc12696840006174041”,
“flowName”: “Webhook 177”,
“applicationName”: “Sigfox”,
“glocals”: {}
}

Output after function

{
“time”: “2017-08-16T02:14:53.673Z”,
“data”: {
“path”: “/”,
“method”: “post”,
“headers”: {
“content-length”: “291”,
“accept-language”: “fr”,
“content-type”: “application/json”,
“accept-encoding”: “gzip,deflate”,
“user-agent”: “SIGFOX”,
“accept-charset”: “UTF-8;q=0.9,*;q=0.7”,
“x-forwarded-proto”: “https”,
“x-forwarded-for”: “185.110.97.11”
},
“query”: {},
“body”: {
“device”: “2BF177”,
“time”: “1502849692”,
“duplicate”: “false”,
“snr”: “29.60”,
“station”: “35F9”,
“data”: “43090c840502f7fff4ff0201”,
“avgSnr”: “38.59”,
“lat”: “-37.0”,
“lng”: “175.0”,
“rssi”: “-114.00”,
“seqNumber”: “2395”,
“ack”: false,
“temperature”: 255
},
“replyId”: “59938952269684000617403e.BkpLdXE8W.By8i9XbuWW”
},
“applicationId”: “598d41e8bc99f30006dd1fd6”,
“triggerId”: “59938952269684000617403e”,
“triggerType”: “webhook”,
“relayId”: “000000000000000000000000”,
“relayType”: “public”,
“flowVersion”: “develop”,
“flowId”: “59939dc12696840006174041”,
“flowName”: “Webhook 177”,
“applicationName”: “Sigfox”,
“globals”: {}
}

Thanks

Ray

According to XKit’s docs, the temperature is reported as TempC * 100.

If I take your data (43090c840502f7fff4ff0201) and parse it with that in mind, I get something that seems more accurate. Here’s the function node I used:

var data = payload.data.body.data;
var buf = Buffer.from(data, 'hex');

payload.data.result = buf.readInt16LE(0) / 100;

This gives me 23.71:

image

Let me know if that helps!

Thank you Brandon,

This helped a lot as I can see the temperature value now in the data/body. The problem I have now is the java code in the function returns the following error:

I’m not actually using the AWS Callback template at the Sigfox backend but using the Custom callback example here: https://www.losant.com/blog/collect-monitor-visualize-sigfox-data so there are no fields for inputing ARN Role: or Region.

Ray Woods | Rayza Edge Solutions Limited | NZ +64 21 248 0640 | ray@rayzaedge.co.nz

Sorry for the confusion there - I posted the screenshot just to show the data format of the incoming data. The only part of the screenshot to pay attention to is the table at the bottom.

Looking at your example output from above, the incoming data should be on the payload at data.body.data, which is what the function node is referencing. Can you paste the rest of the debug output that shows the current payload so we can see what’s missing?

Thanks Brandon, No problem. I noticed that the “Temperature” variable in the payload was another level further into the body so as you say it should be data.body.data.Temperature and not data.body.Temperature. I have also changed the Function as per the attached and it seems to work ok know for all three values Temperature, Pressure & Photo. Is it ok to overwrite the original payload values in this way or should it be done differently ?

Glad we got it all working. There’s no issue in overwriting the payload fields, just as long as you don’t need the original values anymore.