Temperature reading using NUCLEO-L152RE microcontroller and Grove – Temperature&Humidity Sensor Pro.

Dependencies:   DHT LMiC SX1276Lib mbed

Fork of LoRaWAN_send_text by Thomas Amberg

Revision:
9:fdd150f9db9e
Parent:
8:747796516a2f
Child:
10:576f275cfc14
--- a/main.cpp	Wed Sep 16 00:02:20 2015 +0000
+++ b/main.cpp	Wed Sep 16 07:53:43 2015 +0000
@@ -1,4 +1,4 @@
-/* License: Revised BSD License, see LICENSE.TXT, (c)2015 tamberg.org, (c)2015 Semtech */
+// License: Revised BSD License, see LICENSE.TXT, (c)2015 tamberg.org, (c)2015 Semtech
 
 #include "mbed.h"
 #include "lmic.h"
@@ -21,76 +21,37 @@
     0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
 };
 
+osjob_t initjob;
 osjob_t sendFrameJob;
+u1_t n = 0;
 
 void os_getArtEui (uint8_t *buf) {} // ignore
 void os_getDevEui (uint8_t *buf) {} // ignore
 void os_getDevKey (uint8_t *buf) {} // ignore
 
-u1_t n = 0;
-
-static void prepareTxFrame (void) {
-    debug_str("prepareTxFrame\r\n");
-    //for (int i = 0; i < LORAWAN_APP_DATA_SIZE; i++) {
-    //    LMIC.frame[i] = n;
-    //}
-    //n++;
-    LMIC.frame[0] = n++;
-}
-
-void processRxFrame (void) {
-    debug_str("processRxFrame\r\n");
-    u1_t rxPort = LMIC.frame[LMIC.dataBeg - 1];
-    debug_val("rxPort", rxPort);
-    for (int i = 0; i < LMIC.dataLen; i++) {
-        debug_hex(LMIC.frame[LMIC.dataBeg + i]);
-        debug_char(' ');    
-    }
+void onSendFrame (osjob_t* j) {
+    LMIC.frame[0] = n++; // or any other payload
+    int result = LMIC_setTxData2(LORAWAN_APP_PORT, LMIC.frame, 
+        LORAWAN_APP_DATA_SIZE, LORAWAN_CONFIRMED_MSG_ON); // calls onEvent()
 }
 
-static void onSendFrame (osjob_t* j) {
-    debug_str("onSendFrame\r\n");
-    prepareTxFrame();
-    int result = LMIC_setTxData2(
-        LORAWAN_APP_PORT, 
-        LMIC.frame, 
-        LORAWAN_APP_DATA_SIZE, 
-        LORAWAN_CONFIRMED_MSG_ON); // calls onEvent()
-    debug_val("LMIC_setTxData2, result = ", result);
-}
-
-static void onInit (osjob_t* j) {
-    debug_str("onInit\r\n");
-    LMIC_reset(); // reset MAC state
+void onInit (osjob_t* j) {
+    LMIC_reset();
     LMIC_setAdrMode(LORAWAN_ADR_ON);
-    LMIC_setDrTxpow(DR_SF12, 16); // 14
-    LMIC_setSession(
-        LORAWAN_NET_ID, 
-        LORAWAN_DEV_ADDR, 
-        NwkSKey, 
-        ArtSKey);
+    LMIC_setDrTxpow(DR_SF12, 14);
+    LMIC_setSession(LORAWAN_NET_ID, LORAWAN_DEV_ADDR, NwkSKey, ArtSKey);
     onSendFrame(NULL);
 }
 
 void onEvent (ev_t ev) { // called by lmic.cpp, see also oslmic.h
-    debug_str("onEvent\r\n");
     debug_event(ev);
-    if (ev == EV_TXCOMPLETE) { // scheduled data sent (optionally data received)
-        debug_val("Datarate = ", LMIC.datarate);
-        if ((LMIC.txrxFlags & (TXRX_DNW1 | TXRX_DNW2)) != 0) { // downlink?
-            if (LMIC.dataLen != 0) { // data received in rx slot after tx
-                debug_buf(LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
-                processRxFrame();
-            }
-        }
-        //os_setTimedCallback(&sendFrameJob, os_getTime() + 5000, onSendFrame);
+    if (ev == EV_TXCOMPLETE) {
         os_setCallback(&sendFrameJob, onSendFrame);
     }
 }
 
 int main (void) {
     debug_str("main\r\n");
-    osjob_t initjob;
     os_init();
     os_setCallback(&initjob, onInit);
     os_runloop(); // blocking