softemp

Dependencies:   mbed DHT22 ATParser SerialGPS

Revision:
2:f760e8507750
Parent:
1:297aba9a5830
--- a/main.cpp	Wed Jan 17 14:34:05 2018 +0000
+++ b/main.cpp	Fri Feb 02 10:00:12 2018 +0000
@@ -1,171 +1,173 @@
 #include "mbed.h"
-#include "SerialGPS.h"
 #include "DHT22.h"
-#include "Sigfox.h"
-#include "BufferedSerial.h"
-//#include "ATParser.h"
+#include "string.h"
+#include "DS1820.h"
 
  
-Serial pc(USBTX, USBRX); // tx, rx
-SerialGPS gps(PC_10,PC_11);  // tx, rx
-DHT22 dht22(D4);//pin pour la lecture du dht22 grove
-DHT22 dht22Bis(D5);//pin pour la lecture du dht22 
+Serial pc(USBTX,USBRX); // tx, rx
+Serial sigfox(PA_9,PA_10); // tx, rx
+DHT22 dht22(D3);//pin pour la lecture du dht22 grove
+DHT22 dht22Bis(D6);//pin pour la lecture du dht22 
 AnalogIn IRSensor(A1);//Pin de lecture du capteur IR
-
-BufferedSerial serial = BufferedSerial(PC_10,PC_11);
-//ATParser at = ATParser(serial, "\r\n");
-Sigfox sig(*);
-
-//Sigfox(at(&at));
+DigitalOut led0(LED1);
+DigitalOut led1(LED2);
+double longi;
+double lat;
+const int MAX_PROBES = 1;
+DS1820 probe[1] = {A4};
 
 
-//programme du gps
-
-/**
- * A callback function for logging data.
- */
-void cbfunc_log(char *s) {
-
-}
-
-/**
- * A callback function for GGA.
- *
- * GGA - Global Positioning System Fixed Data.
- */
-void cbfunc_gga(SerialGPS::gps_gga_t *p) {
-
-     pc.printf("%02d:%02d:%02d(P%d,S%d)\r\n", p->hour, p->min, p->sec, p->position_fix, p->satellites_used);
-
-       // pc.printf("latitude  %c=%10.4f\r\n", p->ns, p->latitude);
-
-       // pc.printf("longitude %c=%10.4f\r\n", p->ew, p->longitude);
-        double a = p->latitude;
-        double b = p->longitude;
-        pc.printf("latitude %10.4f\r\n", a);
-        pc.printf("longitude %10.4f\r\n", b);
-}
-
-/**
- * A callback function for GSA.
- *
- * GSA - GNSS DOP and Active Satellites.
- */
-void cbfunc_gsa(SerialGPS::gps_gsa_t *p) {
-
-  pc.printf("SEL:%c FIX:%d\r\n", p->selmode, p->fix);
-  
-}
-
-/**
- * A callback function for GSV.
- *
- * GSV - GNSS Satellites in View.
- */
-void cbfunc_gsv(SerialGPS::gps_gsv_t *p) {
- 
-      pc.printf("Satellites:%2d\r\n", p->satcnt);
-
-}
-
-/**
- * A callback function for RMC.
- *
- * RMC - Recommended Minimum Specific GNSS Data.
- */
-void cbfunc_rmc(SerialGPS::gps_rmc_t *p) {
-
-     pc.printf("%02d:%02d:%02d(%c)\r\n", p->hour, p->min, p->sec, p->status);
-
-}
-
-/**
- * Entry point.
- */
-
-//fin du prgramme de lecture GPS
 
 //Fonction lecture des donneé sigfox
 
  
 int main() {
-    //programme main du gps
-        //programme main de lecture DHT22
-    
-    int hum;
-    int temp;
-    int hum1;
-    int temp1;
-    
+  
+   int humExt;  // humidité intérieur dst22
+   int tempExt; // température extérieur dst22
+   int humInt;  // humidité intérieur dst22
+   int tempInt; // température intérieur dst22
+   int i;
+   int devices_found=0;
+   int tempDs; //tempérarure de la sonde Ds18B20;
+   
     pc.baud(9600);
- 
+    sigfox.baud(9600);
     
     pc.printf("TEST\r\n");
     wait(0.5);
-    pc.printf("TEST1\r\n");
-    
-    SerialGPS::gps_callback_t cb;
-    cb.cbfunc_log = cbfunc_log;
-    pc.printf("TEST2\r\n");
+
+    //partie declarative DS18B20
+    pc.printf("Started\r\n");
+    pc.printf("search_ROM_setup\r\n");
+    probe[0].search_ROM_setup();
+    pc.printf("search_ROM\r\n");
+ 
+     while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1)
+          devices_found++;
     
-    cb.cbfunc_gsa = cbfunc_gsa;
-    cb.cbfunc_gsv = cbfunc_gsv;
-    cb.cbfunc_rmc = cbfunc_rmc;
-    gps.attach(&cb);
-    pc.printf("TEST3\r\n");
-
+    // If maximum number of probes are found,
+    // bump the counter to include the last array entry
+    if (probe[devices_found].ROM[0] != 0xFF)
+        devices_found++;
+    pc.printf("devices found:%d\r\n",devices_found);
+    
+        //Fin de la partie declarative DS18B20   
+        
     while(1) {
-        
+     char donnee[] = "AT$SF=";
      wait(1);
-     gps.processing();
      pc.printf("TEST4\r\n");
-     //lecture du DHT22 grove
-             
-       dht22.sample() ;
-        hum=dht22.getHumidity()/10.0;
-        temp=dht22.getTemperature()/10.0;
-        printf("temperature: %d, humidity: %d\n\r",temp,hum);
+     
+   //  lecture du DHT22 grove
+            
+        dht22.sample() ;
+        humExt=dht22.getHumidity()/10.0;
+        tempExt=dht22.getTemperature()/10.0;
+        pc.printf("temperature: %d humidity: %d\n\r",tempExt,humExt);
         
-        //lecture du DHT22 simple
-        
-        dht22Bis.sample() ;
-        hum1=dht22Bis.getHumidity()/10.0;
-        temp1=dht22Bis.getTemperature()/10.0;
-        printf("temperature1: %3d, humidity1: %3d\n\r",temp1,hum1);
+        //lecture du DHT22 simple Intérieure 
+      
+        dht22Bis.sample(); 
+        humInt=dht22Bis.getHumidity()/10.0;
+        tempInt=dht22Bis.getTemperature()/10.0;
+        pc.printf("temperature1: %d humidity1: %d\n\r",tempInt,humInt);
       
         //mesure de la distance 
-        
-        //wait(2);
-       //3.1V at 4cm to 0.3V at 30cm. 
+      
+             //3.1V at 4cm to 0.3V at 30cm. 
        float a = IRSensor;// 1=4cm 0=30cm
-       pc.printf("IR sensor reads %2.2f\n ", a);
-       a=1-a;// now 0=4cm and 1=30cm 
-       float b= 40+a * 260; //(a26+4);
-       pc.printf("\rDistance is %2.2f mm \n ", b); // print and convert to distance by taking x=0->1 and 26x+4
-      float x = 200 - b;
-      float f = 2.913*x;
-      int m= 1000*(f/(9.8));
-      pc.printf("\la masse de la ruche est egale a %2.2f g \n ",m); 
+       //pc.printf("IR sensor reads %2.2f\n ", a);
+       float v=2.8*a;
+      //  pc.printf("\r ANALOGIN %2.2f v \n ", v);
+       float l= 10*((12/v)-0.42);
      
-      sig->send(""+m);
+       pc.printf("\rDistance is %2.2f mm \n ", l); // print and convert to distance by taking x=0->1 and 26*x+4
+       float x=193-l;//218
+       float f= 4*(2.913*x);//2.5
+       int m = (f/(9.8));
+       pc.printf("\la masse de la ruche est égale à %d Kg \n ",m); 
+       
+       //mesure de la température avec DS18B20
+
+        probe[0].convert_temperature(DS1820::all_devices);
+        for (i=0; i<devices_found; i++) {
+            tempDs = probe[i].temperature('c');
+            pc.printf("Device[%d]: %d \r\n",i,tempDs);
+        }
+       
+       //fin de mesure de temperature avec DS18B20
+    
+      
+        pc.printf("TEST5\r\n");
+
+    
+        
+        
+        if(humExt<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt);
+         pc.printf("\n");
+         
+       if(humInt<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt);
+         pc.printf("\n");
+         
+        if(tempDs<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt,tempDs);
+         pc.printf("\n");
+         
+        if(m<=16){
+        strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt,tempDs,m); 
+         
+         pc.printf("\n");     
+          
+        if(tempExt<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt,tempDs,m,tempExt);
+        pc.printf("\n");
+        
+        if(tempInt<=16){
+           strcat(donnee,"0%x ");
+        }else {strcat(donnee,"%2x ");}
+         pc.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
+         pc.printf("\n");
+         sigfox.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
+         pc.printf("\n");
+         pc.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
+         
+         // pc.printf(donnee);
+          pc.printf("TEST6\r\n");
+          led0 = 1;
+          led1 = 1;
+          wait (10);
+          //wait(0.1); // wait 100 ms
+        
+                 //  LEDs OFF
+                   led0 = 0;
+                   led1 = 0;
       
       
-      wait(1);
+                // wait(660);
+        
+           
     
 
     }
-       //programme main de lecture DHT22
+     
     
 
     
 
-    
-/*    while (1) {
-        
-       
-    }
-  */  
-    //Fin du programme de lecture DHT22
+
     
  
 }