diff --git a/IOT/Capteur/src/main.cpp b/IOT/Capteur/src/main.cpp index 967dae4..79903bf 100644 --- a/IOT/Capteur/src/main.cpp +++ b/IOT/Capteur/src/main.cpp @@ -5,22 +5,17 @@ #include #include #include +#include +#include -float readTemp() { - return 21.0; -} +DHT dht(DHT_PIN, DHT_TYPE);// pour capteur dht11 humi/temp +SFE_BMP180 pressure;// pour capteur BMP180 pression/temp -float readHum() { - return random(0,100); -} - - - -float data1; -float data2; void setup() { beginFDRS(); + dht.begin(); + pressure.begin(); if (!SD.begin(SD_CS)) { Serial.println("Fail, verifier que la carte SD est presente."); return; @@ -28,10 +23,35 @@ void setup() { } void loop() { - data1 = readHum(); + + // mesure DHT11 + float data1 = dht.readHumidity(); + float data2 = dht.readTemperature(); + + if (isnan(data1) || isnan(data2)) { + DBG("Failed to read from DHT sensor!"); + return; + } + + // mesure BMP180 + double data3; + double data4; + + char status = pressure.startTemperature(); + + if (status != 0){ + delay(status); + status = pressure.getPressure(data3,data4); + } + if(status == 0){ + DBG("failed to read BMP sensor!") + return; + } + loadFDRS(data1, HUMIDITY_T); - data2 = readTemp(); loadFDRS(data2, TEMP_T); + loadFDRS(data3, PRESSURE_T); + loadFDRS(data4, TEMP2_T); sendFDRS(); File dataFile = SD.open(LOG_FILENAME, FILE_WRITE); @@ -49,12 +69,24 @@ void loop() { dataFile.print(TEMP_T); dataFile.print(",\"data\":"); dataFile.print(data2); + dataFile.print("},{\"id\":"); + dataFile.print(READING_ID); + dataFile.print(",\"type\":"); + dataFile.print(PRESSURE_T); + dataFile.print(",\"data\":"); + dataFile.print(data3); + dataFile.print("},{\"id\":"); + dataFile.print(READING_ID); + dataFile.print(",\"type\":"); + dataFile.print(TEMP2_T); + dataFile.print(",\"data\":"); + dataFile.print(data4); dataFile.println("}]"); dataFile.close(); }else{ DBG("SD fail"); } - // [{"id":2,"type":3,"data":66},{"id":2,"type":1,"data":21}] + // [{"id":2,"type":3,"data":66},{"id":2,"type":1,"data":21},{"id":2,"type":1,"data":21},{"id":2,"type":1,"data":21}] sleepFDRS(10); //Sleep time in seconds }