Note this is from a while back so please check for errors as you go!
Update packages:
sudo apt-get update
Check python version:
python --version
- need 2.7
Install tools:
sudo apt-get install i2c-tools python-pip python-smbus
- SHOULD BE smbus2 ??
Check bmesensor address (needed later):
i2cdetect -y 1
Install paho mqtt client:
pip install paho-mqtt
Install BME280 library:
pip install RPi.bme280
Install smbus2 library:
sudo pip install smbus2
Create the python script:
sudo nano bme280_publish_mqtt.py
Copy and paste the script, replacing address
with your bme snesor address, and replacing broker_address
with yours. Exit and save.
Make executable:
chmod +x filename.py
You can now run the script and check it publishes to your mqtt broker:
./filename/py
Steup crontab to run every 1 minute
crontab -e
then add this:
# publish bme280 sensor data to mqtt every 1 minute
*/1 * * * * ~/877mqtt/bme280_publish_mqtt.py >/dev/null 2>&1
https://www.circuitbasics.com/how-to-write-and-run-a-python-program-on-the-raspberry-pi/
http://www.steves-internet-guide.com/into-mqtt-python-client/