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:
- 2:866a72c3c3bf
- Parent:
- 1:36e336869699
- Child:
- 3:5c2bcba214b5
--- a/main.cpp Sun Jul 03 16:00:14 2016 +0000
+++ b/main.cpp Mon Jul 04 22:29:31 2016 +0000
@@ -7,8 +7,17 @@
#include "mbed.h"
#include <math.h>
+ #include <string>
+ #include "mDot.h"
+ #include "MTSLog.h"
+ #include "MTSText.h"
#include "BME280.h"
+using namespace mts;
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
// mDot UDK Specific
// MDot Pinout: https://developer.mbed.org/platforms/MTS-mDot-F411/#pinout-diagram
// Uncomment this line if using a full sized UDK2.0 instead of a Micro UDK
@@ -28,12 +37,17 @@
// Globals
Ticker tick;
+mDot* dot;
+
// Function Declarations
void endLessTestLoop();
void setUpLEDBlink();
void blink();
void readandprintBME280();
+void mDotConfig();
+void mDotGotoDeepSleep(int seconds);
+
/*****************************************************
@@ -43,12 +57,35 @@
// Simple Test Functions, "Hello World on UDK
setUpLEDBlink();
-
+ mDotConfig();
endLessTestLoop();
return 0;
}
+/*****************************************************
+ * mDot Functions
+ ****************************************************/
+
+
+void mDotConfig() {
+ // get a mDot handle
+ dot = mDot::getInstance();
+ //dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+ dot->setLogLevel(mts::MTSLog::TRACE_LEVEL);
+ // print library version information
+ logInfo("version: %s", dot->getId().c_str());
+}
+
+void mDotGotoDeepSleep(int seconds) {
+ // logInfo("input to sleep routine %d", seconds);
+ // Should sleep here and wakeup after a set interval.
+ uint32_t sleep_time = MAX((dot->getNextTxMs() / 1000), seconds);
+ 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, false);
+
+}
@@ -57,7 +94,25 @@
****************************************************/
void readandprintBME280() {
- printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", b280.getTemperature(), b280.getPressure(), b280.getHumidity());
+ float temperature;
+ float pressure;
+ float humidity;
+ char string_buffer[64];
+
+ // Temperature
+ temperature = b280.getTemperature();
+ sprintf(string_buffer, "%s%3.2f", "TC:", temperature);
+ logInfo("The temperature is %s", string_buffer);
+ // Pressure
+ pressure = b280.getPressure();
+ sprintf(string_buffer, "%s%04.2f", "hPa:", pressure);
+ logInfo("The pressure is %s", string_buffer);
+ // Humidity
+ humidity = b280.getHumidity();
+ sprintf(string_buffer, "%s%03.2f", "H%:", humidity);
+ logInfo("The humidty is %s", string_buffer);
+
+ // printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", temperature, pressure, humidity);
}
@@ -76,7 +131,9 @@
// printf("Hello world!\r\n");
printf("BME280 Sensor: \n");
readandprintBME280();
- wait(5);
+
+ mDotGotoDeepSleep(10);
+
}
}