Application that allows to follow the evolution of a plant with many sensors on the prototype.
Prerequisites
Installation
Usage
Result
Resources
Open arduino, then install the following libraries :
- DHT sensor library (to run the DHT22 Time/Humidity sensor)
- PubSubClient
- Adafruit Unified Sensor
- WiFiNINA
- WiFi101

Now open a console (outside arduino) and install the MQTT protocol (Mosquitto) :
sudo apt install mosquitto mosquitto-clients
- Mosquito is the MQTT broker
- Mosquito-clients installs the Mosquito_sub client to subscribe to a topic and Mosquito_pub to publish a topic
The MQTT broker starts at startup, you do not have to do anything to receive and issue Topics from another terminal.
Warning
You must allow anonymous connections.
Edit the mosquitto.conf file : sudo nano /etc/mosquitto/mosquitto.conf
Then add these two lines :
à llow_anonymous true
listener 1883
Save the file, then restart the Mosquitto service: sudo service mosquitto restart : sudo service mosquitto restart
For Python2: sudo pip install paho-mqtt
or sudo apt install python3-paho-mqtt
For Python3: sudo pip3 install paho-mqtt
or sudo apt install python3-paho-mqtt
The library documentation can be found at https://pypi.org/project/paho-mqtt/.
The Client class contains the methods to connect/disconnect to the broker, to publish a message on a topic, to subscribe/unsubscribe from a topic :
- connect() and disconnect()
- publish()
- subscribe() and unsubscribe ()
To use the Client class you must include the library at the beginning of your program : import paho.mqtt.client as mqtt

Note
- a temperature sensor
- a humidity sensor
- a soil humidity sensor
- a brightness sensor
Test the Mosquitto broker locally with the client on the Raspberry.
Open a terminal and type the command : mosquitto_sub -h localhost -v -t "test/message
so that the mosquitto client subscribes to the Topic /test/message.
The terminal is waiting to receive a message on this topic
Open another terminal and type the command : mosquitto_pub -h localhost -t "test/message" -m "Coucou"
to publish a message on this topic.
You should see the message "Coucou" displayed on the terminal subscribing to the Topic


https://mosquitto.org/man/mosquitto_sub-1.html
https://pypi.org/project/paho-mqtt/
https://pypi.org/project/paho-mqtt/#constructor-reinitialise
https://docs.arduino.cc/libraries/pubsubclient/
https://wiki.seeedstudio.com/Grove-Moisture_Sensor/
https://wiki.seeedstudio.com/Grove-Temperature_and_Humidity_Sensor_Pro/