-
-
Notifications
You must be signed in to change notification settings - Fork 20
node red
To test VSCP with node-red you can use the VSCP demo server located at demo.vscp.org. This server has a MQTT broker active for public use at port 1883 which can be accessed with user="vscp" and password="secret". Also this server have websocket support on port 9001. The demo server is fully described here.
This is a simple flow that display the temperature in our kitchen. The temperature is displayed in a gauge as well as in a diagram and looks like this
The code for the flow is
´´´json [{"id":"1808f66585de11aa","type":"mqtt in","z":"8102f2ad6305cf60","name":"Kitchen temperature","topic":"vscp/25:00:00:00:00:00:00:00:00:00:00:00:06:00:00:01/1040/6/1/4","qos":"2","datatype":"json","broker":"d5c2659b.267728","nl":false,"rap":true,"rh":0,"x":170,"y":1120,"wires":"eb77935aa44eeb1e"},{"id":"83e4c24fab4c374b","type":"ui_gauge","z":"8102f2ad6305cf60","name":"Kitchen temperature","group":"ff769916b5262def","order":1,"width":"6","height":"4","gtype":"gage","title":"Kitchen temperature","label":"Degrees Celsius","format":"{{value}}","min":"0","max":"40","colors":["#00b500","#e6e600","#ca3838"],"seg1":"25","seg2":"30","x":820,"y":1120,"wires":[]},{"id":"efc68f7b1ad54ff1","type":"debug","z":"8102f2ad6305cf60","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":1200,"wires":[]},{"id":"0e5e19ded032ba48","type":"function","z":"8102f2ad6305cf60","name":"","func":"msg.value = msg.payload.measurement.value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1120,"wires":"83e4c24fab4c374b"},{"id":"21a9fd8531d7d058","type":"ui_chart","z":"8102f2ad6305cf60","name":"Kitchen temperature","group":"ff769916b5262def","order":5,"width":"11","height":"5","label":"Kitchen Temperature","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"No data","dot":false,"ymin":"0","ymax":"40","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1d6faa","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":820,"y":1160,"wires":]]},{"id":"e4be5ab290fee203","type":"function","z":"8102f2ad6305cf60","name":"","func":"msg.payload = msg.payload.measurement.value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1160,"wires":[["21a9fd8531d7d058"},{"id":"eb77935aa44eeb1e","type":"function","z":"8102f2ad6305cf60","name":"Add localtime","func":"var utcDate = msg.payload.vscpDateTime;\nmsg.payload.localtime = new Date(utcDate);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":1120,"wires":"0e5e19ded032ba48","e4be5ab290fee203","efc68f7b1ad54ff1"},{"id":"d5c2659b.267728","type":"mqtt-broker","name":"Demo server","broker":"demo.vscp.org","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":"","credentials":{}},{"id":"ff769916b5262def","type":"ui_group","name":"Brattberg","tab":"a4efd49613773787","order":1,"disp":true,"width":"11","collapse":false},{"id":"a4efd49613773787","type":"ui_tab","name":"Kitchen","icon":"dashboard","disabled":false,"hidden":false}] ´´´
VSCP event have date and time set in UTC to be universally usable. To get local time you have to convert this UTC time to a local time. But don't despair the conversion is easy.
Add a function node in the flow from the MQTT broker with the following content
var utcDate = msg.payload.vscpDateTime;
msg.payload.localtime = new Date(utcDate);
return msg;
you will now have the localtime in msg.payload.localtime and can
The VSCP Project (https://www.vscp.org) - Copyright © 2000-2024 Åke Hedman, the VSCP Project