Projet

Général

Profil

Actions

Link probes to Rasp (software side)

Software installation

We assume to that part, all previous steps are done :

1) OS installation and Rasp working. You have sheel access on it. 2) BME280 is connected thru I2C ports (SDA/SCL).

First, we need to update RPI to last version of firmware (you need to have internet access to do so):

sudo rpi-update

a reboot is need after upgrade.

We have to install pyhton packages and pip

sudo apt-get install python3 pip

Once all installed with perquisites, you can download the tooling for getting details from I2C ports:

sudo apt-get install i2c-tools

You also need to activate I2C on the rasp :

sudo raspi-config

A ncurse blue screen must appear. You must go to :

"5 interfacing Options" ==> "P5 I2C Enable / Dibale I2C"

Once done you are ready to start.

Configuration

1) we need to get the adress used by your BME280. We will use the tool installed with package I2C-tools above :

#i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77

In this case my BME280 is running on 0x77 adress.

To read values of sensors, we need to install the package from pip "BEM280". To do so :

sudo pip3 install bme280

infos here : https://github.com/kbrownlees/bme280/blob/master/README.rst once installation done :

$ ~/.local/bin/read_bme280 --i2c-address 0x77
1011.97 hPa
  58.31 %
  23.36 C

You can note that usage is made by regular user. Some switches exist in order to get only one sensor value instead of all.

To store datas we will use sqlite which is super light in consumption perspective. To install

sudo apt-get install sqlite

$ sqlite hive_sensors.db
SQLite version 2.8.17
Enter ".help" for instructions
sqlite> create table bme280(
   ...> DATE TEXT NOT NULL,
   ...> SENSOR TEXT NOT NULL,
   ...> PRESSURE REAL NOT NULL,
   ...> TEMPERATURE REAL NOT NULL,
   ...> HUMIDITY REAL NOT NULL
   ...> );
sqlite>

A script can be run by cron to insert datas :

#!/bin/sh
. ../config/openbeelab.conf

DATE=$( date +%Y-%m-%d )
TIME=$( date +%H:%M )


# get datas from censor
PRESSURE=`~/.local/bin/read_bme280 --i2c-address $EXTSENS --pressure`
HUMIDITY=`~/.local/bin/read_bme280 --i2c-address $EXTSENS --humidity`
TEMPERATURE=`~/.local/bin/read_bme280 --i2c-address $EXTSENS --temperature`

#modify a bit format for datas (remove space and unity)
PRESSURE=`echo $PRESSURE | sed 's/ *//g' | sed 's/hPa//g'`
HUMIDITY=`echo $HUMIDITY | sed 's/ *//g' | sed 's/%//g'`
TEMPERATURE=`echo $TEMPERATURE | sed 's/ *//g' | sed 's/C//g'`

echo "$PRESSURE $HUMIDITY $TEMPERATURE"
echo "sqlite3 $BASE/sqlite/openbeelab.db insert into bme280 values ($DATE $TIME,$EXTSENS,$PRESSURE,$TEMPERATURE,$HUMIDITY);"

# inserting in database
sqlite3 $BASE/sqlite/openbeelab.db "insert into bme280 values ('$DATE $TIME','$EXTSENS','$PRESSURE','$TEMPERATURE','$HUMIDITY')";

and this script use the config file openbeelab.conf

# Configuration
# base repo of scripts
BASE=/home/pi/openbeelab_v1.0

#external sensore address
EXTSENS=0x77

Mis à jour par guillaume.devoyon il y a presque 6 ans · 4 révisions