supprimer les warnings
Dependencies: mbed projet_embarque WakeUp SigfoxToiture DHT DS1820
main.cpp@5:a5a213701cd1, 2019-10-15 (annotated)
- Committer:
- 3874313
- Date:
- Tue Oct 15 15:02:36 2019 +0000
- Revision:
- 5:a5a213701cd1
- Parent:
- 4:54e0220b3d83
fin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
liuyingshan | 0:8fc2f1479292 | 1 | #include"mbed.h" |
liuyingshan | 0:8fc2f1479292 | 2 | #include"DS1820.h" |
liuyingshan | 0:8fc2f1479292 | 3 | #include"DHT.h" |
liuyingshan | 0:8fc2f1479292 | 4 | #include "TCS34725.h" |
liuyingshan | 0:8fc2f1479292 | 5 | #include "Sigfox.h" |
3874313 | 3:6af60ea9a240 | 6 | #include "WakeUp.h" |
liuyingshan | 0:8fc2f1479292 | 7 | #include <math.h> |
liuyingshan | 0:8fc2f1479292 | 8 | |
liuyingshan | 0:8fc2f1479292 | 9 | #define GROVE_MOIST_MIN 0 |
liuyingshan | 0:8fc2f1479292 | 10 | #define GROVE_MOIST_MAX 0.55 |
3874313 | 3:6af60ea9a240 | 11 | #define LOG_RANGE 5.0f |
liuyingshan | 0:8fc2f1479292 | 12 | |
liuyingshan | 0:8fc2f1479292 | 13 | float Temp_Sol; |
liuyingshan | 0:8fc2f1479292 | 14 | float Temp_Air; |
liuyingshan | 0:8fc2f1479292 | 15 | float Humi_Air; |
liuyingshan | 0:8fc2f1479292 | 16 | float Humi_Sol; |
liuyingshan | 0:8fc2f1479292 | 17 | float Lumiere; |
liuyingshan | 0:8fc2f1479292 | 18 | uint16_t r; |
liuyingshan | 0:8fc2f1479292 | 19 | uint16_t g; |
liuyingshan | 0:8fc2f1479292 | 20 | uint16_t b; |
liuyingshan | 0:8fc2f1479292 | 21 | uint16_t c; |
liuyingshan | 0:8fc2f1479292 | 22 | |
liuyingshan | 0:8fc2f1479292 | 23 | DHT dht22(D6,DHT22);//pin,type |
liuyingshan | 0:8fc2f1479292 | 24 | DS1820 ds1820(A0);//pin |
liuyingshan | 0:8fc2f1479292 | 25 | TCS34725 tcs34725(D4,D5); //I2C sda and scl |
liuyingshan | 0:8fc2f1479292 | 26 | AnalogIn humigrove(A1); |
liuyingshan | 0:8fc2f1479292 | 27 | AnalogIn lumiere(A5); |
3874313 | 5:a5a213701cd1 | 28 | AnalogIn bat(A4); |
3874313 | 2:17db0f2dea0b | 29 | DigitalOut ledTest(LED1); |
3874313 | 3:6af60ea9a240 | 30 | DigitalOut mos(D9); |
liuyingshan | 0:8fc2f1479292 | 31 | |
liuyingshan | 0:8fc2f1479292 | 32 | void ReadTempHumiAir(){ |
liuyingshan | 0:8fc2f1479292 | 33 | int err=1; |
liuyingshan | 0:8fc2f1479292 | 34 | while(err!=0){ |
liuyingshan | 0:8fc2f1479292 | 35 | err=dht22.readData(); |
3874313 | 3:6af60ea9a240 | 36 | //ledTest = 1; |
liuyingshan | 0:8fc2f1479292 | 37 | wait(1); |
liuyingshan | 0:8fc2f1479292 | 38 | } |
liuyingshan | 0:8fc2f1479292 | 39 | if(err==0){ |
liuyingshan | 0:8fc2f1479292 | 40 | Temp_Air= dht22.ReadTemperature(CELCIUS); |
liuyingshan | 0:8fc2f1479292 | 41 | Humi_Air=dht22.ReadHumidity(); |
3874313 | 3:6af60ea9a240 | 42 | //ledTest = 0; |
liuyingshan | 0:8fc2f1479292 | 43 | } |
3874313 | 2:17db0f2dea0b | 44 | |
liuyingshan | 0:8fc2f1479292 | 45 | } |
liuyingshan | 0:8fc2f1479292 | 46 | |
liuyingshan | 0:8fc2f1479292 | 47 | void ReadTempSol(){ |
liuyingshan | 0:8fc2f1479292 | 48 | if (ds1820.begin()) { |
liuyingshan | 0:8fc2f1479292 | 49 | ds1820.startConversion(); // start temperature conversion from analog to digital |
liuyingshan | 0:8fc2f1479292 | 50 | wait(1); // let DS1820 complete the temperature conversion |
liuyingshan | 0:8fc2f1479292 | 51 | Temp_Sol = ds1820.read(); |
liuyingshan | 0:8fc2f1479292 | 52 | } |
liuyingshan | 0:8fc2f1479292 | 53 | } |
liuyingshan | 0:8fc2f1479292 | 54 | |
liuyingshan | 0:8fc2f1479292 | 55 | void ReadRGBC(){ |
liuyingshan | 0:8fc2f1479292 | 56 | if(tcs34725.init(TCS34725_INTEGRATIONTIME_101MS, TCS34725_GAIN_60X)){ |
liuyingshan | 0:8fc2f1479292 | 57 | tcs34725.getColor(r,g,b,c); |
liuyingshan | 0:8fc2f1479292 | 58 | r/=256; |
liuyingshan | 0:8fc2f1479292 | 59 | g/=256; |
liuyingshan | 0:8fc2f1479292 | 60 | b/=256; |
liuyingshan | 0:8fc2f1479292 | 61 | c/=256; |
liuyingshan | 0:8fc2f1479292 | 62 | } |
liuyingshan | 0:8fc2f1479292 | 63 | } |
liuyingshan | 0:8fc2f1479292 | 64 | |
liuyingshan | 0:8fc2f1479292 | 65 | void ReadHumiSol(){ |
liuyingshan | 0:8fc2f1479292 | 66 | float grove_moist=humigrove.read(); |
liuyingshan | 0:8fc2f1479292 | 67 | Humi_Sol= ((grove_moist-GROVE_MOIST_MIN) / (GROVE_MOIST_MAX - GROVE_MOIST_MIN)) * 100; |
liuyingshan | 0:8fc2f1479292 | 68 | } |
liuyingshan | 0:8fc2f1479292 | 69 | |
liuyingshan | 0:8fc2f1479292 | 70 | void ReadLumi(){ |
3874313 | 3:6af60ea9a240 | 71 | float raw=lumiere.read(); |
3874313 | 4:54e0220b3d83 | 72 | float loglux=raw*LOG_RANGE; |
3874313 | 4:54e0220b3d83 | 73 | Lumiere=(float)(pow(10,loglux)*255.0f)/10000; |
3874313 | 3:6af60ea9a240 | 74 | //Lumiere=loglux; |
liuyingshan | 0:8fc2f1479292 | 75 | } |
liuyingshan | 0:8fc2f1479292 | 76 | |
liuyingshan | 0:8fc2f1479292 | 77 | int main(){ |
liuyingshan | 0:8fc2f1479292 | 78 | //Serial at(D1,D0); |
liuyingshan | 0:8fc2f1479292 | 79 | Sigfox sigfox(D1,D0); |
3874313 | 3:6af60ea9a240 | 80 | /*ledTest = 1; |
3874313 | 3:6af60ea9a240 | 81 | wait(20); |
3874313 | 3:6af60ea9a240 | 82 | ledTest = 0; |
3874313 | 3:6af60ea9a240 | 83 | wait(5);*/ |
3874313 | 3:6af60ea9a240 | 84 | WakeUp::calibrate(); |
3874313 | 3:6af60ea9a240 | 85 | //wait(30); |
liuyingshan | 0:8fc2f1479292 | 86 | |
liuyingshan | 0:8fc2f1479292 | 87 | while(1){ |
3874313 | 3:6af60ea9a240 | 88 | WakeUp::set(120); |
3874313 | 3:6af60ea9a240 | 89 | mos = 0; |
3874313 | 3:6af60ea9a240 | 90 | sigfox.wake(); |
3874313 | 3:6af60ea9a240 | 91 | wait(2); |
liuyingshan | 0:8fc2f1479292 | 92 | ReadTempHumiAir(); |
liuyingshan | 0:8fc2f1479292 | 93 | ReadTempSol(); |
liuyingshan | 0:8fc2f1479292 | 94 | ReadRGBC(); |
liuyingshan | 0:8fc2f1479292 | 95 | ReadHumiSol(); |
3874313 | 2:17db0f2dea0b | 96 | wait(1); |
liuyingshan | 0:8fc2f1479292 | 97 | ReadLumi(); |
liuyingshan | 0:8fc2f1479292 | 98 | wait(1); |
liuyingshan | 0:8fc2f1479292 | 99 | printf("R:%d, G:%d, B:%d\n\r", r, g, b); |
3874313 | 2:17db0f2dea0b | 100 | sigfox.send((s16)(Temp_Air*10),(u16)(Humi_Air*10),(s16)(Temp_Sol*10),(u16)(Humi_Sol*10), |
3874313 | 5:a5a213701cd1 | 101 | (u8)Lumiere,(u8)r,(u8)g,(u8)b, (u8)((float)bat*255.0f)); |
3874313 | 3:6af60ea9a240 | 102 | wait(10); |
3874313 | 3:6af60ea9a240 | 103 | mos = 1; |
3874313 | 3:6af60ea9a240 | 104 | //wait(10); |
3874313 | 3:6af60ea9a240 | 105 | sigfox.sleep(); |
3874313 | 3:6af60ea9a240 | 106 | deepsleep(); |
liuyingshan | 0:8fc2f1479292 | 107 | } |
liuyingshan | 0:8fc2f1479292 | 108 | } |