Data["temperature"]) KeyError: 'temperature'

Iā€™ve got 2 ruuvi sensors working nicely with android phone and in one RPi Zero sending data to a DB. Iā€™m trying to install newer ruuvi samples to another RPi (3) but the samples hang and with Ctrl-C I get the above message. The same sample on Win10 laptop does not hang but always returns temp value 24.0, humidity and pressure seem to be fixed too.

On the RPi3 sudo hcitool lescan finds both sensors ok.

Any suggegstions?

It stops at ā€œStartingā€, the error message after ctrl+c is:
line_tem = str.format(ā€œTemperature: {0} Cā€, data[ā€œtemperatureā€])
KeyError: ā€˜temperatureā€™

This is the code on RPI 'm trying, itā€™s from your examples:

import os
import time
from datetime import datetime

from ruuvitag_sensor.ruuvitag import RuuviTag

mac = ā€˜E1:12:95:61:A8:3Dā€™
#mac = ā€œCA:66:70:94:C7:6Aā€

print(ā€œStartingā€)

sensor = RuuviTag(mac)

while True:
data = sensor.update()

line_sen = str.format("Sensor - {0}", mac)
line_tem = str.format("Temperature: {0} C", data["temperature"])
line_hum = str.format("Humidity:    {0}", data["humidity"])
line_pre = str.format("Pressure:    {0}", data["pressure"])

# Clear screen and print sensor data
os.system("clear")
print("Press Ctrl+C to quit.\n\r\n\r")
print(str(datetime.now()))
print(line_sen)
print(line_tem)
#print(line_hum)
#print(line_pre)
print("\n\r\n\r.......")
#break

# Wait for 2 seconds and start over again
try:
    time.sleep(2)
except KeyboardInterrupt:
    # When Ctrl+C is pressed execution of the while loop is stopped
    print("Exit")
    break

PPS. The above code runs on the Zero which has been running a few years now with an update to ruuvitag-sensor 2.0.0 last year. Changing to that older version 2.0.0 from the latest on RPi3 does not help, the code wonā€™t run.

This sounds like something @otso could possibly help with.

Anyone anything?

Complete reinstall helped.

1 Like

Hello @ripa , glad to hear that reinstall fixed this issue.