Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexterlabora/df109bf67c554dd23bd4cb078bd98f23 to your computer and use it in GitHub Desktop.
Save dexterlabora/df109bf67c554dd23bd4cb078bd98f23 to your computer and use it in GitHub Desktop.
WiFi Controlled train - Node-RED Master Dashboard
[{"id":"b1a4b956.4e5b48","type":"ui_tab","name":"Train","icon":"dashboard","order":"1"},{"id":"7609358c.89f6cc","type":"mqtt-broker","z":"","broker":"52.19.148.133","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"1a2d0774.e5d2f9","type":"inject","z":"8e58674f.71a798","name":"Forward","topic":"motor","payload":"{\"command\":{\"motor\":1024}}","payloadType":"json","repeat":"","crontab":"","once":false,"x":117,"y":3088,"wires":[["bd88d388.42773"]]},{"id":"b8189f3c.47e76","type":"inject","z":"8e58674f.71a798","name":"Stop","topic":"motor","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":107,"y":3168,"wires":[["bd88d388.42773"]]},{"id":"b18313d0.4e7cf","type":"inject","z":"8e58674f.71a798","name":"Reverse","topic":"motor","payload":"-1000","payloadType":"num","repeat":"","crontab":"","once":false,"x":117,"y":3128,"wires":[["bd88d388.42773"]]},{"id":"4aef7a23.b51084","type":"comment","z":"8e58674f.71a798","name":"Train Control - WiFi: via MQTT","info":"The train is controlled by a NodeMCU (ESP8266) w/ motor shield\nThe NodeMCU offers a REST interface, for local access\nThis flow provides a PubNub interface, so commands can be sent from the Internet","x":152,"y":3042,"wires":[]},{"id":"bd88d388.42773","type":"mqtt out","z":"8e58674f.71a798","name":"","topic":"/trains/horizonexpress/motor","qos":"","retain":"","broker":"7609358c.89f6cc","x":497,"y":3128,"wires":[]},{"id":"b50d87ad.4af278","type":"ui_button_row","z":"8e58674f.71a798","tab":"b1a4b956.4e5b48","name":"Motor","topic":"motor","group":"Train Control - WiFi - Horizon Express","order":"2","toggle":false,"buttons":[{"payload":"-1023","icon":"arrow_back","color":"black","on_icon":"arrow_back","on_color":"green"},{"payload":"-900","icon":"chevron_left","color":"black","on_icon":"chevron_left","on_color":"green"},{"payload":"0","icon":"cancel","color":"black","on_icon":"close","on_color":"red"},{"payload":"900","icon":"chevron_right","color":"black","on_icon":"chevron_right","on_color":"green"},{"payload":"1023","icon":"arrow_forward","color":"black","on_icon":"arrow_forward","on_color":"green"}],"inputs":0,"x":107,"y":3208,"wires":[["bd88d388.42773"]]},{"id":"8dba6d48.72459","type":"ui_gauge","z":"8e58674f.71a798","tab":"b1a4b956.4e5b48","name":"Speed","group":"Train Control - WiFi - Horizon Express","order":"1","format":"{{value}}","min":"-1023","max":"1023","x":827,"y":3388,"wires":[]},{"id":"f3bb9f11.0c446","type":"json","z":"8e58674f.71a798","name":"","x":427,"y":3388,"wires":[["3570b9e.fca8f46","7c70fd89.838f04"]]},{"id":"3570b9e.fca8f46","type":"function","z":"8e58674f.71a798","name":"speed scale","func":"// Convert the speed from an absolute value with direction\n// to a negative/positive number\nvar speed = msg.payload.variables.speed;\nvar direction = msg.payload.variables.direction;\n\nif (direction === 1){\n msg.payload = -1*speed;\n}else{\n msg.payload = speed;\n}\nreturn msg;","outputs":1,"noerr":0,"x":667,"y":3404,"wires":[["8dba6d48.72459","86e93329.cdda3"]]},{"id":"7c70fd89.838f04","type":"function","z":"8e58674f.71a798","name":"trainStatus","func":"// update node status indicator\nif(msg.payload.variables.speed !== undefined){\n if(msg.payload.variables.speed !== 0){\n node.status({fill:\"green\",shape:\"ring\",text:\"moving \"+ msg.payload.variables.speed+\":\"+msg.payload.variables.direction});\n }else{\n node.status({fill:\"red\",shape:\"ring\",text:\"stopped\"});\n }\n}else{\n node.status({fill:\"yellow\",shape:\"ring\",text:\"unknown\"});\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"x":667,"y":3348,"wires":[["190b13be.e6f4ec"]]},{"id":"190b13be.e6f4ec","type":"function","z":"8e58674f.71a798","name":"format status for lights UI","func":"msg.payload = msg.payload.variables.lights || 0;\nreturn msg;","outputs":1,"noerr":0,"x":207,"y":3328,"wires":[["88977dce.77688"]]},{"id":"e6f687f3.190978","type":"mqtt in","z":"8e58674f.71a798","name":"","topic":"/trains/horizonexpress/status","broker":"7609358c.89f6cc","x":177,"y":3388,"wires":[["f3bb9f11.0c446","4ed894d5.4c00dc"]]},{"id":"88977dce.77688","type":"ui_switch","z":"8e58674f.71a798","tab":"b1a4b956.4e5b48","name":"Lights","topic":"lights","group":"Train Control - WiFi - Horizon Express","order":"3","onvalue":"1","offvalue":"0","x":107,"y":3288,"wires":[["3a6cc62e.c5933a"]]},{"id":"3a6cc62e.c5933a","type":"mqtt out","z":"8e58674f.71a798","name":"","topic":"/trains/horizonexpress/lights","qos":"","retain":"","broker":"7609358c.89f6cc","x":497,"y":3288,"wires":[]},{"id":"86e93329.cdda3","type":"debug","z":"8e58674f.71a798","name":"Speed UI","active":true,"console":"false","complete":"payload","x":816.5,"y":3430,"wires":[]},{"id":"4ed894d5.4c00dc","type":"debug","z":"8e58674f.71a798","name":"MQTT Trains","active":true,"console":"false","complete":"payload","x":447.50001525878906,"y":3429,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment