Projet

Général

Profil

Link probes to Rasp (software side) » Historique » Révision 3

Révision 2 (guillaume.devoyon, 24/05/2018 16:02) → Révision 3/4 (guillaume.devoyon, 24/05/2018 17:55)

h1. Link probes to Rasp (software side) 

 h2. 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@ sudo rpi-update 

 a reboot is need after upgrade. 

 We have to install pyhton packages and pip 

 <pre> 
 sudo apt-get install python3 pip 
 </pre> 


 Once all installed with perquisites, you can download the tooling for getting details from I2C ports: 
 <pre> 
 sudo apt-get install i2c-tools 
 </pre> 

 You also need to activate I2C on the rasp : 
 <pre> 
 sudo raspi-config 
 </pre> 

 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 : 

 <pre> 
 #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 
 </pre> 

 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 : 
 <pre> 
 sudo pip3 install bme280 
 </pre> 

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

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

 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 
 <pre> 
 sudo apt-get install sqlite 
 </pre> 

 <pre> 
 $ 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> 
 </pre> 

 A script can be run by cron to insert datas : 

 <pre> 
 #!/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')"; 
 </pre> 

 and this script use the config file openbeelab.conf 

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

 #external sensore address 
 EXTSENS=0x77 

 </pre>