tobiasschuerg / InfluxDB-Client-for-Arduino

Simple library for sending measurements to an InfluxDB with a single network request. Supports ESP8266 and ESP32.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is the library thread safe?

maxdd opened this issue · comments

commented

Hello,
i was wondering whether the library is thread safe?
In my case i have multiple classes representing different sensors each with its own scheduling time.
Currently each sensor "gets" the influxdbclient handle and pushes its Points to influxdb database.
Given each class is running asynchronously in RTOS tasks can i assume the library is thread-safe?
Shall i instead put a mutex everytime time the handle is retrieved till the class pushes a point?

e.g

_client->Take();
_client->writePoint(p);
_client->flushBuffer();
_client->Give();

Regards,

@maxdd, no, this library is not thread-safe. There is no synchronization inside. I don't think ESP32 can send data through the network layer on different cores. So, It seems the best pattern would be to keep writing in a single task and sending data (points) from sensors to the writing tasks using a queue.

commented

Hello, i also thought about that solution by using a queue of Points (or pointers to memory regions) and a condition variable.
Do you think it is a better design?
Would you mind to provide a basic example as a reference?

Regards,

Definitively, there should be a single place when the client sends data to the server.

I don't have any such code. You should be able to find several examples of using a queue with a custom type.