Keep bmp180 status information
This commit is contained in:
parent
9ca3c49aa2
commit
e99f63ef41
@ -1,3 +1,15 @@
|
|||||||
|
SFE_BMP180 bmp180;
|
||||||
|
int bmp180Connected = 0;
|
||||||
|
|
||||||
|
int setupBMP180() {
|
||||||
|
bmp180Connected = bmp180.begin(SDA, SCL);
|
||||||
|
return bmp180Connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isBMPConnected() {
|
||||||
|
return bmp180Connected != 0;
|
||||||
|
}
|
||||||
|
|
||||||
int getTemperature(double &t) {
|
int getTemperature(double &t) {
|
||||||
char status;
|
char status;
|
||||||
status = bmp180.startTemperature();
|
status = bmp180.startTemperature();
|
||||||
|
@ -5,6 +5,7 @@ void handleRoot() {
|
|||||||
"Current temperature " + String(temp, 2) + "C<br/>"
|
"Current temperature " + String(temp, 2) + "C<br/>"
|
||||||
"Current pressure " + String(pressure, 2) + "mB<br/>"
|
"Current pressure " + String(pressure, 2) + "mB<br/>"
|
||||||
"MQTT Status: " + (MQTT_isConnected() ? "Connected" : "Disconnected") + "<br/>"
|
"MQTT Status: " + (MQTT_isConnected() ? "Connected" : "Disconnected") + "<br/>"
|
||||||
|
"BMP 180 (Temp+Pression) Status: " + (isBMPConnected() ? "Connected" : "Disconnected") + "<br/>"
|
||||||
"Free space: "+ ESP.getFreeSketchSpace() +"<br/>"
|
"Free space: "+ ESP.getFreeSketchSpace() +"<br/>"
|
||||||
"Free heap: "+ ESP.getFreeHeap() +"<br/>"
|
"Free heap: "+ ESP.getFreeHeap() +"<br/>"
|
||||||
"<a href=\"/setup\">Setup</a><br/>"
|
"<a href=\"/setup\">Setup</a><br/>"
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
//#define ENABLE_EXTRA_GPIO
|
//#define ENABLE_EXTRA_GPIO
|
||||||
|
|
||||||
#define EEPROM_SIZE 512
|
#define EEPROM_SIZE 256
|
||||||
char eeprom[EEPROM_SIZE];
|
char eeprom[EEPROM_SIZE];
|
||||||
|
|
||||||
#define WEB_DELAY_MS 100
|
#define WEB_DELAY_MS 100
|
||||||
@ -49,7 +49,6 @@ uint8_t mode;
|
|||||||
const char *ssid = "ESPConfigurator";
|
const char *ssid = "ESPConfigurator";
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
SFE_BMP180 bmp180;
|
|
||||||
|
|
||||||
/* WebServer decl*/
|
/* WebServer decl*/
|
||||||
void handleRoot();
|
void handleRoot();
|
||||||
@ -68,6 +67,9 @@ void readEEPROM(uint8_t &bootMode, char **ssid, char **password, char **host, ch
|
|||||||
/* BMP180 decl */
|
/* BMP180 decl */
|
||||||
int getTemperature(double &t);
|
int getTemperature(double &t);
|
||||||
int getTempAndPressure(double &t, double &p);
|
int getTempAndPressure(double &t, double &p);
|
||||||
|
int setupBMP180();
|
||||||
|
bool isBMPConnected();
|
||||||
|
|
||||||
|
|
||||||
/* MQTT decl */
|
/* MQTT decl */
|
||||||
int MQTT_connect();
|
int MQTT_connect();
|
||||||
@ -195,7 +197,7 @@ void setup() {
|
|||||||
if (mode == BOOTMODE_OTA) {
|
if (mode == BOOTMODE_OTA) {
|
||||||
setupOTA();
|
setupOTA();
|
||||||
} else {
|
} else {
|
||||||
if (bmp180.begin(SDA, SCL))
|
if (setupBMP180())
|
||||||
Serial.println("BMP180 init success");
|
Serial.println("BMP180 init success");
|
||||||
setupWebServer(mode);
|
setupWebServer(mode);
|
||||||
}
|
}
|
||||||
@ -210,7 +212,7 @@ void loop() {
|
|||||||
delay(WEB_DELAY_MS);
|
delay(WEB_DELAY_MS);
|
||||||
nbCycle++;
|
nbCycle++;
|
||||||
if (nbCycle > SAMPLING_PERIODE_MS / WEB_DELAY_MS) {
|
if (nbCycle > SAMPLING_PERIODE_MS / WEB_DELAY_MS) {
|
||||||
if (getTempAndPressure(temp, pressure) == 0) {
|
if (isBMPConnected() && getTempAndPressure(temp, pressure) == 0) {
|
||||||
Serial.print("Current T°C ");
|
Serial.print("Current T°C ");
|
||||||
Serial.print(temp);
|
Serial.print(temp);
|
||||||
Serial.print( " Pressure mB ");
|
Serial.print( " Pressure mB ");
|
||||||
|
Loading…
Reference in New Issue
Block a user