Send DHT11 & SHT10 sensors data through LoRa SX1272 board.

Dependencies:   SX1272Lib mbed

Fork of SX1272PingPong by Semtech

Revision:
18:1ee53f77b90d
Parent:
17:cd37e3e63cec
Child:
19:e50e4a513de1
--- a/main.cpp	Mon Mar 13 16:00:29 2017 +0000
+++ b/main.cpp	Mon Mar 13 17:23:03 2017 +0000
@@ -1,7 +1,10 @@
 #include "mbed.h"
 #include "main.h"
+// SX1272 Lib
 #include "sx1272-hal.h"
 #include "debug.h"
+// DHT11 Lib (air temperature and humidity)
+#include "DHT11.h"
 
 /* Set this flag to '1' to display debug messages on the console */
 #define DEBUG_MESSAGE   1
@@ -43,7 +46,7 @@
  */
 SX1272MB2xAS Radio( NULL );
 
-const uint8_t msg[] = "Temp=184.26 \r\nHumi=423.99 \r\n";
+uint8_t msg[BUFFER_SIZE];
 
 uint16_t BufferSize = BUFFER_SIZE;
 uint8_t Buffer[BUFFER_SIZE];
@@ -53,6 +56,10 @@
 
 int msglen = 0;
 
+// Air temperature and humidity sensor
+DHT11 d(D6);
+int DHT11_state;
+
 int main()
 {
     uint8_t i;
@@ -88,7 +95,14 @@
 
     led = 0;
 
-    while( 1 ) {
+    while(1) {
+        // Retrieving sensors data
+        DHT11_state = d.readData();
+        if (DHT11_state == DHT11::OK) {
+            sprintf((char*) msg, "Temp=%d \r\nHumi=%d \r\n", d.readTemperature(), d.readHumidity());
+        }
+        
+        // Sending a new packet
         debug("\r\n========\r\nSending a new Packet\r\n========\r\n");
         strcpy( ( char* )Buffer, ( char* ) msg );
         // We fill the buffer with numbers for the payload
@@ -96,9 +110,13 @@
         for( i = msglen; i < BufferSize; i++ ) {
             Buffer[i] = i - msglen;
         }
-        wait_ms( 10 );
-        Radio.Send( Buffer, BufferSize );
+        wait_ms(10);
+        Radio.Send(Buffer, BufferSize);
+        
+        // Reversing the led state
         led = 1-led;
+        
+        // wait 3 seconds before resend data
         wait(3);
     }
 }