The user was experiencing issues with passing msg.payload correctly to the SQL statement in a Node-RED flow using SQLite node. Despite attempts to configure the flow to insert RFID data into a database table, the data was not being saved. Various adjustments were made to the function node to correctly prepare the SQL query and parameters, but the issue persisted.
The user attempted several adjustments in their Node-RED flow to resolve the issue of not being able to save RFID data into an SQLite database table:
They modified the Function node to correctly prepare msg.payload, ensuring uid and timestamp were properly included.
Adjustments were made to the SQL node configuration to use msg.payload.sql for the SQL statement and msg.payload.params for the parameters.
Debug outputs were used to verify that msg.payload contained the expected uid and timestamp values before passing them to the SQL node.
Despite these efforts, the user expected the RFID data (uid and timestamp) to be successfully inserted into the SQLite database table upon reading a RFID card, but the data was not being saved as intended.
[
{
"id": "0cb2bc183ab9df77",
"type": "tab",
"label": "RFID Log",
"disabled": false,
"info": ""
},
{
"id": "7ef5e73544386326",
"type": "serial in",
"z": "0cb2bc183ab9df77",
"name": "",
"serial": "84095b4c7122f283",
"x": 160,
"y": 120,
"wires": [
[
"872a010ada0321b6"
]
]
},
{
"id": "872a010ada0321b6",
"type": "function",
"z": "0cb2bc183ab9df77",
"name": "Process RFID Data",
"func": "let uid = msg.payload.uid;nlet timestamp = msg.payload.timestamp;nmsg.payload = {n sql: "INSERT INTO rfid_logs (uid, timestamp) VALUES (?, ?)",n params: [uid, timestamp]n};nreturn msg;n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 120,
"wires": [
[
"74ac2d7a071231a6",
"78cfd6cfc4de8241"
]
]
},
{
"id": "74ac2d7a071231a6",
"type": "debug",
"z": "0cb2bc183ab9df77",
"name": "Debug RFID Data",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 600,
"y": 120,
"wires": []
},
{
"id": "78cfd6cfc4de8241",
"type": "sqlite",
"z": "0cb2bc183ab9df77",
"mydb": "1daa2288530db980",
"sqlquery": "msg.payload.sql",
"sql": "",
"name": "",
"x": 620,
"y": 200,
"wires": [
[]
]
},
{
"id": "84095b4c7122f283",
"type": "serial-port",
"z": "0cb2bc183ab9df77",
"serialport": "COM4",
"serialbaud": "9600",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"dtr": "none",
"rts": "none",
"cts": "none",
"dsr": "none",
"newline": "\n",
"bin": "false",
"out": "char",
"addchar": "",
"responsetimeout": "10000"
},
{
"id": "1daa2288530db980",
"type": "sqlitedb",
"z": "0cb2bc183ab9df77",
"db": "C:\Users\Can\Desktop\rfid\testuser.db",
"mode": "RWC"
}
]