Buffer if connection lost

#1

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?

Thanks!
Evetse

0 Likes

#2

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.

0 Likes

#3

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.

0 Likes

#4

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

0 Likes

#5

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

#6

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

0 Likes

#7

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

0 Likes

#8

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

0 Likes

#9

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.

0 Likes