for(i=0;i<6;i++)
{
switch(rx_data[1])
{
case 0 : //show o3 value
msg.topic="Read_All_is_OK";
msg.payload="Read All Sensors Value is ok.";
break;
case 1 : //show co value
msg.topic="Read_All_is_OK";
msg.payload="Read All Sensors Value is ok.";
break;
case 2 : //show co2 value
msg.topic="Read_All_is_OK";
msg.payload="Read All Sensors Value is ok.";
break;
case 3 : //show tvoc value
msg.topic="Read_All_is_OK";
msg.payload="Read All Sensors Value is ok.";
break;
case 4 : //show ch2o value
msg.topic="Read_All_is_OK";
msg.payload="Read All Sensors Value is ok.";
break;
case 5 : //show no2 value
msg.topic="Read_All_is_OK";
msg.payload="Read All Sensors Value is ok.";
break;
}
return msg;
}
I have 6 muliti output
My question is at 2. :
How to send data to ouput at time in for loop,
Cause only one msg.payload and if I have multi msg but return msg.payload just one and return msg.payload will done function then exit ...
So how to do the for loop and return msg.payload each at time?
for(i=0;i<6;i++)
{
switch(rx_data[1])
{
case 0 : //show o3 value
msg.topic="O3_Send_OK";
msg.payload="Read O3 Sensor Value is ok.";
break;
case 1 : //show co value
msg.topic="CO_Send_OK";
msg.payload="Read CO Sensor Value is ok.";
break;
case 2 : //show co2 value
msg.topic="CO2_Send_OK";
msg.payload="Read CO2 Sensor Value is ok.";
break;
case 3 : //show tvoc value
msg.topic="TVOC_Send_OK";
msg.payload="Read TVOC Sensor Value is ok.";
break;
case 4 : //show ch2o value
msg.topic="CH2O_is_OK";
msg.payload="Read CH2O Sensor Value is ok.";
break;
case 5 : //show no2 value
msg.topic="NO2_Send_OK";
msg.payload="Read NO2 Sensor Value is ok.";
break;
}
return msg;
}
My code is right? Cause Im not familiar with JS...
Some is integer,
Some is long,
Some is float.
var msg_read={ payload:"Read_All_is_OK" ,topic:"Read_All_is_OK"};
var o3_value=rx_data[16]<<24+rx_data[17]<<16+rx_data[18]<<8+rx_data[19];
var msg_o3={ payload:o3_value ,topic:"O3_Send_Value"};
var co_value=rx_data[20]<<24+rx_data[21]<<16+rx_data[22]<<8+rx_data[23];
var msg_co={ payload:co_value ,topic:"CO_Send_Value"};
var co2_value=rx_data[24]<<8+rx_data[25];
var msg_co2={ payload:co2_value ,topic:"CO2_Send_Value"};
var tvoc_value=rx_data[26]<<8+rx_data[27];
var msgtvoc={ payload:tvoc_value ,topic:"TVOC_Send_Value"};
var ch2o_value=rx_data[28]<<24+rx_data[29]<<16+rx_data[30]<<8+rx_data[31];
var msg_ch2o={ payload:ch2o_value ,topic:"CH2O_Send_Value"};
var no2_value=rx_data[32]<<8+rx_data[33];
var msg_no2={ payload:no2_value ,topic:"NO2_Send_Value"};
//
return [ msg_read, msg_o3, msg_co , msg_co2 , msg_tvoc , msg_ch2o , msg_no2];
1.Cause The buffer parser output1 That I want connect to gauge and text...
So I think it can not to do that? Right?
2. Look at Pic :
How did this value come from? Sorry, Im not smart!
var msg_read={ payload:"Read_All_is_OK" ,topic:"Read_All_is_OK"};
//
var o3_value=[msg.payload.data[16],msg.payload.data[17],msg.payload.data[18],msg.payload.data[19]];
var o3_value_buf=new Buffer(o3_value);
o3_value=o3_value_buf.readFloatBE(0);
var msg_o3={ payload:o3_value ,topic:"O3_Send_Value"};
//
var co_value=[msg.payload.data[20],msg.payload.data[21],msg.payload.data[22],msg.payload.data[23]];
var co_value_buf=new Buffer(co_value);
co_value=co_value_buf.readFloatBE(0);
var msg_co={ payload:co_value ,topic:"CO_Send_Value"};
//
var co2_value=[msg.payload.data[24],msg.payload.data[25]];
var co2_value_buf=new Buffer(co2_value);
co2_value=co2_value_buf.readUInt16BE(0);
var msg_co2={ payload:co2_value ,topic:"CO2_Send_Value"};
//
var tvoc_value=[msg.payload.data[26],msg.payload.data[27]];
var tvoc_value_buf=new Buffer(tvoc_value);
tvoc_value=tvoc_value_buf.readUInt16BE(0);
var msg_tvoc={ payload:tvoc_value ,topic:"TVOC_Send_Value"};
//
var ch2o_value=[msg.payload.data[28],msg.payload.data[29],msg.payload.data[30],msg.payload.data[31]];
var ch2o_value_buf=new Buffer(ch2o_value);
ch2o_value=ch2o_value_buf.readFloatBE(0);
var msg_ch2o={ payload:ch2o_value ,topic:"CH2O_Send_Value"};
//
var no2_value=[msg.payload.data[32],msg.payload.data[33]];
var no2_value_buf=new Buffer(no2_value);
no2_value=co2_value_buf.readUInt16BE(0);
var msg_no2={ payload:no2_value ,topic:"NO2_Send_Value"};
//
return [ msg_read, msg_o3, msg_co , msg_co2 , msg_tvoc , msg_ch2o , msg_no2];
RX has receive data,But Tte Gauge didnt show value! Where I was wrong?
Read the Gauge built in help - that is NOT how you use Value Format
Because there is no data property in msg.payload
Here is a working demo...
[{"id":"2a94e767.b2e158","type":"inject","z":"f9687f620c582b41","name":"Demo Data 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,246,102,102,65,68,204,205,0,50,0,150,66,254,51,51,0,0]","payloadType":"bin","x":1630,"y":1500,"wires":[["27c16664.aa0e3a","a3052117.1edea"]]},{"id":"27c16664.aa0e3a","type":"buffer-parser","z":"f9687f620c582b41","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"O3_Send_Value","offset":16,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"CO_Send_Value","offset":20,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"CO2_Send_Value","offset":24,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"TVOC_Send_Value","offset":26,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"CH2O_Send_Value","offset":28,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"NO2_Send_Value","offset":32,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":true,"setTopic":true,"outputs":6,"x":1826,"y":1612,"wires":[["94e3c954.8ec968","467c82ff.3f4a5c"],["853dc0bd.61069","3c949324.15898c"],["7e904a21.609dd4","56f58ef4.c662"],[],[],[]]},{"id":"94e3c954.8ec968","type":"debug","z":"f9687f620c582b41","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2090,"y":1460,"wires":[]},{"id":"467c82ff.3f4a5c","type":"ui_gauge","z":"f9687f620c582b41","name":"","group":"81dd3718.b97888","order":0,"width":"5","height":"4","gtype":"gage","title":"O3 Value","label":"units","format":"{{value | number:2}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":2080,"y":1508,"wires":[]},{"id":"853dc0bd.61069","type":"ui_gauge","z":"f9687f620c582b41","name":"","group":"81dd3718.b97888","order":0,"width":"5","height":"4","gtype":"gage","title":"CO Value","label":"units","format":"{{value | number:2}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":2080,"y":1604,"wires":[]},{"id":"3c949324.15898c","type":"debug","z":"f9687f620c582b41","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2090,"y":1556,"wires":[]},{"id":"7e904a21.609dd4","type":"debug","z":"f9687f620c582b41","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2090,"y":1652,"wires":[]},{"id":"56f58ef4.c662","type":"ui_gauge","z":"f9687f620c582b41","name":"","group":"81dd3718.b97888","order":0,"width":"5","height":"4","gtype":"gage","title":"CO Value","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":2080,"y":1700,"wires":[]},{"id":"a3052117.1edea","type":"debug","z":"f9687f620c582b41","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1826,"y":1500,"wires":[]},{"id":"d248a0f033e182b9","type":"inject","z":"f9687f620c582b41","name":"Demo Data 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,66,246,102,102,64,68,204,205,0,45,0,150,66,254,51,51,0,0]","payloadType":"bin","x":1630,"y":1560,"wires":[["27c16664.aa0e3a"]]},{"id":"b7cdb12b79ef6cfd","type":"inject","z":"f9687f620c582b41","name":"Demo Data 3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,253,253,212,66,1,204,205,0,56,0,150,66,254,51,51,0,0]","payloadType":"bin","x":1630,"y":1620,"wires":[["27c16664.aa0e3a"]]},{"id":"81dd3718.b97888","type":"ui_group","name":"Monitor","tab":"4e11db25.239e94","order":1,"disp":true,"width":"13","collapse":true,"className":""},{"id":"4e11db25.239e94","type":"ui_tab","name":"Gauges","icon":"dashboard","order":1,"disabled":false,"hidden":false}]