Link probes to Rasp (software side) » Historique » Version 1
guillaume.devoyon, 24/05/2018 15:58
1 | 1 | guillaume.devoyon | h1. Link probes to Rasp (software side) |
---|---|---|---|
2 | |||
3 | h2. Software installation |
||
4 | |||
5 | We assume to that part, all previous steps are done : |
||
6 | |||
7 | 1) OS installation and Rasp working. You have sheel access on it. 2) BME280 is connected thru I2C ports (SDA/SCL). |
||
8 | |||
9 | First, we need to update RPI to last version of firmware (you need to have internet access to do so): |
||
10 | sudo rpi-update |
||
11 | |||
12 | a reboot is need after upgrade. |
||
13 | |||
14 | We have to install pyhton packages and pip |
||
15 | <pre> |
||
16 | sudo apt-get install python3 pip |
||
17 | </pre> |
||
18 | |||
19 | Once all installed with perquisites, you can download the tooling for getting details from I2C ports: |
||
20 | <pre> |
||
21 | sudo apt-get install i2c-tools |
||
22 | </pre> |
||
23 | |||
24 | You also need to activate I2C on the rasp : |
||
25 | <pre> |
||
26 | sudo raspi-config |
||
27 | </pre> |
||
28 | |||
29 | A ncurse blue screen must appear. You must go to : |
||
30 | |||
31 | "5 interfacing Options" ==> "P5 I2C Enable / Dibale I2C" |
||
32 | |||
33 | Once done you are ready to start. |
||
34 | |||
35 | Configuration |
||
36 | |||
37 | 1) we need to get the adress used by your BME280. We will use the tool installed with package I2C-tools above : |
||
38 | |||
39 | <pre> |
||
40 | #i2cdetect -y 1 |
||
41 | 0 1 2 3 4 5 6 7 8 9 a b c d e f |
||
42 | 00: -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
43 | 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
44 | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
45 | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
46 | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
47 | 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
48 | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
||
49 | 70: -- -- -- -- -- -- -- 77 |
||
50 | </pre> |
||
51 | |||
52 | In this case my BME280 is running on 0x77 adress. |
||
53 | |||
54 | To read values of sensors, we need to install the package from pip "BEM280". To do so : |
||
55 | <pre> |
||
56 | sudo pip3 install bme280 |
||
57 | </pre> |
||
58 | |||
59 | infos here : https://github.com/kbrownlees/bme280/blob/master/README.rst once installation done : |
||
60 | |||
61 | <pre> |
||
62 | $ ~/.local/bin/read_bme280 --i2c-address 0x77 |
||
63 | 1011.97 hPa |
||
64 | 58.31 % |
||
65 | 23.36 C |
||
66 | </pre> |
||
67 | |||
68 | You can note that usage is made by regular user. Some switches exist in order to get only one sensor value instead of all. |
||
69 | |||
70 | To store datas we will use sqlite which is super light in consumption perspective. To install |
||
71 | <pre> |
||
72 | sudo apt-get install sqlite |
||
73 | </pre> |
||
74 | |||
75 | <pre> |
||
76 | $ sqlite hive_sensors.db |
||
77 | SQLite version 2.8.17 |
||
78 | Enter ".help" for instructions |
||
79 | sqlite> create table bme280( |
||
80 | ...> DATE TEXT NOT NULL, |
||
81 | ...> SENSOR TEXT NOT NULL, |
||
82 | ...> PRESSURE REAL NOT NULL, |
||
83 | ...> TEMPERATURE REAL NOT NULL, |
||
84 | ...> HUMIDITY REAL NOT NULL |
||
85 | ...> ); |
||
86 | sqlite> |
||
87 | </pre> |
||
88 | |||
89 | A script can be run by cron to insert datas : |
||
90 | |||
91 | <pre> |
||
92 | #!/bin/sh |
||
93 | . ../config/openbeelab.conf |
||
94 | |||
95 | DATE=$( date +%Y-%m-%d ) |
||
96 | TIME=$( date +%H:%M ) |
||
97 | |||
98 | |||
99 | # get datas from censor |
||
100 | PRESSURE=`~/.local/bin/read_bme280 --i2c-address $EXTSENS --pressure` |
||
101 | HUMIDITY=`~/.local/bin/read_bme280 --i2c-address $EXTSENS --humidity` |
||
102 | TEMPERATURE=`~/.local/bin/read_bme280 --i2c-address $EXTSENS --temperature` |
||
103 | |||
104 | #modify a bit format for datas (remove space and unity) |
||
105 | PRESSURE=`echo $PRESSURE | sed 's/ *//g' | sed 's/hPa//g'` |
||
106 | HUMIDITY=`echo $HUMIDITY | sed 's/ *//g' | sed 's/%//g'` |
||
107 | TEMPERATURE=`echo $TEMPERATURE | sed 's/ *//g' | sed 's/C//g'` |
||
108 | |||
109 | echo "$PRESSURE $HUMIDITY $TEMPERATURE" |
||
110 | echo "sqlite3 $BASE/sqlite/openbeelab.db insert into bme280 values ($DATE $TIME,$EXTSENS,$PRESSURE,$TEMPERATURE,$HUMIDITY);" |
||
111 | |||
112 | # inserting in database |
||
113 | sqlite3 $BASE/sqlite/openbeelab.db "insert into bme280 values ('$DATE $TIME','$EXTSENS','$PRESSURE','$TEMPERATURE','$HUMIDITY')"; |
||
114 | </pre> |
||
115 | |||
116 | and this script use the config file openbeelab.conf |
||
117 | |||
118 | <pre> |
||
119 | # Configuration |
||
120 | # base repo of scripts |
||
121 | BASE=/home/pi/openbeelab_v1.0 |
||
122 | |||
123 | #external sensore address |
||
124 | EXTSENS=0x77 |
||
125 | |||
126 | </pre> |