IoTFlows
  • Welcome to IoTFlows Docs
  • IoTFlows
  • Console
  • REST API
  • Device Management & Secure Remote Access
    • 1. Connect a device to the cloud or create a virtual device
    • 2. SSH to your device over the internet
    • 3. Transfer files to your device over the internet
    • 4. Remotely access Node-RED on your device
    • 5. Create public links for local web-apps
  • Real-Time Data Streams, Alerts, and Actions
    • Create a Device API Key
    • Publish and subscribe to real-time messages with Node-RED
    • Creating an Alert Channel
    • Publish an Alert with Node-RED
    • Define and execute an Action in Node-RED
    • Python real-time SDK
    • Javascript real-time SDK
  • Cloud Node-RED Servers
    • Create a secure Cloud Node-RED Server in five minutes
    • Subscribe to data streams with a Cloud Node-RED Server
    • Integrate data streams to Node-RED dashboard
    • Integrate data streams to Slack
  • IOTFLOWS OVERVIEW
    • IoTFlows Roles and Permissions
    • Adding Team Members
  • Example Projects
    • Raspberry Pi as Gateway
      • Arduino to Raspberry Pi Serial Communication for Ultrasonic Sensor
    • Getting Started with Node-Red Dashboard
      • Installing Node-Red Dashboard
      • Accessing Node-Red Dashboard
      • 1. Creating a Page
      • 2. Adding Gauge Nodes
      • 3. Changing Dashboard Themes
      • 4. Adding Data to Gauge Nodes
      • 5. Adding a Chart Node
      • 6. Adding Data to Chart Node
      • 7. Adding a Template Node
      • 8. Adding Data to Template Node
      • 9. Adding Switch Node
      • 10. Adding Logic to Switch Node
      • 11. Adding a Slider Node
      • 12. Adding a Color Picker Node
      • 13. Adding a Numeric Node
      • 14. Adding a Button Node
      • 15. Adding Logic to a Button Node
      • Node-Red Dashboard Code
    • Publishing Data Streams from Python
    • Ultrasonic Sensor on Raspberry Pi Node-Red
  • General
    • Downloading IoTFlows Node-Red Nodes
    • Publishing Alert from Node-Red Manual
    • Publishing Data Stream from Node-Red Manual
Powered by GitBook
On this page

Was this helpful?

  1. Example Projects
  2. Getting Started with Node-Red Dashboard

Node-Red Dashboard Code

Previous15. Adding Logic to a Button NodeNextPublishing Data Streams from Python

Last updated 4 years ago

Was this helpful?

Below is an image of the entire dashboard code for the previous example. You can also use the following code to Import it into your Node-Red.

[{"id":"a2c28c79.cc093","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"a0b18284.b94b2","type":"ui_gauge","z":"a2c28c79.cc093","name":"","group":"f30d1ecd.61daa","order":1,"width":0,"height":0,"gtype":"donut","title":"Temperature","label":"F","format":"{{value}}","min":0,"max":"100","colors":["#ca3838","#00b500","#e6e605"],"seg1":"70","seg2":"75","x":590,"y":120,"wires":[]},{"id":"ea36daf7.a00f38","type":"ui_gauge","z":"a2c28c79.cc093","name":"","group":"f30d1ecd.61daa","order":2,"width":0,"height":0,"gtype":"gage","title":"pH Level","label":"","format":"{{value}}","min":0,"max":"14","colors":["#e6e600","#00b500","#e6e600"],"seg1":"6.5","seg2":"7.5","x":580,"y":180,"wires":[]},{"id":"f1d898a8.564ba8","type":"inject","z":"a2c28c79.cc093","name":"","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":120,"wires":[["4dadeb57.ef7364"]]},{"id":"4d8b1ae8.92b9b4","type":"inject","z":"a2c28c79.cc093","name":"","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":180,"wires":[["300ff1ad.04e79e"]]},{"id":"4dadeb57.ef7364","type":"function","z":"a2c28c79.cc093","name":"Tank Temperature","func":"msg.payload = Math.round(Math.random()*10)+70;\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":120,"wires":[["a0b18284.b94b2"]]},{"id":"300ff1ad.04e79e","type":"function","z":"a2c28c79.cc093","name":"Tank pH","func":"msg.payload = (Math.random() + 6.5).toFixed(1);\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":180,"wires":[["ea36daf7.a00f38"]]},{"id":"45914ac7.9d0fa4","type":"comment","z":"a2c28c79.cc093","name":"Temperature/pH monitor Section","info":"","x":190,"y":60,"wires":[]},{"id":"88d3efa8.192da","type":"ui_chart","z":"a2c28c79.cc093","name":"","group":"ffd8e6f4.96dd38","order":0,"width":0,"height":0,"label":"Motor RPMs","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"10000","removeOlder":1,"removeOlderPoints":"20","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":590,"y":320,"wires":[[]]},{"id":"9c457ed8.f81d3","type":"inject","z":"a2c28c79.cc093","name":"","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":320,"wires":[["b86bc613.faabb8"]]},{"id":"b86bc613.faabb8","type":"function","z":"a2c28c79.cc093","name":"2 Motors RPMS","func":"var msg = {};\nvar msg1 = {};\n\nmsg.payload = Math.round(Math.random()*1000)+500;\nmsg.topic = 'Motor 1 RPM';\n\nmsg1.payload = (Math.round(Math.random()*1000)+1000)*2;\nmsg1.topic = 'Motor 2 RPM';\nreturn [msg, msg1];","outputs":2,"noerr":0,"x":380,"y":320,"wires":[["88d3efa8.192da"],["88d3efa8.192da"]]},{"id":"d9b138a.0af01c8","type":"ui_template","z":"a2c28c79.cc093","group":"ffd8e6f4.96dd38","name":"Motor Data","order":1,"width":"12","height":"2","format":"<div layout=\"row\" layout-align=\"start center\">\n  <span flex style=\"font-size: 15px\"><b>RPM Min</b></span>\n  <span flex style=\"font-size: 15px\"><b>RPM Max</b></span>\n  <span flex style=\"font-size: 15px\"><b>Failure Prob</b></span>\n  <span flex style=\"font-size: 15px\"><b>Machine type</b></span>\n</div>\n<div layout=\"row\" layout-align=\"start center\" ng-repeat=\"machine in msg.payload.factory\">\n  <span flex style=\"color: green\">{{machine.min}}</span>\n  <span flex style=\"color: red\">{{machine.max}}</span>\n  <span flex style=\"color: white\">{{machine.failProb}}%</span>\n  <span flex style=\"color: white\">{{machine.name}}</span>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":590,"y":400,"wires":[[]]},{"id":"8ef4a641.d15bd8","type":"function","z":"a2c28c79.cc093","name":"Generate Data","func":"min = Math.round(Math.random()*1000);\nmax = Math.round((Math.random()*10000)+1000);\n\nmsg.payload = {\n  factory: {\n    machine00: {\n      min: min,\n      max: max,\n      failProb: 20,\n      name: \"Motor 1\"\n    },\n    machine01: {\n      min: min*5,\n      max: max*2,\n      failProb: 10,\n      name: \"Motor 2\"\n    }\n  }\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":400,"wires":[["d9b138a.0af01c8"]]},{"id":"a6bf36d8.cbc208","type":"inject","z":"a2c28c79.cc093","name":"","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":400,"wires":[["8ef4a641.d15bd8"]]},{"id":"d3a9b89b.2f7f78","type":"comment","z":"a2c28c79.cc093","name":"Water Filtration","info":"","x":140,"y":260,"wires":[]},{"id":"7c95683.1266b98","type":"comment","z":"a2c28c79.cc093","name":"Lighting Control Section","info":"","x":170,"y":480,"wires":[]},{"id":"85114ff.086d1b","type":"ui_switch","z":"a2c28c79.cc093","name":"","label":"{{label}}","tooltip":"","group":"81a6484a.884828","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":540,"wires":[["46630cc3.ad95a4"]]},{"id":"361879c9.18a566","type":"inject","z":"a2c28c79.cc093","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":540,"wires":[["5d1e3a18.1e59b4"]]},{"id":"46630cc3.ad95a4","type":"switch","z":"a2c28c79.cc093","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":130,"y":600,"wires":[["340e559b.3c6f0a"],["5d1e3a18.1e59b4"]]},{"id":"340e559b.3c6f0a","type":"change","z":"a2c28c79.cc093","name":"","rules":[{"t":"set","p":"label","pt":"msg","to":"Light is ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":540,"wires":[["85114ff.086d1b"]]},{"id":"5d1e3a18.1e59b4","type":"change","z":"a2c28c79.cc093","name":"","rules":[{"t":"set","p":"label","pt":"msg","to":"Light is OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":600,"wires":[["85114ff.086d1b"]]},{"id":"bc8ea5ba.170b08","type":"ui_slider","z":"a2c28c79.cc093","name":"","label":"Brightness","tooltip":"","group":"81a6484a.884828","order":1,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":0,"max":10,"step":1,"x":590,"y":640,"wires":[["e23fb00f.df439"]]},{"id":"e23fb00f.df439","type":"ui_toast","z":"a2c28c79.cc093","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"Brightness changed to:","name":"","x":790,"y":640,"wires":[]},{"id":"3d6220eb.12304","type":"ui_colour_picker","z":"a2c28c79.cc093","name":"","label":"Lighting Color","group":"81a6484a.884828","format":"hex","outformat":"string","showSwatch":true,"showPicker":false,"showValue":false,"showHue":false,"showAlpha":false,"showLightness":true,"square":"false","dynOutput":"false","order":2,"width":0,"height":0,"passthru":true,"topic":"","x":600,"y":700,"wires":[[]]},{"id":"26bbb454.e3be5c","type":"comment","z":"a2c28c79.cc093","name":"Food Dispenser Section","info":"","x":160,"y":740,"wires":[]},{"id":"8d4f4288.9d0b5","type":"ui_numeric","z":"a2c28c79.cc093","name":"","label":"Feeder rate (oz/minute)","tooltip":"","group":"9b81cf0.836273","order":0,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":10,"step":1,"x":630,"y":780,"wires":[["b0f56d48.a0acf"]]},{"id":"b0f56d48.a0acf","type":"ui_toast","z":"a2c28c79.cc093","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"Feeder dispensery is set to (oz/min)","name":"","x":870,"y":780,"wires":[]},{"id":"ebd3c894.8447d8","type":"ui_button","z":"a2c28c79.cc093","name":"","group":"9b81cf0.836273","order":1,"width":0,"height":0,"passthru":false,"label":"{{payload}}","tooltip":"","color":"","bgcolor":"{{colour}}","icon":"","payload":"press","payloadType":"str","topic":"","x":570,"y":840,"wires":[["e24a0f27.99d22"]]},{"id":"ac0dcf86.922d6","type":"change","z":"a2c28c79.cc093","name":"","rules":[{"t":"set","p":"colour","pt":"msg","to":"green","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"<i class=\"fa fa-rotate-90 fa-folder-open-o\"></i> OPENED FEEDER","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":840,"wires":[["ebd3c894.8447d8"]]},{"id":"c3bcf037.a9c97","type":"change","z":"a2c28c79.cc093","name":"","rules":[{"t":"set","p":"colour","pt":"msg","to":"red","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"<i class=\"fa fa-rotate-90 fa-folder-o\"></i> CLOSED FEEDER","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":900,"wires":[["ebd3c894.8447d8"]]},{"id":"da4ea327.fa00a","type":"inject","z":"a2c28c79.cc093","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":840,"wires":[["c3bcf037.a9c97"]]},{"id":"e24a0f27.99d22","type":"function","z":"a2c28c79.cc093","name":"State","func":"var state = context.state || false;\nstate = !state;\ncontext.state = state;\nif (state) { return [msg,null]; }\nelse { return [null,msg]; }","outputs":2,"noerr":0,"x":130,"y":900,"wires":[["ac0dcf86.922d6"],["c3bcf037.a9c97"]]},{"id":"f30d1ecd.61daa","type":"ui_group","z":"","name":"Temperature/ph monitor","tab":"c2f603e5.e52fe","order":1,"disp":true,"width":"6","collapse":false},{"id":"ffd8e6f4.96dd38","type":"ui_group","z":"","name":"Water filtration","tab":"c2f603e5.e52fe","order":2,"disp":true,"width":"12","collapse":false},{"id":"81a6484a.884828","type":"ui_group","z":"","name":"Lighting","tab":"c2f603e5.e52fe","order":3,"disp":true,"width":"6","collapse":false},{"id":"9b81cf0.836273","type":"ui_group","z":"","name":"Food Dispenser","tab":"c2f603e5.e52fe","order":4,"disp":true,"width":"6","collapse":false},{"id":"c2f603e5.e52fe","type":"ui_tab","z":"","name":"Fish Tank","icon":"dashboard","order":1,"disabled":false,"hidden":false}]