可视化传感器数据在网页Node Red中

时间:2016-11-26 17:37:33

标签: javascript html json node-red

我正在与TI Sensortag和Node red合作。我将加速度计的值存储在json-db dataIn中。然后我想要显示网页中的最后一个加速度值(通过get请求)。

我试图将我的{{msg.payload.acc_x}}写入html块,但它不起作用。这样做的正确方法是什么?

谢谢!

我的流程:

[{"id":"1806c6da.bcf299","type":"http in","z":"e6102a63.549ad8","name":"status","url":"/status","method":"get","swaggerDoc":"","x":216.05708694458008,"y":337.15556049346924,"wires":[["a93fc711.c668b8"]]},{"id":"2e44d337.56820c","type":"http response","z":"e6102a63.549ad8","name":"","x":762.5349426269531,"y":379.66663932800293,"wires":[]},{"id":"5e67e951.064d18","type":"template","z":"e6102a63.549ad8","name":"HTML","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <body>\n        this is my acc:  </br>\n        x: {{payload.acc_x}} </br>\n        y: {{payload.acc_y}}  </br>\n        z: {{payload.acc_z}}\n    </body>\n</html>","x":563.0904083251953,"y":372.33329677581787,"wires":[["2e44d337.56820c"]]},{"id":"6573764c.40f878","type":"inject","z":"e6102a63.549ad8","name":"","topic":"","payload":"{      \"d\":{         \"myName\":\"TI CC2650 SensorTag\",       \"Seq #\":1,       \"Uptime (sec)\":245,       \"Def Route\":\"fe80::212:4b00:afe:5a07\",       \"RSSI (dBm)\":-22,       \"Battery Temp (C)\":29,       \"Battery Volt (mV)\":3339,       \"Air Pressure (hPa)\":977.66,       \"Air Temp (C)\":30.10,       \"Object Temp (C)\":15.781,       \"Ambient Temp (C)\":30.187,       \"Light (lux)\":321.92,       \"HDC Humidity (%RH)\":20.97,       \"HDC Temp (C)\":30.22,       \"Acc X (G)\":0.04,       \"Acc Y (G)\":0.18,       \"Acc Z (G)\":1.07,       \"Gyro X (deg per sec)\":1.65,       \"Gyro Y (deg per sec)\":-2.86,       \"Gyro Z (deg per sec)\":-3.22    } }","payloadType":"str","repeat":"","crontab":"","once":false,"x":143.83482360839844,"y":174.93826580047607,"wires":[["d2cc4f4.e7ac8b"]]},{"id":"ab58c310.39684","type":"function","z":"e6102a63.549ad8","name":"acc","func":"var myacc_x = msg.payload;\nmsg.payload={\n    \"acc_x\": 0,\n    \"acc_y\": 0,\n    \"acc_z\": 0,\n};\n\nmsg.payload.acc_x=myacc_x.d[\"Acc X (G)\"];\nmsg.payload.acc_y=myacc_x.d[\"Acc Y (G)\"];\nmsg.payload.acc_z=myacc_x.d[\"Acc Z (G)\"];\n\nmsg.datapath=\"/\" + Date.now().toString();\n\nreturn msg;","outputs":1,"noerr":0,"x":495.94590759277344,"y":107.82713317871094,"wires":[["dca7f11.a513a1"]]},{"id":"dca7f11.a513a1","type":"DataIn","z":"e6102a63.549ad8","collection":"e65ae0.4abc852","name":"","update":false,"path":"/","x":725.057071685791,"y":145.0493631362915,"wires":[]},{"id":"2540b080.2cab9","type":"debug","z":"e6102a63.549ad8","name":"","active":true,"console":"false","complete":"payload","x":796.8348350524902,"y":231.1882677078247,"wires":[]},{"id":"ac43fd63.53634","type":"inject","z":"e6102a63.549ad8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":424.83483505249023,"y":239.1882677078247,"wires":[["304f429c.15016e"]]},{"id":"304f429c.15016e","type":"DataOut","z":"e6102a63.549ad8","collection":"e65ae0.4abc852","name":"","path":"/","error":false,"x":614.8348350524902,"y":244.6882677078247,"wires":[["2540b080.2cab9"]]},{"id":"d2cc4f4.e7ac8b","type":"json","z":"e6102a63.549ad8","name":"","x":314.08482360839844,"y":137.43826389312744,"wires":[["ab58c310.39684"]]},{"id":"a93fc711.c668b8","type":"DataOut","z":"e6102a63.549ad8","collection":"e65ae0.4abc852","name":"","path":"/","error":false,"x":366.0570869445801,"y":368.27160358428955,"wires":[["5e67e951.064d18"]]},{"id":"b7daa4c7.444618","type":"mqtt in","z":"e6102a63.549ad8","name":"","topic":"iot-2/evt/status/#","qos":"2","broker":"7fd38af6.a2e464","x":136.05708694458008,"y":93.82715225219727,"wires":[[]]},{"id":"e65ae0.4abc852","type":"json-db-collection","z":"e6102a63.549ad8","name":"testdb","collection":"testdb","save":true},{"id":"7fd38af6.a2e464","type":"mqtt-broker","z":"537e81a1.e4cbf","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

1 个答案:

答案 0 :(得分:0)

假设您正在使用模板节点,那么胡须模板的范围是在msg级别。

这意味着您不需要在msg. {{payload.acc_x}}开始工作

编辑:添加了示例流程

[{&#34; ID&#34;:&#34; c2490525.f8ec68&#34;&#34;类型&#34;:&#34;模板&#34;&#34; Z&#34 ;:&#34; 8cdaf657.37241&#34;&#34;名称&#34;:&#34;&#34;&#34;字段&#34;:&#34;有效载荷&#34;,& #34;字段类型&#34;:&#34; MSG&#34;&#34;格式&#34;:&#34;车把&#34;&#34;语法&#34;:&#34;髭&# 34;,&#34;模板&#34;:&#34; \ n \ n \ n acc_x:{{payload.acc_x}} \ n \ n&#34;,&#34; x&#34;:600.5, &#34; Y&#34; 131&#34;电线&#34;:[[&#34; 3608d51c.7c3222&#34;]]},{&#34; ID&#34;:&#34; 8354e1e7.7ca9f&#34;,&#34;输入&#34;:&#34; http输入&#34;,&#34; z&#34;:&#34; 8cdaf657.37241&#34;,&#34;名称&#34;:&#34;&#34;&#34; URL&#34;:&#34; /测试&#34;&#34;方法&#34;:&#34;获得&#34; &#34; swaggerDoc&#34;:&#34;&#34;&#34; X&#34;:247.5&#34; Y&#34; 121&#34;电线&#34 ;: [[&#34; 646cd1ad.5bba6&#34;]]},{&#34; ID&#34;:&#34; 3608d51c.7c3222&#34;&#34;类型&#34;:&#34; http响应&#34;,&#34; z&#34;:&#34; 8cdaf657.37241&#34;,&#34; name&#34;:&#34;&#34;,&#34; x&# 34;:768.5&#34; Y&#34; 133&#34;电线&#34;:[]},{&#34; ID&#34;:&#34; 646cd1ad.5bba6&#34 ;, &#34;类型&#34 ;:&#34;功能&#34;&#34; Z&#34;:&#34; 8cdaf657.37241&#34;&#34;名称&#34;:&#34;&#34;,& #34; func&#34;:&#34; msg.payload.acc_x = 1.5 \ nreturn msg;&#34;,&#34;输出&#34;:1,&#34; noerr&#34;:0, &#34; X&#34;:389.5&#34; Y&#34; 129&#34;电线&#34;:[[&#34; c2490525.f8ec68&#34;]]}]