This program connects to the The Things Network backend in OTAA Mode. It logs sensor values from a BME 280 to the backend. Tried adding support for Grove GPS using SerialGPS library but it is not working - conflicting with mbed-rtos, so it commented. Deep Sleep for mDot implemented BUT avoiding reprogramming of the mDot config is NOT working.
Dependencies: BME280 SerialGPS libmDot mbed-rtos mbed
Diff: main.cpp
- Revision:
- 6:35f934e83c74
- Parent:
- 5:4bc6ba66f28e
- Child:
- 7:9e2454b0318a
--- a/main.cpp Thu Jul 07 01:24:10 2016 +0000 +++ b/main.cpp Fri Jul 08 03:00:43 2016 +0000 @@ -6,15 +6,13 @@ *****************************************************/ #include "mbed.h" - #include <math.h> - #include <string> #include "mDot.h" #include "MTSLog.h" #include "MTSText.h" + #include <string> + + //#include "BME280.h" //#include "SerialGPS.h" - #include "BME280.h" - - using namespace mts; @@ -64,22 +62,16 @@ //SerialGPS gps(PA_2, PA_3); //BME280 sensor(I2C_SDA, I2C_SCL) // MDot UDK - I2C_SDA and I2C_SCL connected to PC_9/PA_* -BME280 b280(PC_9, PA_8); +//BME280 b280(PC_9, PA_8); // Serial via USB for debugging only //Serial pc(USBTX,USBRX); - -// Globals -Ticker tick; -mDot* dot; - - // Function Declarations void endLessTestLoop(); void setUpLEDBlink(); void blink(); -void readandprintBME280(); +//void readandprintBME280(); void mDotConfig(); void mDotGotoDeepSleep(int seconds); void mDotConfigPrint(); @@ -87,7 +79,9 @@ void setupNetwork(); void joinNetwork(); - +// Globals +Ticker tick; +mDot* dot; /***************************************************** * MAIN @@ -96,10 +90,11 @@ // Simple Test Functions, "Hello World on UDK setUpLEDBlink(); - mDotConfig(); + //mDotConfig(); setupNetwork(); - mDotConfigPrint(); - + //mDotConfigPrint(); + //wait(15); + // joinNetwork(); endLessTestLoop(); return 0; @@ -141,9 +136,14 @@ std::vector<uint8_t> appKey; // get a mDot handle - // already done in mDotConfig - //dot = mDot::getInstance(); + dot = mDot::getInstance(); + //******************************************* + // configuration + //******************************************* + + //dot->setLogLevel(mts::MTSLog::INFO_LEVEL); + dot->setLogLevel(mts::MTSLog::TRACE_LEVEL); logInfo("Checking Config"); // Test if we've already saved the config @@ -248,23 +248,26 @@ //******************************************* // end of configuration //******************************************* + + mDotConfigPrint(); //char dataBuf[50]; - - -} - -void joinNetwork() { - int32_t ret; + //int32_t ret; logInfo("Joining Network"); + while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); //wait_ms(dot->getNextTxMs() + 1); osDelay(std::max((uint32_t)1000, (uint32_t)dot->getNextTxMs())); } logInfo("Joined Network"); - } + wait(10); + + +} + + void mDotConfigPrint() { @@ -330,6 +333,7 @@ * Sensor Functions ****************************************************/ +/* void readandprintBME280() { float temperature; float pressure; @@ -356,7 +360,7 @@ //printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", temperature, pressure, humidity); } - +*/ /***************************************************** @@ -372,7 +376,7 @@ while(true) { // printf("Hello world!\r\n"); printf("BME280 Sensor: \n"); - readandprintBME280(); + //readandprintBME280(); wait(5); //mDotGotoDeepSleep(60);