ThomDietrich/miflora-mqtt-daemon

Provide daemon configuration and sensors via MQTT subscription topic

Opened this issue · 15 comments

We'll be using these sensors to monitor outdoor plants, and because of range issues for BLE, will have multiple monitoring daemons. It'd be lovely to be able to inform the daemons at wakeup what sensors they "own" without having to modify the config.ini by hand every time a new sensor gets added or a potted plant gets moved from one coverage area to another.

I get your use case but didn't understand which alternative you are seeking.

Retrieving data from a database sounds like out of scope of the daemon. As a tradeoff, wouldn't it be acceptable to modify the config file via a helper script before starting the daemon?

I see.

Well okay, I feel your idea is a bit too specific. I like the idea to centralize the configuration point for multiple sensors. How about the following:

We are already using MQTT for data publication. We could support an MQTT configuration topic per client, so that every client would subscript to a list of sensors he is supposed to query.

A few more details would need to be discussed but I like the idea in general.

...sadly I am currently not able to work on this. Would you like to push the idea forward?

That shouldn't be an issue. Tell me when you'd expect a config update to take effect. Right now the config is only read on read during daemon startup. Would you expect it to be evaluated every time a new sensor readings update is scheduled?
That would totally be possible, we just have to figure out the details.

Your idea of a directing mothership which will directly interact with clients will massively over-complicate things. I believe from the use cases I was able to derive from the basic idea of a distributed system we are looking for a daemon which can be easily installed on a, e.g. RPi, and then be mostly configured from remote.

I would definitely go with MQTT then. It is already used and the concept of retained messages is just great for this.

Conceptually it would look like this:

A daemon will go through the following cycle:

  • Read the latest data published to its dedicated configuration topic (e.g. miflora/config/daemon_unique_id)
  • Store the configuration in temporal memory
  • Poll all sensors according to configuration
  • Optionally: Scan for available sensors, publish to a dedicated topic.

With this behavior in place your central control entity can publish configs (including sensors, polling times, ...) for all clients. On top of that it will learn which client sees which sensor and can (help) rearrange authorities.

@rlmalisz How is your fork working for you? rlmalisz@b689503

@bangom this ticket is a bit older but still very relevant. Are you also interested in this? #35 (comment)

I have no complaints about my fork. We have a half-dozen "readers" around the house and yard. Not too many sensors deployed this time of year, but in summer, a couple dozen. Readers collect their assigned sensor readings every three hours. Just before that interval, a cron (OSX, so actually launchctl) script queries a MySQL DB for assignments, and publishes them to MQTT. Readers' scripts run, get their assignments, and gather readings, and publish them. Another OSX scripts runs after those finish, and collects published readings and adds them to MySQL. It also posts warnings about any readings that are too low (or high) for sensors. Have a PHP script that uses Google Charts to display recent data queried from the DB. Image attached. But adding/deleting/moving a sensor is a simple update to a couple DB tables. This was what I wanted, so am quite happy.
Screen Shot 2020-03-29 at 9 52 46 AM

@bangom this ticket is a bit older but still very relevant. Are you also interested in this? #35 (comment)

Most definitely. Next miflora-mqtt-daemon development step should be implementing distributed miflora-mqtt-daemons configuration from single place (master node?). This is IMHO primary usecase for miflora-mqtt-daemon (multiple btle2wifi clusters of RPI0 connected to central hub like Home Assistant). Let me think this over and get back with my ideas :) But from the initial analysis of this issue I like the idea of using MQTT (sensor data and daemons configuration updates).

I already have an idea. Let me post a proposal this evening