BME280 and SI7021 no longer display temp data MQTT


#1

Using a Raspberry Pi 3 Model B (Raspbian 9)
I am using MQTT to send Temperature, Humidity, and Pressure (BME280) to Cayenne. This all worked great until recently and now neither my BME280 sensor or my SI7021 will display the temperature. I have tried this on 2 different Raspberry Pi’s using the above mentioned sensors. I have not changed anything in my code I am using the typical paho.mqtt.client, but now all of the sudden the Temperature does not display. I did not think the updates would affect MQTT and Raspberry Pi.

Thoughts?


#2

Are you still having this problem? Can you share the code you are using?


#3

I am still having this issue…thank you for responding…My code has not changed and it is mostly code that I found and modified. Again I have this same issue on 2 different Raspberry Pi 3’s and the temperature does not display when using the si7021 or BME280 sensors. Humidity and Pressure display just fine. Thanks.si7021_mqtt.txt (1.5 KB)


#4

Your code looks good, looks familiar :wink:

Try changing your if statements to have a print so you know for sure you are actually getting a value, then run the script in a terminal with python (filename).py to get the output. You can comment out the sleep at the top so you don’t have to wait 30 seconds.

		if fahrTemp is not None:
		    print("temp: " + str(fahrTemp))
			fahrTemp = "temp,f=" + str(fahrTemp)
			mqttc.publish(topic_si7021_temp, payload=fahrTemp, retain=True)
		if humidity is not None:
		    print("hum: " + str(humidity))
			humidity = "rel_hum,p=" + str(humidity)
			mqttc.publish(topic_si7021_humidity, payload=humidity, retain=True)

#5

I have another program…again…one I slightly modified from someone else’s work. But it prints the temperature just fine. Also, I should add that through the dashboard using MQTT…it will display the temperature for like a second and then it goes away and just leaves a " - " where the temperature was. I think this is a Cayenne / MQTT issue. I can display DS18B20 1-wire temperature on the dashboard just fine, no issues at all. This issue started several weeks ago and I had run this same MQTT for months prior with no issue. I do appreciate your assist on this and thanks/sorry if it is your code that I have been borrowing (I’m still learning) :upside_down_face: I have 2 RPi 3’s that I am having this issue on and 2 different sensors (si7021 and BME280) and I am using 2 different Cayenne accounts (1 personal and 1 work) and in all cases the temperature does not display on the dashboard but prints the data fine outside of Cayenne and MQTT. I hope this makes sense. Attached is the loop code that I use that prints the temp just fine. si7021_loop.txt (2.0 KB)


#6

No need to apologize, that’s why I post it here :slight_smile: Can you try this script and paste back the output?

import paho.mqtt.client as mqtt
import smbus
import time
import os
import sys

time.sleep(30) #Sleep to allow wireless to connect before starting MQTT

username = "1234567890"
password = "abcdefgghi"
clientid = "12345-abcd"

mqttc = mqtt.Client(client_id=clientid)
mqttc.username_pw_set(username, password=password)
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)
mqttc.loop_start()

topic_si7021_temp = "v1/" + username + "/things/" + clientid + "/data/3"
topic_si7021_humidity = "v1/" + username + "/things/" + clientid + "/data/4"

while True:
    try:  
# Get I2C bus
        bus = smbus.SMBus(1)
        bus.write_byte(0x40, 0xF5)
        time.sleep(0.3)

# SI7021 address, 0x40  Read 2 bytes, Humidity
        data0 = bus.read_byte(0x40)
        data1 = bus.read_byte(0x40)

# Convert the data
        humidity = ((data0 * 256 + data1) * 125 / 65536.0) - 6
 
        time.sleep(0.3)
        bus.write_byte(0x40, 0xF3)
        time.sleep(0.3)
 
# SI7021 address, 0x40 Read data 2 bytes, Temperature
        data0 = bus.read_byte(0x40)
        data1 = bus.read_byte(0x40)
 
# Convert the data and output it
        celsTemp = ((data0 * 256 + data1) * 175.72 / 65536.0) - 46.85
        fahrTemp = celsTemp * 1.8 + 32
    
        if fahrTemp is not None:
            print("temp: " + str(fahrTemp))
            fahrTemp = "temp,f=" + str(fahrTemp)
            mqttc.publish(topic_si7021_temp, payload=fahrTemp, retain=True)
        else:
            print("temp is None")
        if humidity is not None:
            print("humidity: " + str(humidity))
            humidity = "rel_hum,p=" + str(humidity)
            mqttc.publish(topic_si7021_humidity, payload=humidity, retain=True)
        else:
            print("humidity is None")
        time.sleep(5)
    except (EOFError, SystemExit, KeyboardInterrupt):
        mqttc.disconnect()
        sys.exit()

#7

this is the si7021 sensor and does print the temp and humidity values just fine. It just doesn’t seem to want to post the temp on the Cayenne dashboard for some reason. Again, same issue with the BME280 sensor…everything displays fine on the Cayenne dashboard but the temp. Thanks. I hope this give you some insight as to what is going on…

temp: 67.9846817627
humidity: 35.6660308838
temp: 67.9846817627
humidity: 35.6660308838
temp: 67.9846817627
humidity: 35.6660308838


#8

So it appears something has changed. I have done nothing to my Raspberry Pi 3’s nor have I changed any of the code, but now out of the blue the temperature is displaying again on all of my sensors and my Pi’s. I use a BME280 sensor and a si7021 sensor on 2 different Pi’s and now everything is working again. I assume something was changed on the Cayenne side that has fixed this?


#9

Hi @tim_bauer,

It seems that maybe one of our recent updates may have fixed your problem.
Please keep an eye on this & let us know if this issue comes back.

Thanks.
-Jesse


#10

@tim_bauer We recently released some new updates, so yes. Glad to see it’s working again!

~B


#11

Thank you!