tp_iot
Dependencies: mbed DHT HC_SR04_Ultrasonic_Library
Revision 6:cd3b177a3e33, committed 2017-06-05
- Comitter:
- Cornetin
- Date:
- Mon Jun 05 22:53:33 2017 +0000
- Parent:
- 5:0186f7e2053e
- Commit message:
- Add support for HC SR04 now make it work;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Mon Jun 05 22:53:33 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/Wimpie/code/DHT/#9b5b3200688f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HC_SR04_Ultrasonic_Library.lib Mon Jun 05 22:53:33 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ejteb/code/HC_SR04_Ultrasonic_Library/#e0f9c9fb4cf3
--- 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();
+
}
}
