![](/media/cache/profiles/2dd26bee3d25f4e22c3db125e415203a.jpg.50x50_q85.jpg)
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
main.cpp
- Committer:
- AshuJoshi
- Date:
- 2016-07-04
- Revision:
- 2:866a72c3c3bf
- Parent:
- 1:36e336869699
- Child:
- 3:5c2bcba214b5
File content as of revision 2:866a72c3c3bf:
/****************************************************** * A Program to interface the Grove Base Shielf V2 * to the mDot UDK. * Additionally sample code to compress the data * for use with LPWANs such as LoRa *****************************************************/ #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 #define UDK2 1 #ifdef UDK2 DigitalOut led(LED1); #else DigitalOut led(XBEE_RSSI); #endif //BME280 sensor(I2C_SDA, I2C_SCL) // MDot UDK - I2C_SDA and I2C_SCL connected to PC_9/PA_* BME280 b280(PC_9, PA_8); // Globals Ticker tick; mDot* dot; // Function Declarations void endLessTestLoop(); void setUpLEDBlink(); void blink(); void readandprintBME280(); void mDotConfig(); void mDotGotoDeepSleep(int seconds); /***************************************************** * MAIN *****************************************************/ int main(){ // 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); } /***************************************************** * Sensor Functions ****************************************************/ void readandprintBME280() { 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); } /***************************************************** * FUNCTIONS for Simple Testing ****************************************************/ void setUpLEDBlink(){ // configure the Ticker to blink the LED on 500ms interval tick.attach(&blink, 0.5); } void endLessTestLoop() { while(true) { // printf("Hello world!\r\n"); printf("BME280 Sensor: \n"); readandprintBME280(); mDotGotoDeepSleep(10); } } // Callback function to change LED state void blink() { led = !led; }