RFID-Locker (array-buffer, script)

#1

Good day,

I want to rebuild the locker at my gym from old-fashioned keys to RFID lockers.
The necessary hardware is already installed with electric locks etc.

The goal is that someone logs in with an rfid card, the number of the card is stored in an array buffer and then the index of the arrray buffer specifies which box is assigned. The user can also give the box back.

I am quite new in programming with javascript, I would have liked some help with two scripts.

  1. Check if the rfid tag is already present in a array buffer with a "fuction" node with include() function, https://www.w3schools.com/jsref/jsref_includes_array.asp

    1 input, check array with include() function
    2 outputs,
    output1. ask user on touchscreen if he wants to have a new box, wen yes, feed array buffer.
    output2. wenn already in array buffer activate script 2.

  2. when an rfid tag is added or already in the array buffer, a script will have to check which number has been added or rejected. the rejected or added number must activate the output where the rejected or added number is located.

My flow:
[[{"id":"cbba1eb1.b93f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"96ac12a0.2030a","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1234","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":60,"wires":[["9935b124.cd838"]]},{"id":"9935b124.cd838","type":"function","z":"cbba1eb1.b93f","name":"","func":"return msg;","outputs":2,"noerr":0,"x":350,"y":80,"wires":[["6fe7680d.7b3558"],["886e8cdc.2823a"]]},{"id":"49546dac.f6d674","type":"buffer-array","z":"cbba1eb1.b93f","name":"Buffer","bufferLen":"5","startWhenFilled":false,"x":710,"y":40,"wires":[["b939c2ba.d095e","9935b124.cd838","886e8cdc.2823a"]]},{"id":"2dc40173.87c9ae","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":100,"wires":[["9935b124.cd838"]]},{"id":"874b88d8.1f90e8","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"0910","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":140,"wires":[["9935b124.cd838"]]},{"id":"355d3caf.802774","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1213","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["9935b124.cd838"]]},{"id":"f699c2b1.c63c2","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1415","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":220,"wires":[["9935b124.cd838"]]},{"id":"a8d09bb.e53f868","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1617","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":260,"wires":[["9935b124.cd838"]]},{"id":"886e8cdc.2823a","type":"function","z":"cbba1eb1.b93f","name":"","func":"var msg5 = msg.payload.map(function (p) {\n return {payload: p};\n});\nreturn msg5;","outputs":5,"noerr":0,"x":910,"y":120,"wires":[["7a12ef0b.f8402"],["ad3e813e.f6d6"],["f759495b.49c8a8"],["5bfca401.c7c5bc"],["ecbbc239.059e9"]]},{"id":"7a12ef0b.f8402","type":"debug","z":"cbba1eb1.b93f","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":80,"wires":[]},{"id":"ad3e813e.f6d6","type":"debug","z":"cbba1eb1.b93f","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":100,"wires":[]},{"id":"f759495b.49c8a8","type":"debug","z":"cbba1eb1.b93f","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":120,"wires":[]},{"id":"5bfca401.c7c5bc","type":"debug","z":"cbba1eb1.b93f","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":140,"wires":[]},{"id":"ecbbc239.059e9","type":"debug","z":"cbba1eb1.b93f","name":"5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":160,"wires":[]},{"id":"b939c2ba.d095e","type":"debug","z":"cbba1eb1.b93f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":40,"wires":[]},{"id":"6fe7680d.7b3558","type":"ui_button","z":"cbba1eb1.b93f","name":"","group":"a521fb86.7294d8","order":0,"width":0,"height":0,"passthru":false,"label":"button","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":510,"y":40,"wires":[["49546dac.f6d674"]]},{"id":"a521fb86.7294d8","type":"ui_group","z":"","name":"Default","tab":"","disp":true,"width":"6","collapse":false}]]([{"id":"cbba1eb1.b93f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"96ac12a0.2030a","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1234","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":60,"wires":[["9935b124.cd838"]]},{"id":"9935b124.cd838","type":"function","z":"cbba1eb1.b93f","name":"","func":"return msg;","outputs":2,"noerr":0,"x":350,"y":80,"wires":[["6fe7680d.7b3558"],["886e8cdc.2823a"]]},{"id":"49546dac.f6d674","type":"buffer-array","z":"cbba1eb1.b93f","name":"Buffer","bufferLen":"5","startWhenFilled":false,"x":710,"y":40,"wires":[["b939c2ba.d095e","9935b124.cd838","886e8cdc.2823a"]]},{"id":"2dc40173.87c9ae","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":100,"wires":[["9935b124.cd838"]]},{"id":"874b88d8.1f90e8","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"0910","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":140,"wires":[["9935b124.cd838"]]},{"id":"355d3caf.802774","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1213","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["9935b124.cd838"]]},{"id":"f699c2b1.c63c2","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1415","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":220,"wires":[["9935b124.cd838"]]},{"id":"a8d09bb.e53f868","type":"inject","z":"cbba1eb1.b93f","name":"","topic":"","payload":"1617","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":260,"wires":[["9935b124.cd838"]]},{"id":"886e8cdc.2823a","type":"function","z":"cbba1eb1.b93f","name":"","func":"var msg5 = msg.payload.map(function (p) {\n return {payload: p};\n});\nreturn msg5;","outputs":5,"noerr":0,"x":910,"y":120,"wires":[["7a12ef0b.f8402"],["ad3e813e.f6d6"],["f759495b.49c8a8"],["5bfca401.c7c5bc"],["ecbbc239.059e9"]]},{"id":"7a12ef0b.f8402","type":"debug","z":"cbba1eb1.b93f","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":80,"wires":[]},{"id":"ad3e813e.f6d6","type":"debug","z":"cbba1eb1.b93f","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":100,"wires":[]},{"id":"f759495b.49c8a8","type":"debug","z":"cbba1eb1.b93f","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":120,"wires":[]},{"id":"5bfca401.c7c5bc","type":"debug","z":"cbba1eb1.b93f","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":140,"wires":[]},{"id":"ecbbc239.059e9","type":"debug","z":"cbba1eb1.b93f","name":"5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":160,"wires":[]},{"id":"b939c2ba.d095e","type":"debug","z":"cbba1eb1.b93f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":40,"wires":[]},{"id":"6fe7680d.7b3558","type":"ui_button","z":"cbba1eb1.b93f","name":"","group":"a521fb86.7294d8","order":0,"width":0,"height":0,"passthru":false,"label":"button","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":510,"y":40,"wires":[["49546dac.f6d674"]]},{"id":"a521fb86.7294d8","type":"ui_group","z":"","name":"Default","tab":"","disp":true,"width":"6","collapse":false}])

0 Likes

Help with a function node
#2

I would suggest using an alternative approach, which I think is a much better match to the problem. Use an sqlite database to save the user/box assignment data. Then you can query the database to find the box that a particular user has, or which user has a particular box and so on. I would probably have a table with a record for every box and a field containing current user id or zero to mean the box is free. Something like that anyway.

0 Likes

#3

Thank you, sqlite is great!

0 Likes