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

Committer:
AshuJoshi
Date:
Sun Jul 03 16:00:14 2016 +0000
Revision:
1:36e336869699
Parent:
0:3ec6a7645098
Child:
2:866a72c3c3bf
Added support for the Grove BME280 based Triple Sensor - Pressure, Humidity and Temperature

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AshuJoshi 0:3ec6a7645098 1 /******************************************************
AshuJoshi 0:3ec6a7645098 2 * A Program to interface the Grove Base Shielf V2
AshuJoshi 0:3ec6a7645098 3 * to the mDot UDK.
AshuJoshi 0:3ec6a7645098 4 * Additionally sample code to compress the data
AshuJoshi 0:3ec6a7645098 5 * for use with LPWANs such as LoRa
AshuJoshi 0:3ec6a7645098 6 *****************************************************/
AshuJoshi 0:3ec6a7645098 7
AshuJoshi 0:3ec6a7645098 8 #include "mbed.h"
AshuJoshi 0:3ec6a7645098 9 #include <math.h>
AshuJoshi 1:36e336869699 10 #include "BME280.h"
AshuJoshi 0:3ec6a7645098 11
AshuJoshi 1:36e336869699 12 // mDot UDK Specific
AshuJoshi 1:36e336869699 13 // MDot Pinout: https://developer.mbed.org/platforms/MTS-mDot-F411/#pinout-diagram
AshuJoshi 0:3ec6a7645098 14 // Uncomment this line if using a full sized UDK2.0 instead of a Micro UDK
AshuJoshi 1:36e336869699 15
AshuJoshi 0:3ec6a7645098 16 #define UDK2 1
AshuJoshi 0:3ec6a7645098 17 #ifdef UDK2
AshuJoshi 0:3ec6a7645098 18 DigitalOut led(LED1);
AshuJoshi 0:3ec6a7645098 19 #else
AshuJoshi 0:3ec6a7645098 20 DigitalOut led(XBEE_RSSI);
AshuJoshi 0:3ec6a7645098 21 #endif
AshuJoshi 0:3ec6a7645098 22
AshuJoshi 1:36e336869699 23 //BME280 sensor(I2C_SDA, I2C_SCL)
AshuJoshi 1:36e336869699 24 // MDot UDK - I2C_SDA and I2C_SCL connected to PC_9/PA_*
AshuJoshi 1:36e336869699 25 BME280 b280(PC_9, PA_8);
AshuJoshi 1:36e336869699 26
AshuJoshi 1:36e336869699 27
AshuJoshi 1:36e336869699 28
AshuJoshi 0:3ec6a7645098 29 // Globals
AshuJoshi 0:3ec6a7645098 30 Ticker tick;
AshuJoshi 0:3ec6a7645098 31
AshuJoshi 0:3ec6a7645098 32 // Function Declarations
AshuJoshi 0:3ec6a7645098 33 void endLessTestLoop();
AshuJoshi 0:3ec6a7645098 34 void setUpLEDBlink();
AshuJoshi 0:3ec6a7645098 35 void blink();
AshuJoshi 1:36e336869699 36 void readandprintBME280();
AshuJoshi 0:3ec6a7645098 37
AshuJoshi 0:3ec6a7645098 38
AshuJoshi 0:3ec6a7645098 39 /*****************************************************
AshuJoshi 0:3ec6a7645098 40 * MAIN
AshuJoshi 0:3ec6a7645098 41 *****************************************************/
AshuJoshi 0:3ec6a7645098 42 int main(){
AshuJoshi 0:3ec6a7645098 43
AshuJoshi 0:3ec6a7645098 44 // Simple Test Functions, "Hello World on UDK
AshuJoshi 0:3ec6a7645098 45 setUpLEDBlink();
AshuJoshi 1:36e336869699 46
AshuJoshi 0:3ec6a7645098 47 endLessTestLoop();
AshuJoshi 0:3ec6a7645098 48
AshuJoshi 0:3ec6a7645098 49 return 0;
AshuJoshi 0:3ec6a7645098 50 }
AshuJoshi 0:3ec6a7645098 51
AshuJoshi 0:3ec6a7645098 52
AshuJoshi 0:3ec6a7645098 53
AshuJoshi 0:3ec6a7645098 54
AshuJoshi 1:36e336869699 55 /*****************************************************
AshuJoshi 1:36e336869699 56 * Sensor Functions
AshuJoshi 1:36e336869699 57 ****************************************************/
AshuJoshi 0:3ec6a7645098 58
AshuJoshi 1:36e336869699 59 void readandprintBME280() {
AshuJoshi 1:36e336869699 60 printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", b280.getTemperature(), b280.getPressure(), b280.getHumidity());
AshuJoshi 1:36e336869699 61 }
AshuJoshi 0:3ec6a7645098 62
AshuJoshi 0:3ec6a7645098 63
AshuJoshi 0:3ec6a7645098 64
AshuJoshi 0:3ec6a7645098 65 /*****************************************************
AshuJoshi 1:36e336869699 66 * FUNCTIONS for Simple Testing
AshuJoshi 1:36e336869699 67 ****************************************************/
AshuJoshi 0:3ec6a7645098 68
AshuJoshi 0:3ec6a7645098 69 void setUpLEDBlink(){
AshuJoshi 0:3ec6a7645098 70 // configure the Ticker to blink the LED on 500ms interval
AshuJoshi 0:3ec6a7645098 71 tick.attach(&blink, 0.5);
AshuJoshi 0:3ec6a7645098 72 }
AshuJoshi 0:3ec6a7645098 73
AshuJoshi 0:3ec6a7645098 74 void endLessTestLoop() {
AshuJoshi 0:3ec6a7645098 75 while(true) {
AshuJoshi 1:36e336869699 76 // printf("Hello world!\r\n");
AshuJoshi 1:36e336869699 77 printf("BME280 Sensor: \n");
AshuJoshi 1:36e336869699 78 readandprintBME280();
AshuJoshi 1:36e336869699 79 wait(5);
AshuJoshi 0:3ec6a7645098 80 }
AshuJoshi 0:3ec6a7645098 81 }
AshuJoshi 0:3ec6a7645098 82
AshuJoshi 0:3ec6a7645098 83 // Callback function to change LED state
AshuJoshi 0:3ec6a7645098 84 void blink() {
AshuJoshi 0:3ec6a7645098 85 led = !led;
AshuJoshi 0:3ec6a7645098 86 }