Connected objects have applications in many sectors, and agriculture is one of the most benefiting from the benefits of the Internet of Things.
This project describes the application of IoT (Internet of Things) in agriculture. In this environment we take measurements of the humidity of the soil of a plant.
Monitoring of the parameter around this process (information provided by the soil sensor) is done using open source tools and resources such as ESP32 and ThingSpeak. We read the sensor data in real time on the internet through a web page and also on the graphs in ThingSpeak.
This work is done using an ESP32 microcontroller which will send all information via WIFI concerning the environment of our plant, to ThingSpeak.
Soil moisture sensor
To perform the assembly, you can connect:
for the soil sensor:
pin S to pin D34 of the ESP32 board
pin (+) to pin 3.3V of the ESP32 board
pin (-) to the GND pin of the ESP32 board
from simple import MQTTClient
from time import sleep
from machine import Pin,ADC
WiFi_SSID = "username"
WiFi_PASS = "password"
SERVER = "mqtt.thingspeak.com"
client = MQTTClient("umqtt_client", SERVER)
CHANNEL_ID = "*************"
WRITE_API_KEY = "*************"
pin_sol = ADC(Pin(34))
wlan = network.WLAN(network.STA_IF)
if not wlan.isconnected():
print('connecting to network...')
while not wlan.isconnected():
print('network config:', wlan.ifconfig())
topic = "channels/" + CHANNEL_ID + "/publish/" + WRITE_API_KEY
humidite_value = pin_sol.read()
payload = "field1="+str(humidite_value)
client.publish(topic, payload) #send temperature and humidity values to thingspeak.com
Remarque: il faut importer la bibliothèque suivante: simple.py