From e99f63ef4135a9192c0067fa5daf12e96e13b1ec Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Sun, 20 Mar 2016 00:14:24 +0100 Subject: [PATCH] Keep bmp180 status information --- WifiControlSensor/BMP180.ino | 12 ++++++++++++ WifiControlSensor/WebServer.ino | 1 + WifiControlSensor/WifiControlSensor.ino | 10 ++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/WifiControlSensor/BMP180.ino b/WifiControlSensor/BMP180.ino index 078e496..811b6b8 100644 --- a/WifiControlSensor/BMP180.ino +++ b/WifiControlSensor/BMP180.ino @@ -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) { char status; status = bmp180.startTemperature(); diff --git a/WifiControlSensor/WebServer.ino b/WifiControlSensor/WebServer.ino index d835c87..c696495 100644 --- a/WifiControlSensor/WebServer.ino +++ b/WifiControlSensor/WebServer.ino @@ -5,6 +5,7 @@ void handleRoot() { "Current temperature " + String(temp, 2) + "C
" "Current pressure " + String(pressure, 2) + "mB
" "MQTT Status: " + (MQTT_isConnected() ? "Connected" : "Disconnected") + "
" + "BMP 180 (Temp+Pression) Status: " + (isBMPConnected() ? "Connected" : "Disconnected") + "
" "Free space: "+ ESP.getFreeSketchSpace() +"
" "Free heap: "+ ESP.getFreeHeap() +"
" "Setup
" diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 9e64a8d..d780d8c 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -28,7 +28,7 @@ //#define ENABLE_EXTRA_GPIO -#define EEPROM_SIZE 512 +#define EEPROM_SIZE 256 char eeprom[EEPROM_SIZE]; #define WEB_DELAY_MS 100 @@ -49,7 +49,6 @@ uint8_t mode; const char *ssid = "ESPConfigurator"; ESP8266WebServer server(80); -SFE_BMP180 bmp180; /* WebServer decl*/ void handleRoot(); @@ -68,6 +67,9 @@ void readEEPROM(uint8_t &bootMode, char **ssid, char **password, char **host, ch /* BMP180 decl */ int getTemperature(double &t); int getTempAndPressure(double &t, double &p); +int setupBMP180(); +bool isBMPConnected(); + /* MQTT decl */ int MQTT_connect(); @@ -195,7 +197,7 @@ void setup() { if (mode == BOOTMODE_OTA) { setupOTA(); } else { - if (bmp180.begin(SDA, SCL)) + if (setupBMP180()) Serial.println("BMP180 init success"); setupWebServer(mode); } @@ -210,7 +212,7 @@ void loop() { delay(WEB_DELAY_MS); nbCycle++; 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(temp); Serial.print( " Pressure mB ");