Using an IoT approach for the fHelper can helps to evaluate the measurements done more easily, using the MQTT protocol.
We need a server capable to receive the measurements from the fHelper sensor (client) and eventually work on the received data.
And of course we need a client/sensor capable to send the humidity level to the server.
See the article about the MQTT/Node-Red server about the preparation of an IoT server on a Raspberry Pi.
This article is about how to quick set up an IoT client for fHelper in order to run some feasibility tests on the sensor and its response.
Basically the idea is to evaluate if the system is reliable enough for the purpose.
Hardware
The basic fHelper version with MQTT is based on a Huzzah32 and a soil humidity sensor.
Optional maybe a display but more probably just a LED to be controlled by the Node-Red server.
The starting point however is just a soil humidity sensor.
The starting point however is just a soil humidity sensor.
The Huzzah32 on a breadboard in order to run tests |
The sensor in the soil (behind the water holder) |
Preparation
On the Arduino IDE need to install these libraries :
- library EspMQTTClient
- the PubSubClient library
The soil humidity sensor is simply read using an analog I/O so no special libraries are needed.
MQTT Topics
The IoT client has two topics :
- esp32/humidity
- esp32/output
esp32/humidity
This topic is sending the humidity readings from the soil sensor.
Every 25 seconds, 10 readings (with a delay between each reading of 50 ms) are performed and an average is calculated.
This average is sento to the server.
esp32/output
The third one is an input for the IoT client, the Huzzah32.
It controls a LED.
It controls a LED.
It is used for tests right now
The code
The code is quite easy and straightforward. I'll publish a public version when finish.
It initialize the WiFi and the MQTT client, then it try to connect to WiFi (see note below), then after connecting to the WiFi it connect with the MQTT server.
After that every 25 seconds (more or less) it read 10 times the soil sensor and calculate the average and send the average over the esp32/humidity topic.
If a message is received on the esp32/output topic, check the content.
If is "on" or "off" control accordingly the LED.
That's it.
WiFi note
A note about the WiFi.Apparently the Arduino library for WiFi can have problems with some routers.
If the router can automatically use channels in different bands, like mesh routers, is possible that sometime the WiFi connection doesn't happens.
I didn't investigate in deep the problem but I think simply the WiFi management of the Huzzah32 (esp32) can't cope with multi-frequency connections.
I noticed no problem, i.e. 100% connection achievement, with routers with 2.4 Ghz frequency.
With routers with multiple frequencies capability, typical for mesh routers, sometime the connection fails.
In this case the only thing to do is to reset the Huzzah32 and let the negotiation restart until the router propose something compatible with the Arduino libs.
Update - April 2019
Initially I did test the circuit on a breadboard (I know I'm lazy :) ).
Now I did assemble a point to point circuit and already I did see huge improvements in the signal coming out from the sensor.
Still fluctuating but in a less range. The better connection and surely the short wiring help a lot to have a clean signal out the ADC.
Note how neat and clean are the readings now.
Still fluctuating but in a much narrow range now.
The drop of values is when I did add water to the plant.
This why I did start to prepare a PCB for the final version.
I also did add, on the schematic for now, a humidity/temperature sensor in order to have some environment data collected and did port out the I2C bus in case to add other stuff eventually.
After the testing time on the new board, and relative adjustments from the readings, I'll add support for that sensor too.
Here the schematic of the circuit :
And this is a possible PCB (it can be modified a this stage, it depends about what humidity/temperature sensor I will decide to adopt).
No comments:
Post a Comment