How to have different properties of sensors under each sensor id in mqqt message in node red

how to re- arrange the details of each sensor under its sensor_id in a function node (as given below) after a buffer parser to send it to a mqqt broker.

{
	"Time": "2021-09-14T08:08:07.434Z",
	 "Location_id" = 1
  { 
    "Circuit_Id"= 1,
	   { 
		"C1Ia": 0.5,
                "C1Ib": 0.6,
                "C1Ic": 0.7,
       }		 
 { 
    "Circuit_Id"= 2,
	   { 
		"C2Ia": 0.7,
                "C2Ib": 0.6,
                "C2Ic": 0.8,	
       }			
   }
}   
}

[{"id":"8c888c45.ce124","type":"delay","z":"f2d0d390.46fca","name":"energydelay","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"50","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":620,"y":620,"wires":[["978b0e29.3ca7c"]]},{"id":"a009d9ff.583bf8","type":"q-gate","z":"f2d0d390.46fca","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","statusCmd":"status","maxQueueLength":"1000","keepNewest":false,"qToggle":false,"persist":false,"x":490,"y":620,"wires":[["8c888c45.ce124"]]},{…

You need to walk through the object and output each property with a new topic.

Your exported flow is invalid....


... please export it again.


Additionally, as we do not have your modbus device, please provide sample data by...

  • add a debug node (set to show FULL MESSAGE) to the output of the ModBus node
  • Wait for data to arrive
  • Copy the messages value by clicking the "copy value" button that appears under your mouse when you hover over the message in the RH sidebar - example...
    image

Lastly, your description is not 100% clear. Are you attempting to make individual MQTT messages like this...

topic payload
Circuit_Id/1/C1Ia 0.5
Circuit_Id/1/C1Ib 0.6
Circuit_Id/1/C1Ic 0.7
Circuit_Id/2/C2Ia 0.7
Circuit_Id/2/C2Ib 0.6
Circuit_Id/2/C2Ic 0.8

If not, please be clear in your requirement.

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