![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ruche
Dependencies: ATParser DHT22 SerialGPS Sigfox mbed
Fork of Nucleo_SerialGPS_to_PC by
main.cpp@1:297aba9a5830, 2018-01-17 (annotated)
- Committer:
- dahmani_belkacem
- Date:
- Wed Jan 17 14:34:05 2018 +0000
- Revision:
- 1:297aba9a5830
- Parent:
- 0:e0a6c18ea0fb
- Child:
- 2:f760e8507750
publier
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
veyselka | 0:e0a6c18ea0fb | 1 | #include "mbed.h" |
veyselka | 0:e0a6c18ea0fb | 2 | #include "SerialGPS.h" |
dahmani_belkacem | 1:297aba9a5830 | 3 | #include "DHT22.h" |
dahmani_belkacem | 1:297aba9a5830 | 4 | #include "Sigfox.h" |
dahmani_belkacem | 1:297aba9a5830 | 5 | #include "BufferedSerial.h" |
dahmani_belkacem | 1:297aba9a5830 | 6 | //#include "ATParser.h" |
veyselka | 0:e0a6c18ea0fb | 7 | |
veyselka | 0:e0a6c18ea0fb | 8 | |
veyselka | 0:e0a6c18ea0fb | 9 | Serial pc(USBTX, USBRX); // tx, rx |
dahmani_belkacem | 1:297aba9a5830 | 10 | SerialGPS gps(PC_10,PC_11); // tx, rx |
dahmani_belkacem | 1:297aba9a5830 | 11 | DHT22 dht22(D4);//pin pour la lecture du dht22 grove |
dahmani_belkacem | 1:297aba9a5830 | 12 | DHT22 dht22Bis(D5);//pin pour la lecture du dht22 |
dahmani_belkacem | 1:297aba9a5830 | 13 | AnalogIn IRSensor(A1);//Pin de lecture du capteur IR |
dahmani_belkacem | 1:297aba9a5830 | 14 | |
dahmani_belkacem | 1:297aba9a5830 | 15 | BufferedSerial serial = BufferedSerial(PC_10,PC_11); |
dahmani_belkacem | 1:297aba9a5830 | 16 | //ATParser at = ATParser(serial, "\r\n"); |
dahmani_belkacem | 1:297aba9a5830 | 17 | Sigfox sig(*); |
dahmani_belkacem | 1:297aba9a5830 | 18 | |
dahmani_belkacem | 1:297aba9a5830 | 19 | //Sigfox(at(&at)); |
veyselka | 0:e0a6c18ea0fb | 20 | |
veyselka | 0:e0a6c18ea0fb | 21 | |
dahmani_belkacem | 1:297aba9a5830 | 22 | //programme du gps |
veyselka | 0:e0a6c18ea0fb | 23 | |
veyselka | 0:e0a6c18ea0fb | 24 | /** |
veyselka | 0:e0a6c18ea0fb | 25 | * A callback function for logging data. |
veyselka | 0:e0a6c18ea0fb | 26 | */ |
veyselka | 0:e0a6c18ea0fb | 27 | void cbfunc_log(char *s) { |
veyselka | 0:e0a6c18ea0fb | 28 | |
veyselka | 0:e0a6c18ea0fb | 29 | } |
veyselka | 0:e0a6c18ea0fb | 30 | |
veyselka | 0:e0a6c18ea0fb | 31 | /** |
veyselka | 0:e0a6c18ea0fb | 32 | * A callback function for GGA. |
veyselka | 0:e0a6c18ea0fb | 33 | * |
veyselka | 0:e0a6c18ea0fb | 34 | * GGA - Global Positioning System Fixed Data. |
veyselka | 0:e0a6c18ea0fb | 35 | */ |
veyselka | 0:e0a6c18ea0fb | 36 | void cbfunc_gga(SerialGPS::gps_gga_t *p) { |
veyselka | 0:e0a6c18ea0fb | 37 | |
dahmani_belkacem | 1:297aba9a5830 | 38 | pc.printf("%02d:%02d:%02d(P%d,S%d)\r\n", p->hour, p->min, p->sec, p->position_fix, p->satellites_used); |
dahmani_belkacem | 1:297aba9a5830 | 39 | |
dahmani_belkacem | 1:297aba9a5830 | 40 | // pc.printf("latitude %c=%10.4f\r\n", p->ns, p->latitude); |
veyselka | 0:e0a6c18ea0fb | 41 | |
dahmani_belkacem | 1:297aba9a5830 | 42 | // pc.printf("longitude %c=%10.4f\r\n", p->ew, p->longitude); |
dahmani_belkacem | 1:297aba9a5830 | 43 | double a = p->latitude; |
dahmani_belkacem | 1:297aba9a5830 | 44 | double b = p->longitude; |
dahmani_belkacem | 1:297aba9a5830 | 45 | pc.printf("latitude %10.4f\r\n", a); |
dahmani_belkacem | 1:297aba9a5830 | 46 | pc.printf("longitude %10.4f\r\n", b); |
veyselka | 0:e0a6c18ea0fb | 47 | } |
veyselka | 0:e0a6c18ea0fb | 48 | |
veyselka | 0:e0a6c18ea0fb | 49 | /** |
veyselka | 0:e0a6c18ea0fb | 50 | * A callback function for GSA. |
veyselka | 0:e0a6c18ea0fb | 51 | * |
veyselka | 0:e0a6c18ea0fb | 52 | * GSA - GNSS DOP and Active Satellites. |
veyselka | 0:e0a6c18ea0fb | 53 | */ |
veyselka | 0:e0a6c18ea0fb | 54 | void cbfunc_gsa(SerialGPS::gps_gsa_t *p) { |
veyselka | 0:e0a6c18ea0fb | 55 | |
dahmani_belkacem | 1:297aba9a5830 | 56 | pc.printf("SEL:%c FIX:%d\r\n", p->selmode, p->fix); |
veyselka | 0:e0a6c18ea0fb | 57 | |
veyselka | 0:e0a6c18ea0fb | 58 | } |
veyselka | 0:e0a6c18ea0fb | 59 | |
veyselka | 0:e0a6c18ea0fb | 60 | /** |
veyselka | 0:e0a6c18ea0fb | 61 | * A callback function for GSV. |
veyselka | 0:e0a6c18ea0fb | 62 | * |
veyselka | 0:e0a6c18ea0fb | 63 | * GSV - GNSS Satellites in View. |
veyselka | 0:e0a6c18ea0fb | 64 | */ |
veyselka | 0:e0a6c18ea0fb | 65 | void cbfunc_gsv(SerialGPS::gps_gsv_t *p) { |
veyselka | 0:e0a6c18ea0fb | 66 | |
dahmani_belkacem | 1:297aba9a5830 | 67 | pc.printf("Satellites:%2d\r\n", p->satcnt); |
veyselka | 0:e0a6c18ea0fb | 68 | |
veyselka | 0:e0a6c18ea0fb | 69 | } |
veyselka | 0:e0a6c18ea0fb | 70 | |
veyselka | 0:e0a6c18ea0fb | 71 | /** |
veyselka | 0:e0a6c18ea0fb | 72 | * A callback function for RMC. |
veyselka | 0:e0a6c18ea0fb | 73 | * |
veyselka | 0:e0a6c18ea0fb | 74 | * RMC - Recommended Minimum Specific GNSS Data. |
veyselka | 0:e0a6c18ea0fb | 75 | */ |
veyselka | 0:e0a6c18ea0fb | 76 | void cbfunc_rmc(SerialGPS::gps_rmc_t *p) { |
veyselka | 0:e0a6c18ea0fb | 77 | |
dahmani_belkacem | 1:297aba9a5830 | 78 | pc.printf("%02d:%02d:%02d(%c)\r\n", p->hour, p->min, p->sec, p->status); |
veyselka | 0:e0a6c18ea0fb | 79 | |
veyselka | 0:e0a6c18ea0fb | 80 | } |
veyselka | 0:e0a6c18ea0fb | 81 | |
veyselka | 0:e0a6c18ea0fb | 82 | /** |
veyselka | 0:e0a6c18ea0fb | 83 | * Entry point. |
veyselka | 0:e0a6c18ea0fb | 84 | */ |
veyselka | 0:e0a6c18ea0fb | 85 | |
dahmani_belkacem | 1:297aba9a5830 | 86 | //fin du prgramme de lecture GPS |
veyselka | 0:e0a6c18ea0fb | 87 | |
dahmani_belkacem | 1:297aba9a5830 | 88 | //Fonction lecture des donneé sigfox |
veyselka | 0:e0a6c18ea0fb | 89 | |
veyselka | 0:e0a6c18ea0fb | 90 | |
veyselka | 0:e0a6c18ea0fb | 91 | int main() { |
dahmani_belkacem | 1:297aba9a5830 | 92 | //programme main du gps |
dahmani_belkacem | 1:297aba9a5830 | 93 | //programme main de lecture DHT22 |
dahmani_belkacem | 1:297aba9a5830 | 94 | |
dahmani_belkacem | 1:297aba9a5830 | 95 | int hum; |
dahmani_belkacem | 1:297aba9a5830 | 96 | int temp; |
dahmani_belkacem | 1:297aba9a5830 | 97 | int hum1; |
dahmani_belkacem | 1:297aba9a5830 | 98 | int temp1; |
veyselka | 0:e0a6c18ea0fb | 99 | |
veyselka | 0:e0a6c18ea0fb | 100 | pc.baud(9600); |
dahmani_belkacem | 1:297aba9a5830 | 101 | |
veyselka | 0:e0a6c18ea0fb | 102 | |
veyselka | 0:e0a6c18ea0fb | 103 | pc.printf("TEST\r\n"); |
veyselka | 0:e0a6c18ea0fb | 104 | wait(0.5); |
dahmani_belkacem | 1:297aba9a5830 | 105 | pc.printf("TEST1\r\n"); |
veyselka | 0:e0a6c18ea0fb | 106 | |
veyselka | 0:e0a6c18ea0fb | 107 | SerialGPS::gps_callback_t cb; |
veyselka | 0:e0a6c18ea0fb | 108 | cb.cbfunc_log = cbfunc_log; |
dahmani_belkacem | 1:297aba9a5830 | 109 | pc.printf("TEST2\r\n"); |
dahmani_belkacem | 1:297aba9a5830 | 110 | |
veyselka | 0:e0a6c18ea0fb | 111 | cb.cbfunc_gsa = cbfunc_gsa; |
veyselka | 0:e0a6c18ea0fb | 112 | cb.cbfunc_gsv = cbfunc_gsv; |
veyselka | 0:e0a6c18ea0fb | 113 | cb.cbfunc_rmc = cbfunc_rmc; |
veyselka | 0:e0a6c18ea0fb | 114 | gps.attach(&cb); |
dahmani_belkacem | 1:297aba9a5830 | 115 | pc.printf("TEST3\r\n"); |
dahmani_belkacem | 1:297aba9a5830 | 116 | |
veyselka | 0:e0a6c18ea0fb | 117 | while(1) { |
veyselka | 0:e0a6c18ea0fb | 118 | |
dahmani_belkacem | 1:297aba9a5830 | 119 | wait(1); |
dahmani_belkacem | 1:297aba9a5830 | 120 | gps.processing(); |
dahmani_belkacem | 1:297aba9a5830 | 121 | pc.printf("TEST4\r\n"); |
dahmani_belkacem | 1:297aba9a5830 | 122 | //lecture du DHT22 grove |
dahmani_belkacem | 1:297aba9a5830 | 123 | |
dahmani_belkacem | 1:297aba9a5830 | 124 | dht22.sample() ; |
dahmani_belkacem | 1:297aba9a5830 | 125 | hum=dht22.getHumidity()/10.0; |
dahmani_belkacem | 1:297aba9a5830 | 126 | temp=dht22.getTemperature()/10.0; |
dahmani_belkacem | 1:297aba9a5830 | 127 | printf("temperature: %d, humidity: %d\n\r",temp,hum); |
dahmani_belkacem | 1:297aba9a5830 | 128 | |
dahmani_belkacem | 1:297aba9a5830 | 129 | //lecture du DHT22 simple |
dahmani_belkacem | 1:297aba9a5830 | 130 | |
dahmani_belkacem | 1:297aba9a5830 | 131 | dht22Bis.sample() ; |
dahmani_belkacem | 1:297aba9a5830 | 132 | hum1=dht22Bis.getHumidity()/10.0; |
dahmani_belkacem | 1:297aba9a5830 | 133 | temp1=dht22Bis.getTemperature()/10.0; |
dahmani_belkacem | 1:297aba9a5830 | 134 | printf("temperature1: %3d, humidity1: %3d\n\r",temp1,hum1); |
dahmani_belkacem | 1:297aba9a5830 | 135 | |
dahmani_belkacem | 1:297aba9a5830 | 136 | //mesure de la distance |
dahmani_belkacem | 1:297aba9a5830 | 137 | |
dahmani_belkacem | 1:297aba9a5830 | 138 | //wait(2); |
dahmani_belkacem | 1:297aba9a5830 | 139 | //3.1V at 4cm to 0.3V at 30cm. |
dahmani_belkacem | 1:297aba9a5830 | 140 | float a = IRSensor;// 1=4cm 0=30cm |
dahmani_belkacem | 1:297aba9a5830 | 141 | pc.printf("IR sensor reads %2.2f\n ", a); |
dahmani_belkacem | 1:297aba9a5830 | 142 | a=1-a;// now 0=4cm and 1=30cm |
dahmani_belkacem | 1:297aba9a5830 | 143 | float b= 40+a * 260; //(a26+4); |
dahmani_belkacem | 1:297aba9a5830 | 144 | pc.printf("\rDistance is %2.2f mm \n ", b); // print and convert to distance by taking x=0->1 and 26x+4 |
dahmani_belkacem | 1:297aba9a5830 | 145 | float x = 200 - b; |
dahmani_belkacem | 1:297aba9a5830 | 146 | float f = 2.913*x; |
dahmani_belkacem | 1:297aba9a5830 | 147 | int m= 1000*(f/(9.8)); |
dahmani_belkacem | 1:297aba9a5830 | 148 | pc.printf("\la masse de la ruche est egale a %2.2f g \n ",m); |
dahmani_belkacem | 1:297aba9a5830 | 149 | |
dahmani_belkacem | 1:297aba9a5830 | 150 | sig->send(""+m); |
dahmani_belkacem | 1:297aba9a5830 | 151 | |
dahmani_belkacem | 1:297aba9a5830 | 152 | |
dahmani_belkacem | 1:297aba9a5830 | 153 | wait(1); |
dahmani_belkacem | 1:297aba9a5830 | 154 | |
veyselka | 0:e0a6c18ea0fb | 155 | |
veyselka | 0:e0a6c18ea0fb | 156 | } |
dahmani_belkacem | 1:297aba9a5830 | 157 | //programme main de lecture DHT22 |
dahmani_belkacem | 1:297aba9a5830 | 158 | |
dahmani_belkacem | 1:297aba9a5830 | 159 | |
dahmani_belkacem | 1:297aba9a5830 | 160 | |
dahmani_belkacem | 1:297aba9a5830 | 161 | |
dahmani_belkacem | 1:297aba9a5830 | 162 | |
dahmani_belkacem | 1:297aba9a5830 | 163 | /* while (1) { |
dahmani_belkacem | 1:297aba9a5830 | 164 | |
dahmani_belkacem | 1:297aba9a5830 | 165 | |
dahmani_belkacem | 1:297aba9a5830 | 166 | } |
dahmani_belkacem | 1:297aba9a5830 | 167 | */ |
dahmani_belkacem | 1:297aba9a5830 | 168 | //Fin du programme de lecture DHT22 |
dahmani_belkacem | 1:297aba9a5830 | 169 | |
dahmani_belkacem | 1:297aba9a5830 | 170 | |
veyselka | 0:e0a6c18ea0fb | 171 | } |
veyselka | 0:e0a6c18ea0fb | 172 | |
dahmani_belkacem | 1:297aba9a5830 | 173 | |
dahmani_belkacem | 1:297aba9a5830 | 174 | |
dahmani_belkacem | 1:297aba9a5830 | 175 |