Projet

Général

Profil

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

guillaume.devoyon, 24/05/2018 16:02

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