I’m writing a plugin that has a global “config” component that contains IP, port, username, and password for a remote server. The user then sets an ID in the node which corresponds to data supplied by the server. The server can contain thousands of individual data items, so I wrote the plugin so the the user can basically query the server for the correct ID. For now, I’m hard coding the server IP, port, username, and password for proof of concept. How can I get that information from the global “config”?
I’m still learning Node Red. If I understand correctly, the global “config” is code that runs on the node server side, and the Ui code runs on the browser side, I am very familiar with Node application development so I know how exchange data between client and server, if I have to do it myself. But I assume there are Node Red specific methods.
YAMCS is a open source ground control system typically used to remotely control and monitor spacecraft. It has a web.based API. I am writing code (plugin, node, whatever it should be called) that interfaces to YAMCS via the web based API. I actually got it working without having to write any code, using a few of the existing nodes together. I’m writing code to make a specialized node specifically for YAMCS.
The code I wrote let’s you specify the server first, and associate the node with the server configuration. Tabbed completed, you’ll enter the name of the parameter. When you deploy, it will login to the server, subscribe to the parameter[s), and send a message containing the current t value of the parameter enter every time there is a new update. I have all that working. I’m just making it more convenient for the user by combining multiple nodes into a single node.
For an added convenience, as you enter in the qualified path and name of the parameter enter, it queries the server and shows you suggestions. Similar to when you enter in Google queries. That part currently executes entirely on the browser side, though I might move some of that to the node side to proxy the connection so I can’t avoid CORS issues. I have this feature working too, but I have the ip, port, and other configuration hard coded. I want to read it from the config.
I feel like we're getting wrapped up in terminology. I'm not using the correct terminology here, and I apologize. I'm still learning this project's terminology. Not global data. Its similar to the "Server" property of the "mqtt" node. There is a button with a pencil on it that opens another dialog to either add or edit the "mqtt-broker" node, and where you specify the IP address and the port. Whatever that is called, I have an identical "yamcsconfig" node where you set the server IP and the port. I'm asking how I can read that server IP and port from the UI controller code that runs on the browser side.
That might be another miscommunication on my part. I'm not sure what the difference between a plugin and a node is in this case. Judging by the link you just gave me, I am writing a node. None of what I already described is hypothetical. What I wrote, whether its a node or a plugin, is fully functional now. When I run Node Red, I see the "YAMCS" node I created. I can click and drag it to my flow. I can create a new config node and set the IP and port. I can fill in the additional properties and it persists. I'm just trying to determine how I can read the IP and port number from the configuration node.
Once deployed, the code uses this to fulfill its primary purpose by subscribing to data and sending out to the next node(s). But while the user is still configuring the flow, I thought it would be nice to let them query the server for the parameter ID. That part works perfectly. I just have to, temporarily, hard code the IP and port of the server that its querying. As the user enters in the parameter name/id, after X number of characters (currently hard coded to 5), it then starts querying the server for parameters that start with the name already entered. It presents the potential parameters as a drop down. The user can either continue manually entering the parameter in, further refining the search, or click on one of the entries in the drop down list. Basically, I implemented a user select-able autocomplete feature for that particular field.
you have a yamcsconfig config node that has the server info (IP address, port, creds, etc)
you have a yamcs node
the yamcs node has a field that is the server field where the user selects the appropriate yamcsconfig config node
the yamcs node has another field where you'd like to populate a drop-down by querying the server
this means that when the user selects a server, you need to kick off an ajax request to get the info for the drop down
when the edit dialog is initially brought up you also need to kick off that request
you're asking "how do I get a handle onto the selected yamcsconfig config node so I can construct the request?"
I suspect:
you need an onchange handler to detect when the user selects a server
you need the initial ajax request to be sent from the oneditprepare callback
you can get the selected yamcsconfig node ID from the input field that has the selected attribute (yeah...)
you can then get a handle onto the yamcsconfig node object by calling RED.nodes.node(id)
I'm also pretty sure:
you will spend quite some time in your browser's "inspect" panel looking for how the server selection drop-down is coded in HTML and how you can tease out the currently selected input
“you can then get a handle onto the yamcsconfig node object by calling RED.nodes.node(id)”
Perfect. That’s exactly what I’m looking for. Thanks!
“you will spend quite some time in your browser's "inspect" panel looking for how the server selection drop-down is coded in HTML and how you can tease out the currently selected input”
I already have it working, but I will still take that drink.