Package: senlib
Pure Python-based I2C sensor library for some I2C sensors. Work in
progress. Nothing serious, just a hobby.Currently, the library supports the following sensors:am2315/am2321bh1750bmp280/bmp180/bmp85bme280hdc1008lm75mcp9808mpl115a2mpl311a2sht31si7021InstallationBefore you can install senlib, you should install firstpipenvusing
the package manager of your operating system.On Arch Linux run the following command to installpipenv:sudo pacman -S python-pipenv or pip install senlibNext, clone this repo and cd into thesenlibdirectory:git clone https://github.com/Awaiskhan4o4/senlib
cd senlibNext, create a Python 3 environment as shown below:pipenv --threeLastly, install the package:pipenv install -e .Testing/DevelopmentFor installation see section Installation.To run the tests use:pipenv run pytest testsor cd into the directory and run:pipenv shell && pytest testsCLIsennodesennode --help
Usage: sennode [OPTIONS] SENSOR

Options:
  --address TEXT              I2C address of the sensor.
  --node TEXT                 Node name.
  --http                      Start Web API.
  --http-host TEXT            HTTP host to use.
  --http-port INTEGER         HTTP port to use.
  -t, --mqtt-topic TEXT       MQTT topic to use.
  -L, --mqtt-broker-url TEXT  MQTT broker to publish data.
  -i, --interval FLOAT        Sampling interval.
  --mock, --fake, --simulate  Mock sensor.
  -d, --debug                 Debug mode.
  -V, --version               Show version.
  --help                      Show this message and exit.Example Usagesennode bme280 --address 'i2c://1/0x77' --mqtt-broker-url mqtts://user:password@mqtt.xyz.ch:8883Once started, the sensor data is exposed over an HTTP interface and a
WebSocket interface:http://0.0.0.0:8080ws://0.0.0.0:8080Besides that, the sensor data is perodically pushlished to the specified
MQTT broker url.senlibsenlib --help
Usage: senlib [OPTIONS] SENSOR

Options:
  --address TEXT              I2C address of the sensor.
  -p, --poll INTEGER          Polls the sensor.
  -i, --interval FLOAT        Sampling interval.
  --output FILENAME           Save output to a file.
  -f, --format TEXT           Output format to use.
  --mock, --fake, --simulate  Mock sensor.
  -d, --debug                 Debug mode.
  --pretty-print, --pp        Pretty printing.
  -V, --version               Show version.
  --help                      Show this message and exit.Example Usagesenlib bme280 --address 'i2c://1/0x77'Code ExamplesFor details and examples have a look in the examples or tests directory.Basic code example:#!/usr/bin/env python3fromsenlib.core.i2cimportSMBusfromsenlib.i2c.sensors.bmeximportBME280importtimeif__name__=='__main__':bus=SMBus(bus=1)sensor=BME280(bus=bus,addr=0x77)for_inrange(0,5):time.sleep(0.2)data=sensor.measure()forkey,valueindata.items():print("{}:{:0.4f}".format(key,value))sensor.close()The shorter example uses thewithsyntax to automatically close the
sensor object:#!/usr/bin/env python3fromsenlib.core.i2cimportSMBusfromsenlib.i2c.sensors.bmeximportBME280importtimeif__name__=='__main__':bus=SMBus(bus=1)withBME280(bus=bus,addr=0x77)assensor:for_inrange(0,5):time.sleep(0.2)data=sensor.measure()forkey,valueindata.items():print("{}:{:0.4f}".format(key,value))