How to do multiple http get request for every 10 seconds without inject node

Hi there,

i am working on a project where i make a get request to a server which returns me the connection state of systems and machines as JSON. i use this return value to visualize the connection states in node red:
grafik

the next step is to query the status of each machine. for this i have an endpoint, which gives me this. in node-red i now want to make a query to this endpoint every 10 seconds to visualize the status, if the health is ok or not. the response will look like this:
grafik

for this i do NOT want to use an inject node, because i have to follow a certain rule regarding structure. this is to look like obove.

so i will modify the "mtconnect" and "opc ua" node like the http request node, only with the except that the nodes will make http request for every 10 seconds instead of only one time as the core node http request.

is there a way to implement a modified version of the HTTP REQUEST NODE that makes me a request every 10 seconds instead of just once?

thank you very much for the answers!!!

Hi. Welcome to the forum.

Unless I am missing something, I can see no reason to modify the core node when what you are asking is 100% possible using either an inject node or a Cron type node.

Can you elaborate more?

1 Like

Firstly, thanks for answering!!
So after visualization the configuration, we have a lot of machines and devices as nodes on Node-RED. So only this machines should be seen. It would be really messy if i would put a inject node for each of the machines, becuase they all have different endpoints to make a request.

Yo don't need to use a preprogrammed inject per request. You can use change nodes to set-up the payload from any source, even an array populated dynamically if necessary.

In general, i will make a request to the endpont, it will returns me a json string with all connection states of the machines. i will convert this json to a node red compatible json-string and will put this json to flows.json, where node-red reads the configuration of the flows. after rebooting the node red docker container, the page will refresh and we will see the connection state as shown above. now each of this "device" nodes should make a http request for a endpont, which will return ONLY the status of the device by id and not for the whole devices. and for this, i will turn the "device" to something like the http request node, only with the except that these will make a request to the specific endpont every 10 seconds.

Still not clear I'm afraid.

Can you write the process as a flow chart or stepwise?

Perhaps something like...

  1. Request a list of endpoints from http
  2. Loop through each endpoint and generate a Payload,
  3. Send this generated payload to the endpoint
  4. Store the result in an object for later display on a dashboard

Etc

1 Like

i will describe you everything in detail, but needs a second for this!
thanks a lot !!!

imagine, that this flow will be created automatically, not important how its made:


the nodes you can see here (i will them call device-nodes) are created by me. but for now they are only dummies. that means, that these have no funcionality:
grafik

the idea is, to modify these device nodes, that they will make a http request to this endpoint:

. the id will represent the id of the node. so that each node will make a http request every 10 seconds. the response will look like this:grafik

after receiving the JSON Object, the status object witihn the respone (see obove) should be processed. if the "health" and "state" key are "ok" and "running", then the node status should be green. if not it should be red like described in the docs:
grafik

for this i only want to modify the device nodes. i had the idea, to copy the source code of the "http request" node (the js and html file) and push it into the js and html file of the device node. in addition i will the feature, that the device nodes make a http request every 10 seconds automatically without using a switch node, inject node,....

now its hopely clear.

are you still there ?
:sweat_smile:

Sounds like you just want the first "node" in the flow to look like a single block, but have it do multiple things repeatedly... for that, you can use a subflow.

In the parent flow, it looks like a single node, but when you edit the subflow, it can have many nodes inside it (e.g. inject -> http request -> json).

I would start by making a single flow that works as you expect, then select all the upstream nodes and use the Menu > Subflows > Selection to Subflow option to put them all into one displayed node.

1 Like

Another nice feature of a subflow is that it can have environment vars that are used by the nodes running inside. For instance, the http request node in the subflow could use env string syntax to substitute the target url like this: ${DEVICE_URL}

1 Like

Thanks a lot, its really good idea! Firstly i also had this idea but the feature with the env var are new for me. I will try it like you described. Thanks a lot again!!

@shrickus is there a way to call the node_id of the instance of the subflow within the subflow itself? i would set the http request URL like this: URL_ENV_VAR/node_id

The http request node (and many others) can be configured with a blank url -- then, if the incoming msg contains a url field, it will be used in the http request. A good example of how to do it is in this thread

So I would suggest that your subflow includes a change node upstream of the http request node, which builds the target string and a sets it on the msg.url field. The only thing I'm not sure about is how to get the current subflow's id inside a change node... but if that's not available, just use another env var, maybe?

1 Like

hey again, i did it!!
thanks again for your help!! <3

1 Like

Looks good! I'm glad you got it all working.

For the benefit of the rest of us, could you show us a bit of how you set up the subflows? Specifically, how did you end up building the url from the env and id vars...

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