oxullo / sensorflux

Service relay for sensors to influxdb
0 stars 2 forks source link

Create the Arduino mock #1

Open jomaves opened 3 years ago

jomaves commented 3 years ago
19201080 commented 3 years ago

Hey @jomaves, i'm working on the interface between the arduino mock and influxdb, and i think it can make sense to have a look at how the data could be formatted to be sent there.

In the branch feature/influxdb_connector (see here), i have an interface that can send data to influxdb. As a parameter to the function writing to influxdb, i use data formatted that way: {'time': '20201125T19:30:20.123456', 'temp': 123, 'atmo': 456, 'humi': 789} time is an optional key, i also provide it in the interface if it's missing. And only one of the temp, atmo, or humi needs to be provided (you can also include two, or all three at once). So these two dicts are also valid parameters: {time': '20201125T19:30:20.123456', 'humi': 789} {'temp': 123, 'atmo': 456}

i do it in this way because maybe not all values are available or accessed at the same time (multiple sensors?). I see in your code for generating values that you have data formatted as [[time], [temp], [atmo], [humi]]. What do you think would be the way to go? Maybe the dictionary could be more robust

jomaves commented 3 years ago

Hey Etienne, perfect, I will create an Dict as you suggested! With time, temp, atmo and humi. One more question, how would we do the actual hand over? Would you request for the dict or would I send it to you in a regular interval? We probably discussed this on Thursday I just can't remember.

19201080 commented 3 years ago

Hey, i tell you if you review my pr first 😛 So i think there's many ways to do it. The way i would approach that is:

A way to solve this periodic thing could be to use asyncio, and do: poll data → send it → asyncio.sleep → repeat (while loop).

oxullo commented 3 years ago

I'd go for a class approach, starting from the mock random data generator and then create a common ancestor shared between mock and real arduino connector. The class should have a start/stop method that starts a tasks that polls for data, as @19201080 describes. The real deal is how to send the data, for this I'll provide no hint :)

jomaves commented 3 years ago

Thank you Étienne, thank you Marco. I will give my best!