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