![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Temperature reading using NUCLEO-L152RE microcontroller and Grove – Temperature&Humidity Sensor Pro.
Dependencies: DHT LMiC SX1276Lib mbed
Fork of LoRaWAN_send_text by
Revision 14:c872172f062c, committed 2016-01-19
- Comitter:
- dagga
- Date:
- Tue Jan 19 09:51:34 2016 +0000
- Parent:
- 13:d2eb917f9883
- Commit message:
- hey
Changed in this revision
DHT.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d2eb917f9883 -r c872172f062c DHT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Tue Jan 19 09:51:34 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Wimpie/code/DHT/#9b5b3200688f
diff -r d2eb917f9883 -r c872172f062c main.cpp --- a/main.cpp Wed Nov 11 18:32:46 2015 +0000 +++ b/main.cpp Tue Jan 19 09:51:34 2016 +0000 @@ -4,13 +4,17 @@ #include "lmic.h" #include "debug.h" +#include "DHT.h" + #define LORAWAN_NET_ID (uint32_t) 0x00000000 // TODO: enter device address below, for TTN just set ??? -#define LORAWAN_DEV_ADDR (uint32_t) 0x5A480??? +#define LORAWAN_DEV_ADDR (uint32_t) 0x02031003 #define LORAWAN_ADR_ON 1 #define LORAWAN_CONFIRMED_MSG_ON 1 #define LORAWAN_APP_PORT 3//15 +DHT sensor(A1, AM2302); + static uint8_t NwkSKey[] = { // TODO: enter network, or use TTN default // e.g. for 2B7E151628AED2A6ABF7158809CF4F3C => @@ -33,14 +37,35 @@ void os_getDevEui (uint8_t *buf) {} // ignore void os_getDevKey (uint8_t *buf) {} // ignore +float getTemperature() { + + int err = 1; + + while(err != 0) { + wait(2.0f); + err = sensor.readData(); + } + + return sensor.ReadTemperature(CELCIUS); +} + void onSendFrame (osjob_t* j) { - const char* message = "Hello"; // ASCII only + + char message[32]; + + float temperature = getTemperature(); + printf("Temperature is %4.2f \r\n", temperature); + + sprintf(message, "%4.2f", temperature); + int frameLength = strlen(message); // keep it < 32 for (int i = 0; i < frameLength; i++) { LMIC.frame[i] = message[i]; } int result = LMIC_setTxData2(LORAWAN_APP_PORT, LMIC.frame, frameLength, LORAWAN_CONFIRMED_MSG_ON); // calls onEvent() + + os_setTimedCallback(j, os_getTime() + sec2osticks(60), onSendFrame); } void onInit (osjob_t* j) {