Same return value for every sensor after Setup()
This commit is contained in:
parent
ff4f72e1f7
commit
786fedc74f
@ -5,9 +5,6 @@
|
|||||||
|
|
||||||
// Get Current altitude with http://fr.mygeoposition.com/
|
// Get Current altitude with http://fr.mygeoposition.com/
|
||||||
#define ALTITUDE 130
|
#define ALTITUDE 130
|
||||||
SFE_BMP180 bmp180;
|
|
||||||
int bmp180Connected = 0;
|
|
||||||
|
|
||||||
int BMP180GetTemperature(double &t);
|
int BMP180GetTemperature(double &t);
|
||||||
int BMP180GetTempAndPressure(double &t, double &p);
|
int BMP180GetTempAndPressure(double &t, double &p);
|
||||||
int BMP180Setup(int sda, int scl);
|
int BMP180Setup(int sda, int scl);
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
#ifdef CONFIG_ENABLE_BMP180
|
#ifdef CONFIG_ENABLE_BMP180
|
||||||
#include "BMP180.h"
|
#include "BMP180.h"
|
||||||
|
SFE_BMP180 bmp180;
|
||||||
|
int bmp180Connected = 0;
|
||||||
|
|
||||||
int BMP180Setup(int sda, int scl) {
|
int BMP180Setup(int sda, int scl) {
|
||||||
//Use BMP fork at https://github.com/mmaret/BMP180_Breakout_Arduino_Library/archive/master.zip
|
//Use BMP fork at https://github.com/mmaret/BMP180_Breakout_Arduino_Library/archive/master.zip
|
||||||
bmp180Connected = bmp180.begin(sda, scl);
|
bmp180Connected = bmp180.begin(sda, scl);
|
||||||
if (!bmp180Connected){
|
if (!bmp180Connected){
|
||||||
SKETCH_DEBUG_PRINTLN("Cannot connect to BMP180");
|
SKETCH_DEBUG_PRINTLN("Cannot connect to BMP180");
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
return bmp180Connected;
|
return 0;
|
||||||
|
err:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BMP180IsConnected() {
|
bool BMP180IsConnected() {
|
||||||
|
@ -228,10 +228,10 @@ void setup() {
|
|||||||
if (mode == BOOTMODE_OTA) {
|
if (mode == BOOTMODE_OTA) {
|
||||||
OTASetup();
|
OTASetup();
|
||||||
} else {
|
} else {
|
||||||
if (BMP180Setup(CONFIG_BMP180_SDA, CONFIG_BMP180_SCL)){
|
if (!BMP180Setup(CONFIG_BMP180_SDA, CONFIG_BMP180_SCL)){
|
||||||
SKETCH_DEBUG_PRINTLN("BMP180 init success");
|
SKETCH_DEBUG_PRINTLN("BMP180 init success");
|
||||||
}
|
}
|
||||||
if (DHTSetup(CONFIG_DHT_PIN)){
|
if (!DHTSetup(CONFIG_DHT_PIN)){
|
||||||
SKETCH_DEBUG_PRINTLN("DHT init success");
|
SKETCH_DEBUG_PRINTLN("DHT init success");
|
||||||
}
|
}
|
||||||
WebSetupServer(mode);
|
WebSetupServer(mode);
|
||||||
@ -252,14 +252,14 @@ void loop() {
|
|||||||
|
|
||||||
nbCycle++;
|
nbCycle++;
|
||||||
if (nbCycle > CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS) {
|
if (nbCycle > CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS) {
|
||||||
if (BMP180GetTempAndPressure(temp, pressure) == 0) {
|
if (!BMP180GetTempAndPressure(temp, pressure)) {
|
||||||
SKETCH_DEBUG_PRINT("Current T°C ");
|
SKETCH_DEBUG_PRINT("Current T°C ");
|
||||||
SKETCH_DEBUG_PRINT(temp);
|
SKETCH_DEBUG_PRINT(temp);
|
||||||
SKETCH_DEBUG_PRINT(" Pressure mB ");
|
SKETCH_DEBUG_PRINT(" Pressure mB ");
|
||||||
SKETCH_DEBUG_PRINTLN(pressure);
|
SKETCH_DEBUG_PRINTLN(pressure);
|
||||||
MqttPublish(temp, pressure);
|
MqttPublish(temp, pressure);
|
||||||
}
|
}
|
||||||
if (DHTGetTempAndHumidity(dhtTemp, dhtHumidity) == 0) {
|
if (!DHTGetTempAndHumidity(dhtTemp, dhtHumidity)) {
|
||||||
SKETCH_DEBUG_PRINT("Current T°C ");
|
SKETCH_DEBUG_PRINT("Current T°C ");
|
||||||
SKETCH_DEBUG_PRINT(dhtTemp);
|
SKETCH_DEBUG_PRINT(dhtTemp);
|
||||||
SKETCH_DEBUG_PRINT(" Humidity ");
|
SKETCH_DEBUG_PRINT(" Humidity ");
|
||||||
|
@ -8,7 +8,7 @@ int DHTGetTempAndHumidity(float &t, float &h);
|
|||||||
bool DHTIsConnected();
|
bool DHTIsConnected();
|
||||||
|
|
||||||
#else //CONFIG_ENABLE_DHT
|
#else //CONFIG_ENABLE_DHT
|
||||||
int DHTSetup(int pin){SKETCH_DEBUG_PRINTLN("DHT is disabled at build time"); return 0};
|
int DHTSetup(int pin){SKETCH_DEBUG_PRINTLN("DHT is disabled at build time"); return -1};
|
||||||
int DHTGetTempAndHumidity(float &t, float &h){return -1;};
|
int DHTGetTempAndHumidity(float &t, float &h){return -1;};
|
||||||
bool DHTIsConnected(){return false;};
|
bool DHTIsConnected(){return false;};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user