Buffer if connection lost

Hi, im reading data in real time, so some times we lost the connection to internet (where we have the endpoint to influxDB) how i can implement a buffer to save the data if the connection with influxDB fails?


The following page from the uibuilder WIKI demonstrates a simple caching function that you may be able to adapt for your needs.

Obviously though, you will need to think about how much data is being cached. Also how to trigger a replay and clear of the cache once the db connection is back.

I would use a flow (or global) context variable containing an array of records to be sent to influxdb. The real time code collects the data and adds it to the end of the array, then a separate activity sends them to influx if the connection is there and removes them from the front of the array. Normally they will get pushed onto the array and immediately sent and popped. If the network is down then will get saved in the array till the network recovers. If you wish records to be kept in the event of node-red restart then use persistent context.

Surely if you buffer realtime data and send it to InfluxDB later the timestamps will be wrong? Just a thought.

When you pass data to influx you can pass the timestamp too, so provided it is timestamped before buffering then it will be ok.

1 Like

I always forget that you can insert timestamp data, I always use the automatic timestamping.

It was worth bringing up in case in case @evetse had not thought of that.

Thanks! i will try it and send a feedback asap.

There may be no need to build your own queue (buffer). The simple-queue node could do the job for you if you can generate trigger messages for it as long as the database is connected. The queue-gate node is similar, with the added feature that you can disable the queueing when you want.