Send DHT11 & SHT10 sensors data through LoRa SX1272 board.
Fork of SX1272PingPong by
Diff: main.cpp
- Revision:
- 21:307b5bf141cb
- Parent:
- 19:e50e4a513de1
- Child:
- 22:6d4464ff7b32
--- a/main.cpp Tue Mar 28 12:20:45 2017 +0000 +++ b/main.cpp Tue Mar 28 14:42:35 2017 +0000 @@ -1,18 +1,11 @@ #include "mbed.h" #include "main.h" -// SX1272 Lib #include "sx1272-hal.h" #include "debug.h" -// DHT11 Lib (air temperature and humidity) -#include "DHT11.h" -// SHT10 (soil temperature and humidity) -#include "SHTx/sht15.hpp" /* Set this flag to '1' to display debug messages on the console */ #define DEBUG_MESSAGE 1 -/* DELAY between two transmission (in seconds) */ -#define DELAY 1800 #define RF_FREQUENCY 868000000 // Hz #define TX_OUTPUT_POWER 14 // 14 dBm @@ -50,7 +43,7 @@ */ SX1272MB2xAS Radio( NULL ); -uint8_t msg[BUFFER_SIZE]; +const uint8_t msg[] = "Temp=184.26 \r\nHumi=423.99 \r\n"; uint16_t BufferSize = BUFFER_SIZE; uint8_t Buffer[BUFFER_SIZE]; @@ -60,18 +53,11 @@ int msglen = 0; -// Air temperature and humidity sensor -DHT11 airSensor(D6); -int DHT11_state; - -// Soil temperature and humidity sensor -SHTx::SHT15 soilSensor(D9, D8); - int main() { uint8_t i; - debug( "\n\n\r iGreenhouse Application - Transmitter \n\n\r" ); + debug( "\n\n\r iGreenhouse Application - Transmitter\n\n\r" ); // Initialize Radio driver RadioEvents.TxDone = OnTxDone; @@ -97,26 +83,12 @@ LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, LORA_IQ_INVERSION_ON, 2000000 ); - - // Soil sensor configuration - soilSensor.setOTPReload(false); - soilSensor.setResolution(true); - soilSensor.setScale(false); debug_if( DEBUG_MESSAGE, "Starting sending loop\r\n" ); led = 0; - while(1) { - // Retrieving sensors data - DHT11_state = airSensor.readData(); - if (DHT11_state == DHT11::OK) { - sprintf((char*) msg, "TempA=%d \r\nHumiA=%d \r\nTempS=%3.2f \r\nHumiS=%3.2f \r\n", airSensor.readTemperature(), airSensor.readHumidity(), soilSensor.getTemperature(), soilSensor.getHumidity()); - } else { - sprintf((char*) msg, "TempS=%3.2f \r\nHumiS=%3.2f \r\n", soilSensor.getTemperature(), soilSensor.getHumidity()); - } - - // Sending a new packet + while( 1 ) { 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 @@ -124,14 +96,10 @@ for( i = msglen; i < BufferSize; i++ ) { Buffer[i] = i - msglen; } - wait_ms(10); - Radio.Send(Buffer, BufferSize); - - // Reversing the led state + wait_ms( 10 ); + Radio.Send( Buffer, BufferSize ); led = 1-led; - - // wait DELAY seconds before resend data - wait(DELAY); + wait(3); } } @@ -146,4 +114,3 @@ Radio.Sleep( ); debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" ); } -