Deploy failed: no response from server does not indicate any problem with your function code.
It indicates a communication problem between the browser and Node-red. Perhaps Node-red is no longer running, perhaps it's a network issue.
Can you give us the details of what computer Node-red is installed on and what computer is running the browser?
What URL did you use to access the editor?
That said, I do think there are issues with your code.
In the first version you seem to be mixing up this syntax for common-or-garden variables and that for environment variables (I rarely use environment variables so I'm not certain)
In the second you are hard coding the values into msg.topic. It's legal in MySQL but bad form because this kind of INSERT is less secure than a "prepared query", which I think your first attempt is supposed to do.
This is what the query statement looks like... (note: In this example all the items are 'strings')
If any of the items are numeric, then leave-off the leading and trailing primes as below...
It's running in a Docker container, and I've verified it's operational, as when I remove the INSERT code, it's able to deploy just fine. Again, I can pull data from the maria DB.
Look in the node red log and see what it shows when you deploy. I don't know how to do that in docker but hopefully you do, since you are using it.
Edit: in fact first disconnect the DB node input and instead feed the function node into a debug node set to output complete message and deploy that. Assuming it deploys, check the message is as you expect.
Ignore the syntax of the queries for a moment, as they don't matter currently. The problem is this builds and deploys:
let ip_add = msg.payload.camera?.settings?.ip || "0.0.0.0";
let mac_add = msg.payload.camera?.settings?.mac || "Unknown";
let area = msg.payload.camera?.settings?.area || "Unknown";
let timestamp = msg.payload.camera?.settings?.timestamp || new Date().toISOString();
let url = msg.payload.camera?.settings?.url || "";
msg.topic = 'INSERT * dwell_time_alerts LIMIT 1';
node.warn(msg.topic); // Log the query to Node-RED console
return msg;
This does NOT:
let cam_name = msg.payload.camera?.settings?.name || "Unknown";
let ip_add = msg.payload.camera?.settings?.ip || "0.0.0.0";
let mac_add = msg.payload.camera?.settings?.mac || "Unknown";
let area = msg.payload.camera?.settings?.area || "Unknown";
let timestamp = msg.payload.camera?.settings?.timestamp || new Date().toISOString();
let url = msg.payload.camera?.settings?.url || "";
msg.topic = 'INSERT INTO dwell_time_alerts LIMIT 1';
node.warn(msg.topic); // Log the query to Node-RED console
return msg;
The word INTO is causing it to not build/deploy. How can that be?
Now Node-red is not going to be validating SQL syntax in a string at deploy (or any other) time but what's going on with LIMIT1 at the end of the INSERT statement? Is that really valid syntax?
If the db node is hanging soon after deploy then it might look as if the Deploy is not completing. That is why I have asked @djackson-telaid to try it with the db node not connected, and also to show the log while trying to deploy, which he has also not responded to.
@djackson-telaid Can you post an example of the msg.payload you are feeding into the function? (Use the copy value button in the debug sidebar, not a screenshot)
Also the exact SQL query syntax that your first posted function node is intended to generate from it.
So it turns out, it was "deploying" the changes all along, but reporting no response from the server. After rebooting the machine and hard-refreshing the screen, the changes took regardless. Not sure why it's doing it, but thanks for all your help.