St-connect
Dependencies: HP206C mbed WakeUp QMC5883L DHT22 DS1820
- ST Conect Project Look how we did it : [Hackster](https://www.hackster.io/monginjulien/st-connect-dike-monitoring-534a32)
Diff: main.cpp
- Revision:
- 7:036d9a2accff
- Parent:
- 6:865aa63f2106
- Child:
- 8:c4801ce16934
--- a/main.cpp Mon Oct 22 09:22:05 2018 +0000 +++ b/main.cpp Tue Nov 06 13:22:55 2018 +0000 @@ -4,22 +4,42 @@ #include "HP20x_dev.h" #include "DS1820.h" #include "QMC5883L.h" +#define ENABLE_BAROMETER 1 +#define ENABLE_MAGNETOMETER 1 +#define ENABLE_GROUND_TEMPERATURE 1 +#define ENABLE_GROUND_HUMIDITY 1 +#define ENABLE_DHT22 1 #define MESSAGE_SIZE 32 #define TRAME_SIZE 25 -#define DEBUG 1 +#define DEBUG // #define SEND_SIGFOX 1 #ifdef DEBUG Serial pc(USBTX, USBRX); #endif -HP20x_dev capt_barometer(D4, D5); -QMC5883L capt_magnetometer(D4, D5); -DS1820 capt_ground_temperature(A1); -AnalogIn capt_ground_humidity(A0); // SEN0 -DHT22 capt_thermo_air_humidity(D3); // DHT22 +#ifdef ENABLE_BAROMETER + HP20x_dev capt_barometer(D4, D5); +#endif + +#ifdef ENABLE_MAGNETOMETER + QMC5883L capt_magnetometer(D4, D5); +#endif + +#ifdef ENABLE_GROUND_TEMPERATURE + DS1820 capt_ground_temperature(A1); +#endif + +#ifdef ENABLE_GROUND_HUMIDITY + AnalogIn capt_ground_humidity(A0); // SEN0 +#endif + +#ifdef ENABLE_DHT22 + DHT22 capt_thermo_air_humidity(D3); // DHT22 +#endif + Serial sigfox(D1, D0); char message[MESSAGE_SIZE] = "AT$SF="; @@ -107,34 +127,47 @@ int main() { sigfox.printf("\r\n"); - capt_magnetometer.init(); + #ifdef ENABLE_MAGNETOMETER + capt_magnetometer.init(); + #endif + #ifdef DEBUG pc.printf("\r\n\r\n\r\nInit...\r\n"); #endif while(1) { - // Temperature Sol - capt_ground_temperature.convertTemperature(true, DS1820::all_devices); - ground_temperature = capt_ground_temperature.temperature(); + #ifdef ENABLE_GROUND_TEMPERATURE + // Temperature Sol + capt_ground_temperature.convertTemperature(true, DS1820::all_devices); + ground_temperature = capt_ground_temperature.temperature(); + #endif - // Humidite Sol - ground_humidity = capt_ground_humidity.read() * 100; + #ifdef ENABLE_GROUND_HUMIDITY + // Humidite Sol + ground_humidity = capt_ground_humidity.read() * 100; + #endif - // Temperature et Humidite Air - if(capt_thermo_air_humidity.sample()) - { - air_temperature = capt_thermo_air_humidity.getTemperature() / 10.0; - air_humidity = capt_thermo_air_humidity.getHumidity() / 10.0; - } + #ifdef ENABLE_DHT22 + // Temperature et Humidite Air + if(capt_thermo_air_humidity.sample()) + { + air_temperature = capt_thermo_air_humidity.getTemperature() / 10.0; + air_humidity = capt_thermo_air_humidity.getHumidity() / 10.0; + } + #endif - // Pression - if(capt_barometer.isAvailable()) - pressure = capt_barometer.ReadPressure(); + #ifdef ENABLE_BAROMETER + // Pression + if(capt_barometer.isAvailable()) + pressure = capt_barometer.ReadPressure(); + #endif - // Magnetometre - magnetic_field[0] = capt_magnetometer.getMagXvalue(); - magnetic_field[1] = capt_magnetometer.getMagYvalue(); - magnetic_field[2] = capt_magnetometer.getMagZvalue(); + #ifdef ENABLE_MAGNETOMETER + // Magnetometre + magnetic_field[0] = capt_magnetometer.getMagXvalue(); + magnetic_field[1] = capt_magnetometer.getMagYvalue(); + magnetic_field[2] = capt_magnetometer.getMagZvalue(); + #endif // Affichage pour debug #ifdef DEBUG @@ -164,6 +197,6 @@ WakeUp::attach(&mycallback); deepsleep(); */ - wait(5); + wait(1000); } } \ No newline at end of file