Skip to content

Read the BME680 sensor with the BSEC library on Linux (e.g. Raspberry Pi)

License

Notifications You must be signed in to change notification settings

divers33/bsec_bme680_linux

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bsec_bme680_linux

Read the BME680 sensor with the BSEC library on Linux (e.g. Raspberry Pi)

Intro

Working example of fully using the BME680 sensor on Linux (e.g. Raspberry Pi) with the precompiled BSEC library, which allows to read calibrated environment values including an actual Indoor Air Quality (IAQ) score.

It makes use of Bosch's provided driver and can be configured in terms of it. Readings will be directly output to stdout in a loop.

Includes edits from BME680 using the official Bosch Sensortec BSEC Library

Prerequisites

Download the BSEC software package from Bosch wget https://www.bosch-sensortec.com/media/boschsensortec/downloads/bsec/bsec_1-4-7-4_generic_release.zip and put it into ./src, then unpack unzip bsec_1-4-7-4_generic_release.zip.

Configure and Compile

Optionally make changes to make.config.

Depending on how your sensor is embedded it might be surrounded by other components giving off heat. Use an offset in °C in bsec_bme680.c to compensate. Current value for my setup is 0.8 °C:

#define temp_offset (0.8f)

To compile: ./make.sh

Usage

Output will be similar to this:

$ ./bsec_bme680
{"IAQ_Accuracy": 0,"IAQ":25.00,"Temperature": 21.71,"Humidity": 39.26,"Pressure": 1009.72,"Gas": 96989,"bVOCe ppm": 0.5000,"Status": 0}
{"IAQ_Accuracy": 0,"IAQ":25.00,"Temperature": 21.71,"Humidity": 39.21,"Pressure": 1009.66,"Gas": 98240,"bVOCe ppm": 0.5000,"Status": 0}
{"IAQ_Accuracy": 0,"IAQ":25.00,"Temperature": 21.71,"Humidity": 39.23,"Pressure": 1009.68,"Gas": 98240,"bVOCe ppm": 0.5000,"Status": 0}
  • IAQ (n) - Accuracy of the IAQ score from 0 (low) to 3 (high).
  • S: n - Return value of the BSEC library

It can easily be modified in the output_ready function.

The BSEC library is supposed to create an internal state of calibration with increasing accuracy over time. Each 10.000 samples it will save the internal calibration state to ./bsec_iaq.state (or wherever you specify the config directory to be) so it can pick up where it was after interruption.

Sending JSON to MQTT with Mostquitto

The output of the sensor can easily be sent to MQTT using Mosquitto First, install Mosquitto Client sudo apt-get install mosquitto-clients

Launch the program and send the standard output to your Mosquitto broker ./bsec_bme680 | mosquitto_pub -h 192.168.1.XXX -u "your broker user" -P "your broker password" -p 1883 -t home/pizero/bme680 -l

This can be automated launching bme680_mosquitto.sh using crontab, with the below command @reboot bash /home/pi/bsec_bme680_linux/bme680_mosquitto.sh >> /home/pi/bsec_bme680_linux/log 2>&1

Further

You can find a growing list of tools to further use and visualize the data here.

Troubleshooting

bsec_bme680 just quits without a message

Your bsec_iaq.state file might be corrupt or incompatible after an update of the BSEC library. Try (re)moving it.

About

Read the BME680 sensor with the BSEC library on Linux (e.g. Raspberry Pi)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 89.6%
  • Shell 10.4%