At the beginning of 2024 the opensprinkler firmware cannot subscribe to MQTT topics. However, I have DIY soil sensors which report the soil moisture via MQTT. I do not speak C++, so I cannot provide code to the opensprinkler firmware project.
I do not have an OpenSprinkler installation yet. I first wanted to see if it works as intended. So I installed a fresh 64-bit lite system (Debian bookworm) on a Raspi B+ (yes, very old board!) I had lying around and rebuilt part of the OSPi hardware on a breadboard.
First I had the idea to use an additional ESP8266 which acts as MQTT subscriber and provides signals to the two input pins of OSPi.
But then I noticed that many of the GPIOs on the raspi were unused. What if I ran some python program subscribing to MQTT and controlling two of these GPIOs and connect them to the sensor inputs of OSPi?
Since I now can provide moisture sensor values via MQTT to OSPi, it's time to order a board and the other necessary hardware.
As I understand, there are plans to integrate MQTT subscriptions into the OpenSprinkler firmware. I hope that this will happen in the not so far future. Until then I will use my workaround/hack.
There was no big surprise. I wrote another short test program (mqtt-test.py) to subscribe to one of my moisture sensors. They simply provide an unsigned integer value. I merely have to get this value and define a threshold below which the soil is sufficiently wet or too dry if above and then set the GPIO accordingly.
The sensor itself is presently not installed (still winter break for my irrigation system). So I provided typical values using MQTT-Explorer. It worked as expected.
Again a small program (sensor-test.py) and corresponding programming of OpenSprinkler shows: it works! (From now on, as I directly connected the GPIOs, I did not use any pull-ups anymore.)
As I use Debian bookworm with kernel 6.1 I can control the GPIOs without using WiringPi (which as I understand is used by OSPi).
I wrote a short python script to blink LEDs on GPIO 16 and 20. These GPIOs are not used by OSPi by default. As I understand the OSPi documentation, further GPIOs might be used by defining them in the configuration. But for my irrigation project I do not have any such intentions.
It turns out that I can run the blinking program (gpio-test.py) while running OSPi without any interference between both of them.
The current version of the OSPi hardware can be found at https://github.com/OpenSprinkler/OpenSprinkler-Hardware/tree/master/OSPi/1.52. I don't need the analog inputs. So my simulation circuit is just a 74HC595 connected to the raspi as in the schematic (however, I powered it from the 3V3 rail) and LEDs at some of the output channels instead of the triacs.
Running the "Run Once Program" shows that everything works fine.
For the sensor inputs I provided 10k pull-up resistors to be on the safe side.
I assigned them to soil moisture sensors and when I connected an input to ground it was correctly recognized as wet soil which does not need irrigation. (The irrigation program was not executed.)
It does, but only to publish messages, so far.