How does the UI access global “config” data

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.

Are you writing a plugin or a node? Nothing in your description suggests to me that you should be writing a plugin, but I may not understand...

Where is that code located? In a .js file running on Node.js or in a .html file running in the browser?

Maybe you can explain what your node(s) are intended to do in a bit more detail? Or point to some code? Or paste some fragments of code here?

My code is at:

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.

The context isn't really meant for holding configuration information (to start with the default context isn't persistent)

Config should be stored in the flow, with transient state in the context.

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.

What you are describing (in the MQTT case) is a config node.

https://nodered.org/docs/creating-nodes/config-nodes

Plugins are very different (and currently lacking good documentation). As tve mentioned I suspect you should be creating Nodes, not a Plugin.

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.

Lemme make sure I understand:

  • 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 will need some stiff drink next to you...
  • don't ask me how I know... :joy:

Or you could just ask. Unless I'm missing something then $("#id-of-select").val() would do just that.

1 Like

Correct. I don’t use ajax, but you get it.

“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.

1 Like

Works great. Thanks again. I should have it polished and in version 1 by Friday.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.