Hello, I want to use BMP280 sensor with cayenne connected to RPI 3. The sensor has default address 0x76. I as read in Cayenne Docs, the supported sensor by the platform - BMP180 has default address 0x77.
Is there anyway to change the discover address of the sensor so I can display the data in dashboard using this sensor?
Any other methods with custom widgets?
You can use the MQTT API. I have an example here that demonstrates using the DHT11/22 sensor. You can use it as a guide and replace the bits that read DHT sensors with your code that reads the BMP. If you need any help let me know.
Thank you very much! I will give it a try first by myself and then I will ask you. Thanks for the fast and reliable response!
You can also implement MQTT on the Pi with the Cayenne C libraries, but @adam’s solution in Python is a lot less steps.
Let me know if you need a C solution.
So in order to get working the BMP280 Sensor, I have to install its library instead of the library for DHT as in the example? Right?
After that, can you help me with the read command, because in the example the following line is used:
humidity11, temp11 = Adafruit_DHT.read_retry(11, 17) #11 is the sensor type, 17 is the GPIO pin number
but I used to connect BMP280 as shown here: https://mydevices.com/cayenne/docs/#supported-hardware-sensors-temperature-bmp180-rpi-tutorial
…so I don’t have a number of GPIO pin.
Thanks a lot!
Yes, install this library https://github.com/adafruit/Adafruit_Python_BMP (if you haven’t already) and then try the code below (I did not test this- just guessing that it will work). For testing don’t use the cron I have in the project just run the file with “python (filename).py”
import paho.mqtt.client as mqtt
import Adafruit_BMP.BMP085 as BMP085
time.sleep(30) #Sleep to allow wireless to connect before starting MQTT
mqttc = mqtt.Client(client_id="")
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)
sensor = BMP085.BMP085()
topic_temp = "v1/username/things/clientid/data/1"
topic_pressure = "v1/username/things/clientid/data/2"
topic_altitude = "v1/username/things/clientid/data/3"
topic_sealevel_pressure = "v1/username/things/clientid/data/4"
temp = sensor.read_temperature()
pressure = sensor.read_pressure()
altitude = sensor.read_altitude()
sealevel_pressure = sensor.read_sealevel_pressure()
mqttc.publish(topic_temp, payload=temp, retain=True)
mqttc.publish(topic_pressure, payload=pressure, retain=True)
mqttc.publish(topic_altitude, payload=altitude, retain=True)
mqttc.publish(topic_sealevel_pressure, payload=sealevel_pressure, retain=True)
except (EOFError, SystemExit, KeyboardInterrupt):
Thank you very much for the whole code!!!
I will test it and return an answer!
I appreciate it.
For testing you can also take out that “time.sleep(30) #Sleep to allow wireless to connect before starting MQTT” line so you don’t have to wait 30 seconds every time you run the script. That’s only in there because I had problems with the script running before there was a connection available on boot.
Later when I go back from work, I will make tests.
I use to try your code and when I try to run it with python “filename”, it gives me the following error:
Traceback (most recent call last):
File "bmp280.py", line 12, in <module>
sensor = BMP085.BMP085()
File "build/bdist.linux-armv7l/egg/Adafruit_BMP/BMP085.py", line 69, in __init__
File "build/bdist.linux-armv7l/egg/Adafruit_BMP/BMP085.py", line 72, in _load_calibration
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 200, in readS16BE
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 177, in readS16
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 164, in readU16
File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 173, in read_word_data
IOError: [Errno 5] Input/output error
On my dashboard, a device with name 737f appeared. It is with empty dashboard. When I try to add widget, it asks for an address which I don’t know.
Can you help me a little bit more please?
Hmm I think I have one of these sensors but finding it will be the problem. I’ll try to test it tonight if I can find it. Until then maybe someone that has one accessible can try? As far as the dashboard your widgets will show up automatically when the script successfully runs.
Have you tried it with:
sudo python "filename"
Sometimes there are permission issues accessing I/O.
Yes, of course. I read already about the GPIO permissions.
I suddenly burn the sensor, so I am waiting for the new one to come.
♫ Suddenly, the wheels are in motion… ♫
Sorry… moment of silence for the dead.