alanb128 / big-sensor

Instantly read data from 15+ popular Adafruit sensors without any configuration.
5 stars 2 forks source link

big-sensor

Instantly read data from 20+ popular Adafruit I2C environmental sensors without any configuration.

This is based off the lighter-weight balena Sensor block which has similar functionality but supports fewer sensors.

Use

Connect one or more of the supported sensors below to your device via I2C. Add this container to your project and it should auto-detect your sensor(s) and start displaying readings every 10 seconds on the console output. The sensor data is also available via http on port 7575 of the IP address of the device or via MQTT.

If there is another service on the device named mqtt the sensor readings will be published to that broker. Otherwise, you can specify an MQTT broker address with the environment variable MQTT_ADDRESS. If MQTT is active, the http server will be disabled. To enable the http server on port 7575 anyway, set ALWAYS_USE_HTTPSERVER to 1.

You can specify the MQTT topic to be published with MQTT_PUB_TOPIC otherwise the default topic is sensors. The MQTT_PUB_INTERVAL sets the number of seconds between packet publication. The default value is 8 seconds. This interval also controls how often the sensor data is printed to the standard output. To disable this printing, set VERBOSE to 0. (This also eliminates other repetitive non-error printing.)

To add the block to your docker-compose file, see this example:

version: '2.1'

services:
  big-sensor:
    image: bh.cr/al_s_apps/big-sensor-armv7hf
    restart: always
    labels:
      io.balena.features.supervisor-api: 1  # necessary to discover services
    privileged: true # necessary to read sensors

Currently supported sensors:

The follwong sensors can be on two different I2C addresses, so up to two at a time (if on different addresses) can be supported: BME680, BME280, BMP280, ENS160.

Options

The sensors are read by default from bus number 1 (/dev/i2c-1). To change the bus number, use the variable BUS_NUMBER.

How it works

A Python dictionary holds all of the information about each sensor, including a reference to the sensor class and a function for reading each sensor's measurement. A loop tries to load each sensor and if successful adds a reference to the sensor in a Python list. Finally, we loop through the found sensor list and pass each sensor to its measurement reading function and print the result.