balenaSense sensor read error

Hi,

I’ve had a lot of success with the bmp680 but I cannot get the bmp280 to work yet.

Version - balenaOS 2.108.18
Device - Raspberry Pi 3+ 32-bit

sensor-block output:

sensor IIO context has 1 devices:
sensor iio:device0: bmp280
sensor 2 channels found:
sensor pressure: (input)
sensor 2 channel-specific attributes found:
sensor input, value: 97.622214843
sensor oversampling_ratio, value: 16
sensor temp: (input)
sensor 2 channel-specific attributes found:
sensor input, value: 14860
sensor oversampling_ratio, value: 2
sensor GET / HTTP/1.1
sensor Host: sensor:7575
sensor User-Agent: Go-http-client/1.1
sensor Accept-Encoding: gzip
sensor
sensor
sensor Transforming bmp280 value(s)…
sensor Exception in thread Thread-1:
sensor Traceback (most recent call last):
sensor File “/usr/local/lib/python3.9/threading.py”, line 954, in _bootstrap_inner
sensor self.run()
sensor File “/usr/local/lib/python3.9/threading.py”, line 892, in run
sensor self._target(*self._args, **self._kwargs)
sensor File “/usr/src/app/sensor.py”, line 74, in background_web
sensor response = ‘HTTP/1.0 200 OK\n\n’+ json.dumps(balenasense.sample())
sensor File “/usr/src/app/sensor.py”, line 53, in sample
sensor return self.sensor.get_readings(self.context)
sensor File “/usr/src/app/reading.py”, line 87, in get_readings
sensor x = reading.write_reading()
sensor File “/usr/src/app/reading.py”, line 35, in write_reading
sensor new_fields = device_transform(dev.name, device_fields)
sensor File “/usr/src/app/transformers.py”, line 38, in device_transform
sensor for field in fields:
sensor RuntimeError: dictionary keys changed during iteration

Any help greatly appreciated.

ps. here is the startup message from the sensor-block:

sensor OKWeb server listening on port 7575…
sensor Initializing sensors…
sensor ======== Searching i2c bus for devices… ========
sensor Found (busy) device at 0x76
sensor ======== Removing existing devices from the i2c bus… ========
sensor Deleting device found at 0x76.
sensor ======== Unloading any existing modules… ========
sensor Unloading module bmp280 as bmp280-i2c.
sensor modprobe: FATAL: Module bmp280 is in use.
sensor New active: [118]
sensor ======== Loading devices found… ========
sensor Loading device bmp280-i2c (chip ID 88) on address 0x76.
sensor Loaded 1 of 1 device(s) found
sensor initializing reading
sensor IIO context created: local
sensor Backend version: 0.16 (git tag: v0.16)
sensor Backend description string: Linux 664add9758ac 5.10.95-v7 #1 SMP Thu Feb 17 11:43:01 UTC 2022 armv7l
sensor IIO context has 1 attributes:
sensor local,kernel: 5.10.95-v7
sensor IIO context has 1 devices:
sensor iio:device0: bmp280
sensor 2 channels found:
sensor pressure: (input)
sensor 2 channel-specific attributes found:
sensor input, value: 97.618246093
sensor oversampling_ratio, value: 16
sensor temp: (input)
sensor 2 channel-specific attributes found:
sensor input, value: 14900
sensor oversampling_ratio, value: 2

Hello, I’ll see if I can reproduce the error to troubleshoot. Just to clarify, are you using a Pi 3A+ or 3B+?

OK, many thanks!
I’ve had the same error starting afresh with a 3A+ and a 3B+, the messages above are from a 3B+.

Hi,

I looked over the error output and saw:
sensor File “/usr/src/app/transformers.py”, line 38, in device_transform
sensor for field in fields:
sensor RuntimeError: dictionary keys changed during iteration

and guessed /usr/src/app/transformers.py might be the problem.

using info from:

I tried RAW_VALUES set to 1 and it works beautiful like with the bmp680, however the output of the temperature is 14860 instead of 14.9 degrees :slight_smile:

Is it possible to fix?

Yes, I’m seeing the same issues with transformers.py using the BMP-280. I’ll see if we can make a quick fix to allow RAW_VALUES to be set to 1 so the temperature is a usable value.

OK, thanks so much, actually the value is not too much of an issue as its simply a factor of 1000.

We are using the sensors to save energy at our small school in the Highlands, Scotland, many thanks for the amazing software.

You’re welcome, sounds like a great use case!
I actually meant “RAW_VALUES to be set to 0 for usable temperature” before. Anyway, I rebooted and now it’s working fine for me, so tough to troubleshoot further at the moment.
My plan is to replace the existing sensor block with one more like this: GitHub - alanb128/big-sensor: Instantly read data from 15+ popular Adafruit sensors without any configuration. (should still be backwards-compatible) in the near future so it may not matter…

Linked to another thread about intervals here:

I followed the end of the guide and used GitHub - balena-io-experimental/simple-sensor: Read sensor data and send via MQTT and that worked a lot better (it has the latest version of the Sensor block)