How to specify an integer data type to InfluxDB

Hello Folks,
I have MQTT data in JSON format which looks like this:


I convert it to a JS Object with the JSON node then inject it to an InfluxDB. That works.

In the MQTT data above, the keys IO and IO2 are each a BYTE where each bit is a binary value which I wish to decode as separate binary values in InlfuxDB, using the math() function and the BINARY AND operator. That part does not work.
After some research it turns out that InfluxDB converts by default the IO and IO2 variables to FLOAT. I guess I need an integer type instead.
I read somewhere that I must append an "i" at the end of the value in order to tell InfluxDB that we want a INTEGER type. And that is where I am stuck. Not sure how to do this on the JS object I have prior to injecting it to InfluxDB node. Does that mean I need to to convert the values to STRING then append an "i" at the end?

Thx for any help

In the end I went around my problem by decoding the bitmaps in a NodeRed function and creating new KEYs for each decoded bit prior to feeding the JS object to Influx.

Code for the decoder is:

var mask = parseInt(msg.payload.IO, 10);

msg.payload.FiltState = (mask & 128) == 128 ? 1:0;
msg.payload.pHPumpState = (mask & 64) == 64 ? 1:0;
msg.payload.ChlPumpState = (mask & 32) == 32 ? 1:0;
msg.payload.pHLevel = (mask & 16) == 16 ? 1:0;
msg.payload.ChlLevel = (mask & 8) == 8 ? 1:0;

return msg;

so the JSON data fed to Influx then becomes:


Note: I first tried to do the above in a CHANGE node but the bitwise operations would not work for some reason

There is a “binary” node that can help parse data like that.

Thx dceejay,
I saw that node but I assumed that using it would have meant extra steps such as isolating the bitmaps from my JS object, feeding them to the binary node, then merging them back into the JS object prior to feeding the whole lot to Influx, so I went for the Function node approach.

If you set the MQTT node Output field to Parsed JSON object then it will parse the JSON for you so you don't need the JSON node
You shouldn't need the parseInt, IO is already a number not a string.

The binary decode is a bit neater, I think, if written as

msg.payload.FiltState = (mask >> 7) & 1; 
msg.payload.pHPumpState = (mask >> 6) & 1;

Thank you Colin for those two useful tips, it is indeed much cleaner.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.