![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tp_iot
Dependencies: mbed DHT HC_SR04_Ultrasonic_Library
Diff: main.cpp
- Revision:
- 6:cd3b177a3e33
- Parent:
- 5:0186f7e2053e
diff -r 0186f7e2053e -r cd3b177a3e33 main.cpp --- a/main.cpp Wed May 24 15:43:22 2017 +0000 +++ b/main.cpp Mon Jun 05 22:53:33 2017 +0000 @@ -1,41 +1,47 @@ #include "mbed.h" #include "Serial.h" #include <string> +#include "DHT/DHT.h" +#include "HC_SR04_Ultrasonic_Library/ultrasonic.h" - // WE USE PA_2 = TX } CN9 - // PA_3 = RX } CN9 - - AnalogIn analog_value(A0); - + DigitalOut led(LED2); -int main() { - float meas; - Serial serial_td1208(PA_2, PA_3); +int main() +{ + Serial serial_td1208(PA_0, PA_1); + DHT dht11(PA_4, DHT11); + ultrasonic usensor(PA_8, PA_9, 1000, 1); - //std::string init("AT"); - - //std::string query("AT$SS=00 12 FF 42/r/n"); - - char* query = "AT$SS=0012FF42"; - + //for ultrasonic we use D8,D7 + serial_td1208.baud(9600); serial_td1208.format(); //serial_td1208.printf("%s", init); - - + + int temperature = 0, humidity = 0, distance = 0, lightlevel = 0; printf("\nAnalogIn example\n"); led = 1; - while(1) { if (led == 1) led = 0; else led = 1; - - serial_td1208.printf("AT$SS=0012FF42"); - wait(10); // 750 ms +//TODO: each 10 second we send the value of the DHT11 +// use %08x + if (!dht11.readData()) { + temperature = static_cast<int>(dht11.ReadTemperature(CELCIUS)); + humidity = static_cast<int>(dht11.ReadHumidity()); + } + + distance = usensor.getCurrentDistance(); + + serial_td1208.printf("AT$SS=%02x%02x%02x%02x\r\n", temperature, humidity, distance, lightlevel); + usensor.startUpdates(); + wait(10); + usensor.pauseUpdates(); + } }