[ { "id": "6aa79e5e.670b2", "type": "tab", "label": "Flow 2" }, { "id": "ee14c859.58d508", "type": "function", "z": "6aa79e5e.670b2", "name": "SetActive()", "func": "var ID;\n\n\nID = global.get('ID'); //Get the global ID for the current read RFID\n\n//If the database, from the last node, gives an array with a lenght longer than 0, the RFID is connected to an user\n//If the response is an array with 0 elements the RFID is connected to a product.\n\n//First clear the current actives, then make the user/product with the correct RFID active.\nif (msg.payload.length > 0) {\n \n var clearUsers = {\n topic : \n \"UPDATE users SET Active = '0' WHERE Active = '1';\"\n };\n\n var setUser = {\n topic : \n \"UPDATE users SET Active = '1' WHERE RFID='\" + ID +\"';\"\n };\n \n return [clearUsers,setUser];\n}\n\nelse {\n var clearProducts = {\n topic :\n \"UPDATE products SET Active = '0' WHERE Active ='1';\"\n };\n\n var setProduct = {\n topic: \n \"UPDATE products SET Active='1' WHERE RFID='\" + ID + \"';\"\n };\n\n return [clearProducts,setProduct];\n}\n\n", "outputs": "2", "noerr": 0, "x": 550, "y": 160, "wires": [ [ "d02e0a11.6d67b8" ], [ "e31a04ec.b76fc8" ] ] }, { "id": "d02e0a11.6d67b8", "type": "mysql", "z": "6aa79e5e.670b2", "mydb": "f6d3334a.9585f", "name": "", "x": 782, "y": 114, "wires": [ [ "4322e227.61a0ac" ] ] }, { "id": "e31a04ec.b76fc8", "type": "mysql", "z": "6aa79e5e.670b2", "mydb": "f6d3334a.9585f", "name": "", "x": 782, "y": 161, "wires": [ [ "627214dd.a035ac" ] ] }, { "id": "4322e227.61a0ac", "type": "debug", "z": "6aa79e5e.670b2", "name": "", "active": true, "console": "false", "complete": "false", "x": 990, "y": 106, "wires": [] }, { "id": "627214dd.a035ac", "type": "debug", "z": "6aa79e5e.670b2", "name": "", "active": true, "console": "false", "complete": "false", "x": 974, "y": 152, "wires": [] }, { "id": "40451b3f.0b1d94", "type": "serial in", "z": "6aa79e5e.670b2", "name": "Arduino", "serial": "c1da6854.cded38", "x": 77, "y": 333, "wires": [ [ "8fd1de1c.7f172", "7bb23e68.94ccf" ] ] }, { "id": "8fd1de1c.7f172", "type": "debug", "z": "6aa79e5e.670b2", "name": "", "active": true, "console": "false", "complete": "false", "x": 230, "y": 380, "wires": [] }, { "id": "7bb23e68.94ccf", "type": "function", "z": "6aa79e5e.670b2", "name": "UserOrProduct", "func": "var ID = msg.payload;\nID = ID.replace(/\\s+/g, '') //Remove all whitespace in the incoming string\n\nglobal.set('ID',ID); //Store the ID in context, so we can access it later\n\n//Request the database if the read RFID is connected to a user.\nmsg = {\n topic:\n \"SELECT * FROM users WHERE RFID = '\" + ID + \"';\"\n}\nreturn msg;", "outputs": 1, "noerr": 0, "x": 240, "y": 200, "wires": [ [ "8742959c.fdee48" ] ] }, { "id": "ae5e4301.8f135", "type": "debug", "z": "6aa79e5e.670b2", "name": "", "active": true, "console": "false", "complete": "false", "x": 570, "y": 443, "wires": [] }, { "id": "8742959c.fdee48", "type": "mysql", "z": "6aa79e5e.670b2", "mydb": "f6d3334a.9585f", "name": "", "x": 410, "y": 300, "wires": [ [ "ae5e4301.8f135", "ee14c859.58d508" ] ] }, { "id": "f6d3334a.9585f", "type": "MySQLdatabase", "z": "", "host": "127.0.0.1", "port": "3306", "db": "warehouse", "tz": "" }, { "id": "c1da6854.cded38", "type": "serial-port", "z": "", "serialport": "/dev/ttyACM0", "serialbaud": "9600", "databits": "8", "parity": "none", "stopbits": "1", "newline": "\\n", "bin": "false", "out": "char", "addchar": false } ]