The result of your query string is forcing the value to be interpreted as an integer by SQL. You must surround your string with single quotes for SQL to properly see it as a string.
include single quotes arouond the content of the msg.payload for SQL to know it's a string.
example:
pld = pld + "WHERE '" + msg.payload + "' in (select value from string... blah blah blah"
resulting string will be like this .. WHERE 'VR1148' in(select value from string... blah blah blah
Great idea. Well, I seem to have broken it. I get the dreaded "TypeError: sql.ConnectionPool is not a constructor" error. You posted to someone with this problem, and this is what I did. I used the pallate to uninstall MSSQL and installed MSSQL-Plus. Unfortunately, I dont really know where node-red is installed, nor how to manipulate it via ssh. Its like its not really on my server. I suppose it could be a docker or something. What I do know, is I cannot reboot the server because the server is supporting other things. I have to ping my admin to restart it and thats a pain.
So, in that post, you describe how you uninstall and install nodes. However, not what to do after the fact.
Lastly, a bit off topic... I see a LOT of things about how node red is basically only to play around in a test environment. However, I was planning to use this for as an applet between a few PLCs and SQL in a production environment. My NodeRed is on a full featured HP server, not on a Rasberry Pi. Should I be concerned about using NodeRed in this manner? I would have no clue how else to tackle such a project.
Definitely not. It works and it works well. Why prototype on node-red, test it works then rewrite it in a complied application that will prevent all the nice runtime monitoring and ease of fix in the event of a bug. In my previous job I used node red to gather thousands of data points from lots of different PLCs, atlas copco tooling, hundreds of Fanuc robots & more, present the data in MQTT and store them in a database. It would have been crazy to replicate this in a custom application or a proprietary application.
Also the Raspberry Pi is not a toy computer, it's a range of small, low power computers, some specifically designed for industrial uses.
Your application might push the I/O, memory, or CPU constraints (or not), in which case a beefier server might be appropriate. A few PLCs and SQL isn't going to need a supercomputer.
Of course you might get fired for recommending free software on a single board computer.
I might have been a bit unclear there. The notion was not my idea that node-red was suitable for production or not. I have seen a lot of forum posts that have said that it isnt. I havent personally seen anything specifically unreliable with it at all. I have installed it on a VM on a HP server, and its working great. I was wanting some real reason why it would NOT be proper for a production setup. I intend to use it as such, because I have no capacity to develop any other API.
My fault for hijacking my own post, but what can you give me for advice on what do to now that I have this ConnectionPool error? Its too late to do what you do when installing/uninstalling. Its broke, and I need it fixed.
Hmm, this is interesting. I was wondering how I would use this for multiple PLC's of identical setup, and identical function. I was thinking I would use multiple MQTT inputs, becuase there would be the case where more than one PLC would trigger node-red at the same time. I was thinking that each PLC would use a different port number to distinguish between them. I will cross that bridge later. But, I think I can figure that out. Ill post another thread on that one.
That is not the way to do it. You would have one MQTT broker and the PLCs would publish to different top level topics with the same structure underneath. You don't need to worry about multiple PLCs publishing at the same time, the network layer and the broker will sort that out.
Also, although node-red is single threaded, provided you have sufficient processor power that is usually irrelevant and the messaging architecture gives the impression of everything happening at once. The only time it is an issue is if you have a task that needs a large amount of processor in one go, image processing for example, in which case you might need to farm that out to a separate process.
MQTT would use a different TOPIC. The broker would be on the same port. Then you'd need a PLC that can speak MQTT... If you used TCP, then you'd need each PLC to be on a different port. MQTT would be the best way to ensure you catch all asynchronous values. Node-RED can also be used with TCP because each port connection would be monitored separately. I would suggest you "MODEL" or test your methods and then you can see if there would be any bandwidth failures.
The reason you see the many instances of "TESTING" is because the programming format makes it incredibly easy to test and figure things out to create efficient means of solving problems. That is the one thing that I like about Node-RED.
Question: Since the first question was about MSSQL, are you collecting data from PLC's to send to a SQL Server? Can you give a more direct description of your project? Thanks.
Not difficult though, it used a list (array) of objects --> split node that ran the following flow for each robot: HTTP Request node to grab specific pages from the robots web server, split out the IO, Registers and alarms, publish them to MQTT and/or store interesting items in database.