Decoding Sensor Data

  • 28 Feb, 2019

Every sensor has it’s own kind off codification The message from the device is like this one:

{"time": "1551285775", "deviceType": "deviceType", "device": "xyzabcd", "duplicate": "false", "snr": "30.00", "rssi": "-128.00", "avgSnr": "19.39", "station": "300C", "lat": "-20.0", "lng": "-44.0", "seqNumber": "497", "data": "1a24183c3801" }

The measurement are encoded on data string, a sequence of 6 bytes. I read the sensor manual and the temperature are usin the last 4 bytes

To get the temperature value i wrote the following:

var dados = msg.payload.data //get the data value “1a24183c3801” var v1 = dados.substring(10,11)+dados.substring(11,12)+dados.substring(8,9)+dados.substring(9,10) //get the 4 values as in the device manual For example the value will be “0138” The temperature will be temp = parseInt(v1,16)/100 Using the value 0138 the result is 3,12 Degrees Celsius But if the temperatue is negative you need to test if the first bit of the meesage is 1 and use

temp = parseInt((~parseInt(v1,16) +1 >>> 0).toString(2).substring(16,32),2)/100 * -1

The formula code on the line above use twos complement format, get the last 16 bits and then convert to a decimal value

Related Posts

Proud to be an IBM Champion 2021

  • 14 Jan, 2021

This history began in 2011 when the category IBM Champions for Social Business was created.At that time there were only 50.  During the following years I was also nominated in other categories such as

Proud to be an IBM Champion 2021Read More

AWS Lambda now supports container images as a packaging format

  • 03 Dec, 2020

You can now package and deploy AWS Lambda(https://aws.amazon.com/lambda/) functions as a container image of up to 10 GB. This makes it easy to build Lambda based applications using familiar container

AWS Lambda now supports container images as a packaging formatRead More

VCP Driver for macOS Big Sur 11.0.x not available yet

  • 24 Nov, 2020

With new version of macOS released which is macOS Big Sur 11.0.x, the latest version of our VCP driver for Macintosh OSX (v5.3.5) now becomes incompatible. The reason for this is because of new drive

VCP Driver for macOS Big Sur 11.0.x not available yetRead More