I want to inject a timestamp in my existing flow after every 10 seconds

i want to actually refresh my data in the template node after every 60 seconds but it shows an error in debug node as (no object response)

my flow : [http request] ------>[function node](contains code to generate timestamp)---->[template node](displays the time)------->[http response].

i tried to attached a inject node with function node that injects time after every 60 seconds but it didn't update data on the ui.

You will need to save the function to context and then retrieve in the template, or use a join node.
e.g.
context

[{"id":"325b07c7d898e0a5","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":4660,"wires":[["0226f694786627ef"]]},{"id":"0226f694786627ef","type":"function","z":"da8a6ef0b3c9a5c8","name":"function 20","func":"flow.set(\"payload\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":4660,"wires":[[]]},{"id":"c406ab59e9c45d34","type":"http in","z":"da8a6ef0b3c9a5c8","name":"","url":"/data","method":"get","upload":false,"swaggerDoc":"","x":220,"y":4600,"wires":[["d4f001a86919d8a6"]]},{"id":"d4f001a86919d8a6","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":" {{flow.payload}} ","output":"str","x":360,"y":4600,"wires":[["5e298c0e94cfdc39"]]},{"id":"5e298c0e94cfdc39","type":"http response","z":"da8a6ef0b3c9a5c8","name":"","statusCode":"","headers":{},"x":510,"y":4600,"wires":[]}]

Join

[{"id":"c406ab59e9c45d34","type":"http in","z":"da8a6ef0b3c9a5c8","name":"","url":"/data","method":"get","upload":false,"swaggerDoc":"","x":140,"y":4560,"wires":[["33ed9360a87bd6a3"]]},{"id":"33ed9360a87bd6a3","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"call","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":4560,"wires":[["6116806407d0a9c8"]]},{"id":"6116806407d0a9c8","type":"join","z":"da8a6ef0b3c9a5c8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":330,"y":4600,"wires":[["79dcf17e2e2a74f9"]]},{"id":"0226f694786627ef","type":"function","z":"da8a6ef0b3c9a5c8","name":"function 20","func":"msg.payload = new Date(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":4660,"wires":[["6116806407d0a9c8"]]},{"id":"79dcf17e2e2a74f9","type":"switch","z":"da8a6ef0b3c9a5c8","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"call","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":4600,"wires":[["d4f001a86919d8a6"]]},{"id":"325b07c7d898e0a5","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"inject","payload":"","payloadType":"date","x":150,"y":4660,"wires":[["0226f694786627ef"]]},{"id":"d4f001a86919d8a6","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":" {{payload.inject}} ","output":"str","x":600,"y":4600,"wires":[["5e298c0e94cfdc39"]]},{"id":"5e298c0e94cfdc39","type":"http response","z":"da8a6ef0b3c9a5c8","name":"","statusCode":"","headers":{},"x":750,"y":4600,"wires":[]}]

You cannot simply inject into HTTP endpoint - it MUST be called by the client.

In other words, if you want the client to get new data every 60s, it must ask for new data every 60s

And if you want a fresh timestamp in the data returned to the template --> for the client, then you could add a change node before the template to set a msg property (e.g. msg.timestamp) OR use Date.now() in the function node.

the data is not getting refreshed automatically on its own

We don't know what flow you are using, but do you have your inject node set to Repeat at a set interval?

How to post your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

See this post for more details - How to share code or flow json

The http in is a endpoint , it does not get refreshed, it receives get requests. If you make a http request to the endpoint every 10 seconds the data should be updated. So in my examples if you refresh the browser every 10 seconds the return date will be updated.
Is the inject node injecting every 10 seconds?

Or maybe a simple websocket example is what you need - Simple Web page with live data updates via websocket (flow) - Node-RED

(but if you do then I'm sure very rapidly you will want more control and the ui-builder project may help you there)

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