-
Notifications
You must be signed in to change notification settings - Fork 20
/
E05_ESP_BMP180.ino
226 lines (178 loc) · 7.58 KB
/
E05_ESP_BMP180.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*NOTES: IMPORTANT! Take care if you have a wire library on your Arduino IDE because it will be used
instead of the library stored on the core of ESP.
Just make a backup of Wire folder on ArduinoIDE/libraries folder and delete the folder.
WIRE PIN CONFIGURATION:
On the ESP library you need to call to Wire.begin() with PIN as parameters
so to configure the SFE_BMP180 library you need to modify this line with Wire.begin(4.5);
*/
// Configure the framework
#include "bconf/MCU_ESP8266.h" // Load the code directly on the ESP8266
#include "conf/Gateway.h" // The main node is the Gateway, we have just one node
#include "conf/IPBroadcast.h"
// Define the WiFi name and password
#define WIFICONF_INSKETCH
#define WiFi_SSID "SSID"
#define WiFi_Password "PASSWORD"
// Include framework code and libraries
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include "Souliss.h"
// This identify the number of the LED logic
#define PRESSURE0 0
#define BMP180TEMP 2
// SDA and SCL pins can be configured, you need to edit SFE_BMP180/SFE_BMP180.cpp line 38. Preconfigured at 14, 12.
#include <SFE_BMP180.h>
#include <Wire.h>
#define ALTITUDE 20.0 // Altitude of reading location in meters
// You will need to create an SFE_BMP180 object, here called "pressure":
SFE_BMP180 pressure;
#define Debug Serial //Change to Serial1 if you want to use the GPIO2 to TX
void setup()
{
Initialize();
Debug.begin(115200);
// Connect to the WiFi network and get an address from DHCP
GetIPAddress();
SetAsGateway(myvNet_dhcp); // Set this node as gateway for SoulissApp
// This is the vNet address for this node, used to communicate with other
// nodes in your Souliss network
SetAddress(0xAB01, 0xFF00, 0x0000);
//Example of Peer Definition
//SetAsPeerNode(0xAB02, 1);
Set_Pressure(PRESSURE0);
Set_Temperature(BMP180TEMP);
if (pressure.begin())
Debug.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.
Debug.println("BMP180 init fail\n\n");
}
}
void loop()
{
EXECUTEFAST() {
UPDATEFAST();
// Here we handle here the communication with Android
FAST_GatewayComms();
}
EXECUTESLOW() {
UPDATESLOW();
SLOW_10s() { // Read temperature and humidity from DHT every 110 seconds
Logic_Pressure(PRESSURE0);
Logic_Temperature(BMP180TEMP);
}
SLOW_50s() {
Souliss_GetPressure_BMP180(PRESSURE0,BMP180TEMP);
}
}
}
/***************************************************************************/
/* BMP180 I2C READING FUNCTION */
/***************************************************************************/
float Souliss_GetPressure_BMP180(uint8_t SLOT_PRESSURE, uint8_t SLOT_TEMPERATURE){
boolean DEBUG_PRESSURE = 0;
char status;
double T,P,p0,a;
// Loop here getting pressure readings every 10 seconds.
// If you want sea-level-compensated pressure, as used in weather reports,
// you will need to know the altitude at which your measurements are taken.
// We're using a constant called ALTITUDE in this sketch:
if(DEBUG_PRESSURE){
Debug.println();
Debug.print("provided altitude: ");
Debug.print(ALTITUDE,0);
Debug.print(" meters, ");
Debug.print(ALTITUDE*3.28084,0);
Debug.println(" feet");
}
// If you want to measure altitude, and not pressure, you will instead need
// to provide a known baseline pressure. This is shown at the end of the sketch.
// You must first get a temperature measurement to perform a pressure reading.
// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = pressure.getTemperature(T);
if (status != 0)
{
if(DEBUG_PRESSURE){
// Print out the measurement:
Debug.print("temperature: ");
Debug.print(T,2);
Debug.print(" deg C, ");
Debug.print((9.0/5.0)*T+32.0,2);
Debug.println(" deg F");
}
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = pressure.getPressure(P,T);
if (status != 0)
{
if(DEBUG_PRESSURE){
// Print out the measurement:
Debug.print("absolute pressure: ");
Debug.print(P,2);
Debug.print(" mb, ");
Debug.print(P*0.0295333727,2);
Debug.println(" inHg");
}
// The pressure sensor returns abolute pressure, which varies with altitude.
// To remove the effects of altitude, use the sealevel function and your current altitude.
// This number is commonly used in weather reports.
// Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
// Result: p0 = sea-level compensated pressure in mb
p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
if(DEBUG_PRESSURE){
Debug.print("relative (sea-level) pressure: ");
Debug.print(p0,2);
Debug.print(" mb, ");
Debug.print(p0*0.0295333727,2);
Debug.println(" inHg");
}
// On the other hand, if you want to determine your altitude from the pressure reading,
// use the altitude function along with a baseline pressure (sea-level or other).
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
// Result: a = altitude in m.
a = pressure.altitude(P,p0);
if(DEBUG_PRESSURE){
Debug.print("computed altitude: ");
Debug.print(a,0);
Debug.print(" meters, ");
Debug.print(a*3.28084,0);
Debug.println(" feet");
}
float pressure = p0;
float temperature = T;
Souliss_ImportAnalog(memory_map, SLOT_PRESSURE, &pressure);
Souliss_ImportAnalog(memory_map, SLOT_TEMPERATURE, &temperature);
return p0;
}
else if(DEBUG_PRESSURE) Debug.println("error retrieving pressure measurement\n");
}
else if(DEBUG_PRESSURE) Debug.println("error starting pressure measurement\n");
}
else if(DEBUG_PRESSURE) Debug.println("error retrieving temperature measurement\n");
}
else if(DEBUG_PRESSURE) Debug.println("error starting temperature measurement\n");
}