Separate the properties of a payload so i can send each individual values to another device

Hi, I am a newbie here, sorry but we all have to start somewhere :slight_smile:
Anyway I am not a newbie with BMS (Building Management Systems) also know as BEMS (Building Energy Management Systems).
The BMS control I use (Niagara Tridium N4 controller) has a MQTT pallet which works fine, no issues with sending or receiving MQTT data via my own server MQTT broker.

So my next step is to take a LoRaWan device back into the Tridium Niagara BMS controller.
The LoRaWan device i am using takes MODBUS electric meter network signals and sends the meter values to my LoRaWAN gateway, then I currently send this data to https://www.thethingsnetwork.org/ all fine, no issues.

Now to Node-Red, I take the information for this LoRaWAN device from https://www.thethingsnetwork.org/ into Node-Red and the MQTT in node.

mqtt_from_thethingsnetwork

I then create a basic flow which currently sends the data back to the Niagara Tridium N4 controller via MQTT out node, which sends fine and i have added a edit debug node.

Here is the debug data

{"topic":"modbuspowerbar_mcf88/devices/mcf88/up","payload":"{\"app_id\":\"modbuspowerbar_mcf88\",\"dev_id\":\"mcf88\",\"hardware_serial\":\"70B3D58FF1013E38\",\"port\":2,\"counter\":641,\"confirmed\":true,\"payload_raw\":\"CxQAEAABVAaAAasAXQW2AAAAFg==\",\"payload_fields\":{\"CPU_Temp\":34,\"MCB0_Mains\":1.664,\"MCB1_Freezers\":0.427,\"MCB2_Lights\":0.093,\"MCB3_Desk_Sockets_Aircon\":1.462,\"MCB4_Sockets\":0,\"MCB5_Spare\":0.022},\"metadata\":{\"time\":\"2020-08-16T18:04:14.238780126Z\",\"frequency\":868.5,\"modulation\":\"LORA\",\"data_rate\":\"SF7BW125\",\"airtime\":71936000,\"coding_rate\":\"4/5\",\"gateways\":[{\"gtw_id\":\"eui-60c5a8fffe766204\",\"timestamp\":1490131788,\"time\":\"\",\"channel\":7,\"rssi\":-43,\"snr\":8.5,\"rf_chain\":0,\"latitude\":51.88843,\"longitude\":-0.53416,\"altitude\":148}],\"latitude\":51.888424,\"longitude\":-0.53416693,\"altitude\":148,\"location_source\":\"registry\"}}","qos":0,"retain":false,"_msgid":"27e905e3.3f2b4a"}

Now what i would like to do is separate the payload_fields, so i can send each individual field to the Niagara Tridium controller.

{\"CPU_Temp\":34,\"MCB0_Mains\":1.664,\"MCB1_Freezers\":0.427,\"MCB2_Lights\":0.093,\"MCB3_Desk_Sockets_Aircon\":1.462,\"MCB4_Sockets\":0,\"MCB5_Spare\":0.022}

I have looked through the forum, and see detailed information on the topic using a change node and a switch node, but not getting very far, so any help would be appreciated.

Below is the current input into the Tridium Niagara controller, which is a long string input.

Any ideas for the best way to extract the 7 fields in the payload ?

Thanks for reading.

So a small lesson on JS objects and their equivalent string representation (AKA JSON)...

Your payload is a string/JSON (due to the Output setting on the MQTT node). You could attempt some complex splits and loops etc - but - as it is JSON (JavaScript Object Notation) - just let JS do its thing - turn that JSON back into a JS Object! (if you dont know what I mean, it'd be worth reading up - will help you greatly in node-red knowing the difference)

So first off, change that MQTT IN to...
image

Now, you data will be an actual JS object (not a string / not JSON)...
image

And once its an object, you can simply "copy path" of any item in the object & use that in a change node (or whatever)...

So, from that, you could generate new messages by using parallel change nodes...

ending up with this...
image

my demo flow...

[{"id":"635795b0.ebc5dc","type":"inject","z":"485b32f3.0bdfbc","name":"your MQTT IN data (faking it)","topic":"modbuspowerbar_mcf88/devices/mcf88/up","payload":"{\"app_id\":\"modbuspowerbar_mcf88\",\"dev_id\":\"mcf88\",\"hardware_serial\":\"70B3D58FF1013E38\",\"port\":2,\"counter\":641,\"confirmed\":true,\"payload_raw\":\"CxQAEAABVAaAAasAXQW2AAAAFg==\",\"payload_fields\":{\"CPU_Temp\":34,\"MCB0_Mains\":1.664,\"MCB1_Freezers\":0.427,\"MCB2_Lights\":0.093,\"MCB3_Desk_Sockets_Aircon\":1.462,\"MCB4_Sockets\":0,\"MCB5_Spare\":0.022},\"metadata\":{\"time\":\"2020-08-16T18:04:14.238780126Z\",\"frequency\":868.5,\"modulation\":\"LORA\",\"data_rate\":\"SF7BW125\",\"airtime\":71936000,\"coding_rate\":\"4/5\",\"gateways\":[{\"gtw_id\":\"eui-60c5a8fffe766204\",\"timestamp\":1490131788,\"time\":\"\",\"channel\":7,\"rssi\":-43,\"snr\":8.5,\"rf_chain\":0,\"latitude\":51.88843,\"longitude\":-0.53416,\"altitude\":148}],\"latitude\":51.888424,\"longitude\":-0.53416693,\"altitude\":148,\"location_source\":\"registry\"}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":140,"wires":[["cfe3cfe5.2fd24","d7eb57a2.3aa148","6d3aae76.88f9"]]},{"id":"362f42bb.e4a57e","type":"debug","z":"485b32f3.0bdfbc","name":"to MQTT Out node (or whatever)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":140,"wires":[]},{"id":"cfe3cfe5.2fd24","type":"change","z":"485b32f3.0bdfbc","name":"CPU_Temp","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload_fields.CPU_Temp","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"modbuspowerbar_mcf88/devices/mcf88/up/CPU_Temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":140,"wires":[["362f42bb.e4a57e"]]},{"id":"d7eb57a2.3aa148","type":"change","z":"485b32f3.0bdfbc","name":"MCB0_Mains","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload_fields.MCB0_Mains","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"modbuspowerbar_mcf88/devices/mcf88/up/MCB0_Mains","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":200,"wires":[["362f42bb.e4a57e"]]},{"id":"6d3aae76.88f9","type":"change","z":"485b32f3.0bdfbc","name":"MCB1_Freezers","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload_fields.MCB1_Freezers","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"modbuspowerbar_mcf88/devices/mcf88/up/MCB1_Freezers","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":260,"wires":[["362f42bb.e4a57e"]]}]

EDIT...

I updated your threads topic as it was fairly inconsequential to do with what you were trying to achieve. In fact, I skipped over your question earlier as I had no clue what a "Niagara Tridium N4 controller" was & thought I couldn't help you (likely others did too). My point is, try to title your topics in relation to the goal or issue.

1 Like

Thank you so much Steve, that worked great and the data is now exported to the Building Management system :smile:

Thank you again for the quick answer back.

BMS Controller with MQTT inputs

1 Like

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