Temperature reading demo
Dependencies: DHT libmDot mbed-rtos mbed
Diff: main.cpp
- Revision:
- 8:8070e9d660e4
- Parent:
- 7:2a704d1a30e1
- Child:
- 9:086351e54b57
diff -r 2a704d1a30e1 -r 8070e9d660e4 main.cpp --- a/main.cpp Wed Oct 28 11:06:03 2015 +0000 +++ b/main.cpp Tue Nov 10 21:46:38 2015 +0000 @@ -22,20 +22,22 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) -// these options must match the settings on your Conduit in -// /var/config/lora/lora-network-server.conf -//static std::string config_network_name = "ThingInnovations"; -//static std::string config_network_pass = "donkey123"; -// +// Values as used by The Things Network //const uint8_t AppKey[16]={0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C}; // Application session key uint8_t AppSKey[16]= {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C}; // Network session key uint8_t NwkSKey[16]= {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C}; -// Dev addr -//uint8_t NodeAddr[4]= {0x23,0x05,0x19,0x67}; + // Network Address -uint8_t NetworkAddr[4]= {0x23,0x05,0x19,0x67}; +//uint8_t NetworkAddr[4]= {0x02,0x01,0x2A,0x00}; // Dev board +uint8_t NetworkAddr[4]= {0x02,0x01,0x2A,0x01}; // Temperature sensor/OxFloodNet sensor + + +// Some defines for the LoRa configuration +#define LORA_SF mDot::SF_12 +#define LORA_ACK 0 +#define LORA_TXPOWER 14 // Ignoring sub band for EU modules. //static uint8_t config_frequency_sub_band = 1; @@ -44,7 +46,7 @@ //#define ACTIVITY_LED PA_0 // DS18B20 OneWire pin -// D13 on Dev Board, pin 18 on mDot +// D13 on Dev Board, pin 18 on mDot, Compatible with Oxford Flood Network PCB temperature sensor. #define DATA_PIN PA_5 // A0 on Dev Board, pin 20 on mDot //#define DATA_PIN PB_1 @@ -114,8 +116,8 @@ // } // Set byte order - AEP less than 1.0.30 -// dot->setJoinByteOrder(mDot::MSB); - dot->setJoinByteOrder(mDot::LSB); +// dot->setJoinByteOrder(mDot::LSB); + dot->setJoinByteOrder(mDot::MSB); // This is default for > 1.0.30 Conduit // dot->setCrc(true); @@ -133,13 +135,12 @@ // Set Spreading Factor, higher is lower data rate, smaller packets but longer range // Lower is higher data rate, larger packets and shorter range. logInfo("Set SF"); -// if((ret = dot->setTxDataRate( mDot::SF_9 )) != mDot::MDOT_OK) { - if((ret = dot->setTxDataRate( mDot::SF_12 )) != mDot::MDOT_OK) { + if((ret = dot->setTxDataRate( LORA_SF )) != mDot::MDOT_OK) { logError("Failed to set SF %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } logInfo("Set TxPower"); - if((ret = dot->setTxPower( 14 )) != mDot::MDOT_OK) { + if((ret = dot->setTxPower( LORA_TXPOWER )) != mDot::MDOT_OK) { logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } @@ -155,7 +156,7 @@ logInfo("Set Ack"); // 1 retries on Ack, 0 to disable - if((ret = dot->setAck( 0 )) != mDot::MDOT_OK) { + if((ret = dot->setAck( LORA_ACK)) != mDot::MDOT_OK) { logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } @@ -270,14 +271,13 @@ logInfo("send data: %s", Text::bin2hexString(send_data).c_str()); } - // Should sleep here and wakeup after a set interval. - uint32_t sleep_time = MAX((dot->getNextTxMs() / 1000), 60); + // Should sleep here and wakeup after a set 10 minute interval. + uint32_t sleep_time = MAX((dot->getNextTxMs() / 1000), 600); logInfo("going to sleep for %d seconds", sleep_time); // go to sleep and wake up automatically sleep_time seconds later -// dot->sleep(sleep_time, mDot::RTC_ALARM); - - wait_ms(sleep_time * 1000); + dot->sleep(sleep_time, mDot::RTC_ALARM); +// wait_ms(sleep_time * 1000); } return 0;