Buffer Parser - Parsing data to Boolean

Hi,

I am trying to parse the modbus read buffer data into separate bolean output by using buffer parser, however the output value it seems not following the correct data as per buffer data. Below is my configuration in buffer parser:

However the output of the parser is not match with the buffer data, for example the first bit of buffer data is TRUE but first bit output of parser is FALSE. Please see below snip:

Appreciate if some one can tell me what is wrong with my nodes configuration and how to resolve it.

Cheers,
Zulpaedi

Hi Zulpaedi,

Just had a quick look.. It looks like your trying to split a message that has a heap of Boolean's and output them to different MQTT topics?

Have you considered just using a switch node?

Something like this

should work... its late here and Ive had a few :slight_smile:

Since your input is already booleans (in an array) there is no need to parse them using buffer parser (as pointed out above) but if you want to, then you can put them together into a buffer from then your current setup will work.

Also, there is no need for separate MQTT nodes - you can apply a topic in the buffer-parser and leave the topic blank on the MQTT node (the topic passed from the buffer-parser will be used in the single MQTT node)

Demo flow (use CTRL-I to import)

[{"id":"a068b9e573d32d5d","type":"inject","z":"2af928946f7f3bae","name":"Read Coils (fake)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[true, false, false, true,  false,  false,  false,  false]","payloadType":"json","x":180,"y":140,"wires":[["6fdb7e6eb19767cc"]]},{"id":"f77f479f7f38d713","type":"debug","z":"2af928946f7f3bae","name":"to MQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":420,"y":200,"wires":[]},{"id":"6fdb7e6eb19767cc","type":"function","z":"2af928946f7f3bae","name":"boolArrayToBuffer","func":"const boolArrayToBuffer = (boolArray) => {\n    const byteArray = []\n    let byte = 0\n\n    for (let i = 0; i < boolArray.length; i++) {\n        if (boolArray[i]) {\n            byte |= (1 << (i % 8))\n        }\n        if (i % 8 === 7 || i === boolArray.length - 1) {\n            byteArray.push(byte)\n            byte = 0\n        }\n    }\n\n    return Buffer.from(byteArray)\n}\n\nmsg.payload = boolArrayToBuffer(msg.payload)\nreturn msg\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":140,"wires":[["8dcef3c86c4c21f5"]]},{"id":"8dcef3c86c4c21f5","type":"buffer-parser","z":"2af928946f7f3bae","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"bool","name":"VALVE_AREA_1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"bool","name":"VALVE_AREA_2","offset":0,"length":1,"offsetbit":1,"scale":"1","mask":""},{"type":"bool","name":"VALVE_AREA_3","offset":0,"length":1,"offsetbit":2,"scale":"1","mask":""},{"type":"bool","name":"SPRAY_PUMP","offset":0,"length":1,"offsetbit":3,"scale":"1","mask":""},{"type":"bool","name":"SUPPLY_PUMP","offset":0,"length":1,"offsetbit":4,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"return","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":190,"y":200,"wires":[["f77f479f7f38d713"]]},{"id":"3f221581ad092243","type":"global-config","env":[],"modules":{"node-red-contrib-buffer-parser":"3.2.2"}}]