Sigfox project

Dependencies:   mbed TCS34725 WakeUp DHT TSL2561_I2C DS1820

Revision:
4:0b63b5897827
Parent:
3:a5b1e083ffd2
Child:
5:59c1c70635c3
--- a/main.cpp	Mon Nov 18 15:49:02 2019 +0000
+++ b/main.cpp	Mon Jan 20 12:30:17 2020 +0000
@@ -3,6 +3,7 @@
 #include "DHT.h"
 #include "TSL2561_I2C.h"
 #include "Adafruit_TCS34725.h"
+#include "WakeUp.h"
 #define commonAnode true
 
 
@@ -10,19 +11,19 @@
 Serial pc(USBTX, USBRX);
 
 //tempAir et humAir
-DHT dht(D12, 22);
+DHT dht(D9, 22);
 
 
 //RGB
 I2C i2c(PB_7, PB_6);
 Adafruit_TCS34725 tcs = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
 
-//tempSol
-DS1820 temp_sol(A7);
+//tempSol 
+DS1820 temp_sol(A4);
 
 
 //luminosite
-TSL2561_I2C lum (PB_7, PB_6);
+//TSL2561_I2C lum (PB_4, PA_7);
 
 
 //humSol
@@ -30,12 +31,15 @@
 
 int main(){
     
+    //WakeUp::calibrate();   
+    
+        
     //DHT22
     int data;
     float tempAir, humAir;
     
     //temp_sol
-    if(temp_sol.unassignedProbe(A2))
+    if(temp_sol.unassignedProbe(A4))
     {
         pc.printf("error temperature_sol");
     }
@@ -46,10 +50,10 @@
     
     //luminosite
     float lux;
-    if(!lum.enablePower())
+    /*if(!lum.enablePower())
     {
         pc.printf("error luminosite");
-    }
+    }*/
     
 
     
@@ -57,29 +61,11 @@
     ////////////////////RGB//////////////////
     /////////////////////////////////////////
     
-    char gammatable[256];
+    //char gammatable[256];
     if(!tcs.begin())
     {
         pc.printf("No TCS34725 found ... check your connections");
     }
-    for (int i=0; i<256; i++)
-    {
-        float x = i;
-        x /= 255;
-        x = pow((double)x, 2.5);
-        x *= 255;
-        if (commonAnode)
-        {
-            gammatable[i] = 255 - x;
-        }
-        else
-        {
-            gammatable[i] = x;      
-        }
-    }
-    
-    
-    
     
     while(1){
         //Capteur air
@@ -87,8 +73,7 @@
         humAir = dht.ReadHumidity();
         tempAir = dht.ReadTemperature(CELCIUS);
         pc.printf("tempAir = %1.f, humAir = %1.f\n", tempAir, humAir);
-        int valeur = 3;
-        wisol.printf("AT$SF=%02X%02X\r\n", (int)tempAir, (int)humAir);
+        
         
         //capteur humidite sol
         hum_sol = (int)(((0.78 - ain.read())*100)/0.38);
@@ -99,10 +84,6 @@
         pc.printf("tempSol : %.1f\n", temp_sol.temperature());
         
         
-        //luminosite
-        lux = lum.getLux();
-        pc.printf("lux = %d\n", (int)lux);
-        
         
         ///////////////
         //Capteur RGB//
@@ -123,13 +104,29 @@
         r *= 256; g *= 256; b *= 256;
         pc.printf("clear = %d, red = %d, green = %d, blue = %d\r\n\n", clear, (int)r, (int)g, (int)b);
         
-        wisol.printf("AT$SF=%06X%02X%02X%02X%04X%02X%04X%02X\r\n", (int)lux, (int)r, (int)g, (int)b, (int)(10*temp_sol.temperature()), (int)(hum_sol*10), (int)(tempAir*10), (int)(humAir*10));
+        
+        
+        
+        //luminosite
+        //lux = lum.getLux();
+        lux = (int)tcs.calculateLux(red,green,blue);
+        pc.printf("lux = %d\n", (int)lux);
+        
+        
+        wisol.printf("AT$SF=%06X%02X%02X%02X%04X%02X%04X%02X\r\n", (int)lux, (int)r, (int)g, (int)b, (int)(10 * temp_sol.temperature()), (int)(hum_sol), (int)(10 * tempAir), (int)(humAir));
+                
+        //wisol.printf("AT$SF=%06X%02X%02X%02X%04X%02X%04X%02X\r\n", (int)lux, (int)r, (int)g, (int)b, temp_solT, (int)(hum_sol*10), (int)(tempAir*10), (int)(humAir*10));
         //lux : 3 octets
         //r, g, b : 1 octet
         //tempSol, tempAir : 2 octets
         //humSol, humAir : 1 octet
         
-        wait(1000);
+        wait(10);
+        
+        //Set wakeup time for 500 seconds
+        WakeUp::set_ms(10000);
+        deepsleep();
+        wait(1);
         
     }
 }
\ No newline at end of file