Projet

Général

Profil

Link probes to Rasp (software side) » Historique » Version 4

guillaume.devoyon, 24/05/2018 17:55

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