This application is used for measuring different values from a variety of sensors and send them to a server via MQTT.
All application is being developed in a Raspberry Pi 4b, using the Raspbery Pi operating system.
The .env is where important configurations that can be changed are.
Enable I2C: sudo raspi-config -> Interfacing Options -> I2C -> Enable.
sudo apt install i2c-tools python3-rpi.gpio
sudo pip install paho-mqtt smbus2 RPI.GPIO python-dotenv
In the /etc/mosquitto/conf.d/default.conf
set the values below
listener 1883 means that it is listening for any MQTT clients on TCP port 1883 on all interfaces (0.0.0.0:1883).
If you want to listen for a specific client set:
listener 1883 <your_client_ip>
allow_anonymous true means the broker will allow clients to connect without a username or password, and any MQTT client can publish or subscribe without restriction. (For the initial development, it's ok)
Then, restart the service
sudo systemctl restart mosquitto
Check if it is listening to the right IP and port:
sudo netstat -tulnp | grep 1883
python3 main.py
The application is publishing to the sensores/medicoes
topic to send the measured sensor data.
The application is subscribed to the topics sensors/status
and sensors/read_now.
With sensors/status
, you can obtain the application's uptime.
With sensors/read_now
, you can access the measured data immediately.