Belkacem DAHMANI / Mbed 2 deprecated Final

Dependencies:   ATParser DHT22 SerialGPS Sigfox mbed

Fork of Nucleo_SerialGPS_to_PC by hime hime

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DHT22.h"
00003 #include "string.h"
00004 #include "DS1820.h"
00005 
00006  
00007 Serial pc(USBTX,USBRX); // tx, rx
00008 Serial sigfox(PA_9,PA_10); // tx, rx
00009 DHT22 dht22(D3);//pin pour la lecture du dht22 grove
00010 DHT22 dht22Bis(D6);//pin pour la lecture du dht22 
00011 AnalogIn IRSensor(A1);//Pin de lecture du capteur IR
00012 DigitalOut led0(LED1);
00013 DigitalOut led1(LED2);
00014 double longi;
00015 double lat;
00016 const int MAX_PROBES = 1;
00017 DS1820 probe[1] = {A4};
00018 
00019 
00020 
00021 //Fonction lecture des donneé sigfox
00022 
00023  
00024 int main() {
00025   
00026    int humExt;  // humidité intérieur dst22
00027    int tempExt; // température extérieur dst22
00028    int humInt;  // humidité intérieur dst22
00029    int tempInt; // température intérieur dst22
00030    int i;
00031    int devices_found=0;
00032    int tempDs; //tempérarure de la sonde Ds18B20;
00033    
00034     pc.baud(9600);
00035     sigfox.baud(9600);
00036     
00037     pc.printf("TEST\r\n");
00038     wait(0.5);
00039 
00040     //partie declarative DS18B20
00041     pc.printf("Started\r\n");
00042     pc.printf("search_ROM_setup\r\n");
00043     probe[0].search_ROM_setup();
00044     pc.printf("search_ROM\r\n");
00045  
00046      while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1)
00047           devices_found++;
00048     
00049     // If maximum number of probes are found,
00050     // bump the counter to include the last array entry
00051     if (probe[devices_found].ROM[0] != 0xFF)
00052         devices_found++;
00053     pc.printf("devices found:%d\r\n",devices_found);
00054     
00055         //Fin de la partie declarative DS18B20   
00056         
00057     while(1) {
00058      char donnee[] = "AT$SF=";
00059      wait(1);
00060      pc.printf("TEST4\r\n");
00061      
00062    //  lecture du DHT22 grove
00063             
00064         dht22.sample() ;
00065         humExt=dht22.getHumidity()/10.0;
00066         tempExt=dht22.getTemperature()/10.0;
00067         pc.printf("temperature: %d humidity: %d\n\r",tempExt,humExt);
00068         
00069         //lecture du DHT22 simple Intérieure 
00070       
00071         dht22Bis.sample(); 
00072         humInt=dht22Bis.getHumidity()/10.0;
00073         tempInt=dht22Bis.getTemperature()/10.0;
00074         pc.printf("temperature1: %d humidity1: %d\n\r",tempInt,humInt);
00075       
00076         //mesure de la distance 
00077       
00078              //3.1V at 4cm to 0.3V at 30cm. 
00079        float a = IRSensor;// 1=4cm 0=30cm
00080        //pc.printf("IR sensor reads %2.2f\n ", a);
00081        float v=2.8*a;
00082       //  pc.printf("\r ANALOGIN %2.2f v \n ", v);
00083        float l= 10*((12/v)-0.42);
00084      
00085        pc.printf("\rDistance is %2.2f mm \n ", l); // print and convert to distance by taking x=0->1 and 26*x+4
00086        float x=193-l;//218
00087        float f= 4*(2.913*x);//2.5
00088        int m = (f/(9.8));
00089        pc.printf("\la masse de la ruche est égale à %d Kg \n ",m); 
00090        
00091        //mesure de la température avec DS18B20
00092 
00093         probe[0].convert_temperature(DS1820::all_devices);
00094         for (i=0; i<devices_found; i++) {
00095             tempDs = probe[i].temperature('c');
00096             pc.printf("Device[%d]: %d \r\n",i,tempDs);
00097         }
00098        
00099        //fin de mesure de temperature avec DS18B20
00100     
00101       
00102         pc.printf("TEST5\r\n");
00103 
00104     
00105         
00106         
00107         if(humExt<=16){
00108            strcat(donnee,"0%x");
00109         }else {strcat(donnee,"%2x");}
00110         pc.printf(donnee,humExt);
00111          pc.printf("\n");
00112          
00113        if(humInt<=16){
00114            strcat(donnee,"0%x");
00115         }else {strcat(donnee,"%2x");}
00116         pc.printf(donnee,humExt,humInt);
00117          pc.printf("\n");
00118          
00119         if(tempDs<=16){
00120            strcat(donnee,"0%x");
00121         }else {strcat(donnee,"%2x");}
00122         pc.printf(donnee,humExt,humInt,tempDs);
00123          pc.printf("\n");
00124          
00125         if(m<=16){
00126         strcat(donnee,"0%x");
00127         }else {strcat(donnee,"%2x");}
00128         pc.printf(donnee,humExt,humInt,tempDs,m); 
00129          
00130          pc.printf("\n");     
00131           
00132         if(tempExt<=16){
00133            strcat(donnee,"0%x");
00134         }else {strcat(donnee,"%2x");}
00135         pc.printf(donnee,humExt,humInt,tempDs,m,tempExt);
00136         pc.printf("\n");
00137         
00138         if(tempInt<=16){
00139            strcat(donnee,"0%x ");
00140         }else {strcat(donnee,"%2x ");}
00141          pc.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
00142          pc.printf("\n");
00143          sigfox.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
00144          pc.printf("\n");
00145          pc.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
00146          
00147          // pc.printf(donnee);
00148           pc.printf("TEST6\r\n");
00149           led0 = 1;
00150           led1 = 1;
00151           wait (10);
00152           //wait(0.1); // wait 100 ms
00153         
00154                  //  LEDs OFF
00155                    led0 = 0;
00156                    led1 = 0;
00157       
00158       
00159                 // wait(660);
00160         
00161            
00162     
00163 
00164     }
00165      
00166     
00167 
00168     
00169 
00170 
00171     
00172  
00173 }
00174 
00175 
00176 
00177