Plant Monitoring Project
Dependencies: mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820
Diff: main.cpp
- Revision:
- 34:fb1b9c5e5cf3
- Parent:
- 33:b576ea9bf0e3
- Child:
- 35:d87c1391706a
--- a/main.cpp Tue Dec 17 18:45:22 2019 +0000 +++ b/main.cpp Tue Jan 07 17:57:19 2020 +0000 @@ -1,7 +1,10 @@ #include "main.hh" +int main(){ + #ifdef DEEPSLEEP + WakeUp::calibrate(); + #endif -int main(){ #ifdef INTERRUPTEUR interrupteur = 1; #endif @@ -12,11 +15,39 @@ #endif while(1) { - readData(); - wait(DUREE_OFF); + if(flag_readData) + readData(); + flag_readData = true; + #ifndef DEEPSLEEP + wait(DUREE_OFF); + #endif + #ifdef DEEPSLEEP + if(oled_on){ + wait(DUREE_ECRAN_ON); + turnOffScreen(); + flag_readData = false; + } + else{ + WakeUp::set(DUREE_OFF); + deepsleep(); + } + #endif } } +#ifdef AIR_PARAMETERS_DHT22 +void air_temp_hum(){ + int err; + wait(1); + do{ + err = dht_sensor.readData(); + wait(1); + }while(err != 0); + temperature_air = dht_sensor.ReadTemperature(CELCIUS); + humidity_air = dht_sensor.ReadHumidity(); +} +#endif + #ifdef FLOOR_TEMPERATURE void temp_sol() { @@ -92,7 +123,7 @@ tempSol_short = (short)(temperature_sol*10); tempAir_short = (short)(temperature_air*10); - wisol.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, humidity_sol, tempAir_short, humidity_air, lum, pr, pg, pb); + wisol.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x%02x\r\n",tempSol_short, humidity_sol, tempAir_short, humidity_air, lum, pr, pg, pb, vBat); } #endif @@ -139,9 +170,8 @@ #ifdef FLOOR_HUMIDITY humidity_sol = fct_humidity_sol(); #endif - #ifdef AIR_PARAMETERS - temperature_air = sht.readTemp(); - humidity_air = sht.readHumidity(); + #ifdef AIR_PARAMETERS_DHT22 + air_temp_hum(); #endif #ifdef DEBUG printf("hum air: %d\n\r", humidity_air); @@ -157,6 +187,9 @@ if(oled_on) oledData(); #endif + #ifdef BATTERY_LVL + readBatteryLvl(); + #endif #ifdef INTERRUPTEUR wait(8); // Il faut du temps au module SigFox pour envoyer les données interrupteur = 0; @@ -171,7 +204,6 @@ #ifdef OLED if(!oled_on){ oledData(); - timeScreen.attach(&turnOffScreen,DUREE_ECRAN_ON); } #endif bouton.enable_irq(); @@ -182,7 +214,6 @@ #ifdef DEBUG pc.printf("Turning off screen \n\r"); #endif - timeScreen.detach(); oled_on = 0; oled.sleep(); } @@ -210,4 +241,18 @@ oled.update(); oled.sleep(); } -#endif \ No newline at end of file +#endif + +void readBatteryLvl(void){ + float calcVbat = 0; + int batIn = 0; + float ain = battery.read(); + batIn = 100*ain; + calcVbat = ((float)(batIn - BATTERIE_MIN)/(float)(BATTERIE_MAX - BATTERIE_MIN))*100; + vBat = calcVbat; + #ifdef DEBUG + pc.printf("batIn = %d\n\r", batIn); + pc.printf("calcVbat = %d\n\r", calcVbat); + pc.printf("vBat = %d\n\r", vBat); + #endif +} \ No newline at end of file