RFID Homie Scanner

#RFID SCANNER

  • This flow listens to an RFID scanner via MQTT.

  • A switch node then assigns a workflow based on the 'uid' received.

  • An authorization message is sent back to the device by setting the 'validate' property.

##Device Info

Written by Cory Guynn, 2016

http://www.InternetOfLEGO.com

[{"id":"fa87e6c6.1d8cc8","type":"mqtt in","z":"63bfebb7.244c94","name":"","topic":"sensors/e1b47ae0/RFID-1/uid","qos":"1","broker":"","x":490,"y":360,"wires":[["1bdf7f20.38ad31","91d54acf.67ffb8"]]},{"id":"b04c5a7.77c5ea8","type":"switch","z":"63bfebb7.244c94","name":"RFID Tags","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"d1f21b2b","vt":"str"},{"t":"eq","v":"94587b25","vt":"str"},{"t":"eq","v":"f58a89","vt":"str"},{"t":"eq","v":"b5482a50","vt":"str"},{"t":"else"}],"checkall":"true","outputs":5,"x":744,"y":400,"wires":[["16d4f51e.8fac4b"],["16d4f51e.8fac4b"],["16d4f51e.8fac4b"],["16d4f51e.8fac4b","e6042f72.167f2"],["922b0d09.2f28c"]]},{"id":"93360b06.45bc58","type":"function","z":"63bfebb7.244c94","name":"{\"command\":\"disco\"}","func":"msg.payload = {\"command\":\"disco\"};\nreturn msg;","outputs":1,"noerr":0,"x":1030,"y":540,"wires":[["689fa502.b8091c"]]},{"id":"db3672a8.7af4d","type":"mqtt out","z":"63bfebb7.244c94","name":"","topic":"iol/command","qos":"","retain":"","broker":"","x":1440,"y":540,"wires":[]},{"id":"859e51b4.6f05d","type":"inject","z":"63bfebb7.244c94","name":"","topic":"","payload":"disco","payloadType":"str","repeat":"","crontab":"","once":false,"x":760,"y":540,"wires":[["93360b06.45bc58"]]},{"id":"1bdf7f20.38ad31","type":"debug","z":"63bfebb7.244c94","name":"sensors/e1b47ae0/RFID-1/uid","active":false,"console":"false","complete":"payload","x":800,"y":320,"wires":[]},{"id":"7ccd4bbc.a33c14","type":"inject","z":"63bfebb7.244c94","name":"Forward","topic":"motor","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":770,"y":680,"wires":[["97de3d4f.09ce3"]]},{"id":"7772d1b5.57aa5","type":"inject","z":"63bfebb7.244c94","name":"Stop","topic":"motor","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":760,"y":720,"wires":[["1222783b.9d60a8"]]},{"id":"60cd775c.5817b8","type":"mqtt out","z":"63bfebb7.244c94","name":"","topic":"trains/horizonexpress/motor","qos":"","retain":"","broker":"","x":1390,"y":680,"wires":[]},{"id":"97de3d4f.09ce3","type":"function","z":"63bfebb7.244c94","name":"1024","func":"msg.payload = 1024;\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":680,"wires":[["60cd775c.5817b8"]]},{"id":"1222783b.9d60a8","type":"function","z":"63bfebb7.244c94","name":"0","func":"msg.payload = 0;\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":720,"wires":[["60cd775c.5817b8"]]},{"id":"d805e73a.9b8ef8","type":"mqtt in","z":"63bfebb7.244c94","name":"","topic":"sensors/e1b47ae0/#","qos":"0","broker":"","x":520,"y":820,"wires":[["bf88fba4.4b4248","4eab4327.7b382c","3cdd12e6.f1b36e"]]},{"id":"bf88fba4.4b4248","type":"debug","z":"63bfebb7.244c94","name":"sensors/e1b47ae0/#","active":true,"console":"false","complete":"payload","x":810,"y":820,"wires":[]},{"id":"689fa502.b8091c","type":"delay","z":"63bfebb7.244c94","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":1260,"y":540,"wires":[["db3672a8.7af4d"]]},{"id":"5d4c7be.3818584","type":"mqtt out","z":"63bfebb7.244c94","name":"","topic":"sensors/e1b47ae0/RFID-1/validate/set","qos":"","retain":"","broker":"","x":1360,"y":420,"wires":[]},{"id":"16d4f51e.8fac4b","type":"function","z":"63bfebb7.244c94","name":"msg.payload = \"granted\";","func":"msg.topic = msg.payload;\nmsg.payload = \"granted\";\nreturn msg;","outputs":1,"noerr":0,"x":1035,"y":366,"wires":[["5d4c7be.3818584","74d47dfa.8ba9f4","9f30dea5.5f539"]]},{"id":"922b0d09.2f28c","type":"function","z":"63bfebb7.244c94","name":"msg.payload = \"denied\";","func":"msg.topic = msg.payload;\nmsg.payload = \"denied\";\nreturn msg;","outputs":1,"noerr":0,"x":1035,"y":426,"wires":[["5d4c7be.3818584","9f30dea5.5f539"]]},{"id":"e6042f72.167f2","type":"trigger","z":"63bfebb7.244c94","op1":"1024","op2":"0","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","name":"","x":990,"y":640,"wires":[["60cd775c.5817b8"]]},{"id":"92d7fe76.0204f","type":"comment","z":"63bfebb7.244c94","name":"RFID Scanner","info":"This flow receives the UID from the RFID scanner\nvia MQTT. The RFID tags are compared against \nseveral workflow options, such as disco, train,etc.\n\nA grant/deny message is sent back to the RFID\nscanner, using the Homie convention. \nhttps://github.com/marvinroger/homie\n\nComplete write-up on the IoL blog:\nwww.InterentOfLEGO.com\n\nwritten by \nCory Guynn\n2016","x":440,"y":280,"wires":[]},{"id":"d02e2bfb.d4e418","type":"comment","z":"63bfebb7.244c94","name":"README","info":"#RFID SCANNER\n\n* This flow listens to an RFID scanner via MQTT.\n\n* A switch node then assigns a workflow based on\nthe 'uid' received.\n\n* An authorization message is sent back to the device \nby setting the 'validate' property.\n\n##Device Info \n* WeMos d1-mini (ESP8266 dev board)\nhttp://www.wemos.cc/Products/d1_mini.html\n\n* RFID RC522\nhttp://playground.arduino.cc/Learning/MFRC522\n\n* Homie MQTT framework\nhttps://github.com/marvinroger/homie/tree/master\n\n\n\n\n## Written by Cory Guynn, 2016\nwww.InternetOfLEGO.com\n\n\n\n","x":510,"y":320,"wires":[]},{"id":"6b642be4.64d5a4","type":"comment","z":"63bfebb7.244c94","name":"Workflows","info":"","x":550,"y":460,"wires":[]},{"id":"73488786.e745a8","type":"comment","z":"63bfebb7.244c94","name":"Disco Cinema","info":"","x":680,"y":500,"wires":[]},{"id":"1c19a02e.87d59","type":"comment","z":"63bfebb7.244c94","name":"Train Routine","info":"","x":680,"y":620,"wires":[]},{"id":"efe17b75.3abea8","type":"comment","z":"63bfebb7.244c94","name":"MQTT Monitor","info":"","x":470,"y":760,"wires":[]},{"id":"9f30dea5.5f539","type":"ui_toast","z":"63bfebb7.244c94","name":"RFID","x":1460,"y":380,"wires":[]},{"id":"74d47dfa.8ba9f4","type":"link out","z":"63bfebb7.244c94","name":"UID Granted","links":["5d757514.cce78c","d9391786.7a6b58","7a52bfa0.58d78","409fd8ad.03b418"],"x":1485,"y":340,"wires":[]},{"id":"5d757514.cce78c","type":"link in","z":"63bfebb7.244c94","name":"","links":["74d47dfa.8ba9f4"],"x":645,"y":540,"wires":[["93360b06.45bc58"]]},{"id":"3ff274d3.5ea1cc","type":"ui_template","z":"63bfebb7.244c94","group":"c1f17c9b.5b9f5","name":"RFID-1 Log","order":2,"width":"6","height":"7","format":"<h1>Event Log</h1>\n<div>\n<ul>\n <li ng-repeat=\"x in msg.payload\">\n <font color=\"red\">{{x.topic}}</font>\n    <ul>\n        <li>{{x.payload}}</li>\n    </ul>\n </li>\n</ul>\n</div>","storeOutMessages":true,"fwdInMessages":true,"x":1100,"y":860,"wires":[[]]},{"id":"4eab4327.7b382c","type":"function","z":"63bfebb7.244c94","name":"Store and shift msg","func":"\n\n\n// initialise the counter to 0 if it doesn't exist already\nvar text = context.get('text')|| [];\n\ntext.push(msg);\nif (text.length > 5){\n    text.shift();\n    text.length = 5;\n} \n\n// store the value back\ncontext.set('text',text);\n// make it part of the outgoing msg object\nmsg = {};\nmsg.payload = text;\nreturn msg;\n","outputs":1,"noerr":0,"x":800,"y":860,"wires":[["3ff274d3.5ea1cc","c045ad6a.229d3"]]},{"id":"c045ad6a.229d3","type":"debug","z":"63bfebb7.244c94","name":"RFID-1 log","active":true,"console":"false","complete":"payload","x":1100,"y":900,"wires":[]},{"id":"91d54acf.67ffb8","type":"delay","z":"63bfebb7.244c94","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":560,"y":400,"wires":[["b04c5a7.77c5ea8"]]},{"id":"3cdd12e6.f1b36e","type":"function","z":"63bfebb7.244c94","name":"store Homie state","func":"\n\n\n// initialise the state to empty object if it doesn't exist already\nvar state = context.get('state')|| {};\n\n// regular expression to look for Homie updates\nvar t;\nvar re = /([^/]+$)/i;\nt = re.exec(msg.topic);\nvar prop = t[0];\n\n// remove preceding $\nif (prop.substring(0, 1) == '$') { \n  prop = prop.substring(1);\n}\n\n// Store state\nstate[prop] = msg.payload;\ncontext.set('state',state);\n\n// send state object\nmsg.payload = state;\nreturn msg;\n","outputs":1,"noerr":0,"x":800,"y":960,"wires":[["ca3ba7bf.90d298","cb60cc79.c5af8"]]},{"id":"ca3ba7bf.90d298","type":"debug","z":"63bfebb7.244c94","name":"RFID-1 State","active":true,"console":"false","complete":"payload","x":1100,"y":960,"wires":[]},{"id":"cb60cc79.c5af8","type":"ui_template","z":"63bfebb7.244c94","group":"c1f17c9b.5b9f5","name":"RFID-1 State","order":1,"width":"6","height":"6","format":"<h1>{{msg.payload.name}}</h1>\n<p ng-style=\"{color: msg.payload.online === 'true' ? 'green' : 'red'}\">\n    {{msg.payload.online === 'true' ? 'ONLINE' : 'OFFLINE'}}\n</p>\n<hr>\n<table>\n<tr ng-repeat=\"(key, value) in msg.payload\">\n  <td> {{key}} </td> <td> {{ value }} </td>\n</tr>\n</table>\n\n","storeOutMessages":false,"fwdInMessages":true,"x":1100,"y":1000,"wires":[[]]},{"id":"c1f17c9b.5b9f5","type":"ui_group","z":"63bfebb7.244c94","name":"RFID","tab":"632f8c33.b2a4f4","order":6,"disp":true,"width":"6"},{"id":"632f8c33.b2a4f4","type":"ui_tab","z":"","name":"IoL City - Master Dashboard","icon":"dashboard","order":3}]

Flow Info

Created 8 years, 3 months ago
Updated 7 years, 8 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x6)
  • debug (x4)
  • delay (x2)
  • function (x7)
  • inject (x3)
  • link in (x1)
  • link out (x1)
  • mqtt in (x2)
  • mqtt out (x3)
  • switch (x1)
  • trigger (x1)
Other
  • ui_group (x1)
  • ui_tab (x1)
  • ui_template (x2)
  • ui_toast (x1)

Tags

  • esp8266
  • homie
  • mqtt
  • wifi
  • rfid
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option