Temperature reading using NUCLEO-L152RE microcontroller and Grove – Temperature&Humidity Sensor Pro.
Dependencies: DHT LMiC SX1276Lib mbed
Fork of LoRaWAN_send_text by
Diff: main.cpp
- Revision:
- 6:fbfc95b5c979
- Parent:
- 5:1f8829bd11ed
- Child:
- 7:4adfa7248a0b
--- a/main.cpp Sun Sep 13 13:51:32 2015 +0000 +++ b/main.cpp Mon Sep 14 09:26:25 2015 +0000 @@ -1,18 +1,17 @@ -/* License: Revised BSD License, see LICENSE.TXT, (c)2015 Semtech */ +/* License: Revised BSD License, see LICENSE.TXT, (c)2015 tamberg.org, (c)2015 Semtech */ #include "mbed.h" #include "lmic.h" #include "debug.h" -#define OVER_THE_AIR_ACTIVATION 0 -#define LORAWAN_NET_ID ( uint32_t )0x00000000 -#define LORAWAN_DEV_ADDR ( uint32_t )0x00001056//0x12345678 -#define APP_TX_DUTYCYCLE 5000 // 5 [s] value in ms -#define APP_TX_DUTYCYCLE_RND 1000 // 1 [s] value in ms -#define LORAWAN_ADR_ON 1 -#define LORAWAN_CONFIRMED_MSG_ON 1 -#define LORAWAN_APP_PORT 15 -#define LORAWAN_APP_DATA_SIZE 6 +#define LORAWAN_NET_ID (uint32_t) 0x00000000 +#define LORAWAN_DEV_ADDR (uint32_t) 0x00001056 +#define APP_TX_DUTYCYCLE 5000 // ms +#define APP_TX_DUTYCYCLE_RND 1000 // ms +#define LORAWAN_ADR_ON 1 +#define LORAWAN_CONFIRMED_MSG_ON 1 +#define LORAWAN_APP_PORT 15 +#define LORAWAN_APP_DATA_SIZE 51 // 6 // max 51 static const uint8_t AppEui[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -37,8 +36,6 @@ 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; -osjob_t rxLedJob; -osjob_t txLedJob; osjob_t sendFrameJob; static bool AppLedStateOn = false; @@ -62,27 +59,23 @@ memcpy(buf, DevKey, 16); } -static void onRxLed (osjob_t* j) { - debug_val("LED2 = ", 0 ); -} - -static void onTxLed (osjob_t* j) { - debug_val("LED1 = ", 0 ); -} - static void prepareTxFrame (void) { debug_str("prepareTxFrame\r\n"); - LMIC.frame[0] = AppLedStateOn; - LMIC.frame[1] = LMIC.seqnoDn >> 8; - LMIC.frame[2] = LMIC.seqnoDn; - LMIC.frame[3] = LMIC.rssi >> 8; - LMIC.frame[4] = LMIC.rssi; - LMIC.frame[5] = LMIC.snr; + for (int i = 0; i < LORAWAN_APP_DATA_SIZE; i++) { + LMIC.frame[i] = i; + } +// LMIC.frame[0] = 0;//AppLedStateOn; +// LMIC.frame[1] = 1;//LMIC.seqnoDn >> 8; +// LMIC.frame[2] = 2;//LMIC.seqnoDn; +// LMIC.frame[3] = 3;//LMIC.rssi >> 8; +// LMIC.frame[4] = 4;//LMIC.rssi; +// LMIC.frame[5] = 5;//LMIC.snr; } void processRxFrame (void) { debug_str("processRxFrame\r\n"); - switch(LMIC.frame[LMIC.dataBeg - 1]) { // Check Rx port number + u1_t rxPort = LMIC.frame[LMIC.dataBeg - 1]; + switch(rxPort) { case 1: // The application LED can be controlled on port 1 or 2 case 2: if(LMIC.dataLen == 1) { @@ -98,14 +91,14 @@ static void onSendFrame (osjob_t* j) { debug_str("onSendFrame\r\n"); prepareTxFrame(); - LMIC_setTxData2( + // int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed); + debug_str("LMIC_setTxData2\r\n"); + int result = LMIC_setTxData2( LORAWAN_APP_PORT, LMIC.frame, LORAWAN_APP_DATA_SIZE, LORAWAN_CONFIRMED_MSG_ON); - -// debug_val("LED1 = ", 1); -// os_setTimedCallback(&txLedJob, os_getTime() + ms2osticks(25), onTxLed); + debug_val("result = ", result); } static void onInit (osjob_t* j) { @@ -122,7 +115,7 @@ // onEvent() callback will be invoked... } -int main(void) { +int main (void) { debug_str("main\r\n"); osjob_t initjob; os_init(); @@ -130,12 +123,11 @@ os_runloop(); // blocking } -void onEvent (ev_t ev) { +void onEvent (ev_t ev) { // called by lmic.cpp, see also oslmic.h debug_str("onEvent\r\n"); bool txOn = false; debug_event(ev); - - switch(ev) { + switch (ev) { case EV_JOINED: // network joined, session established debug_val("Net ID = ", LMIC.netid); txOn = true; @@ -144,8 +136,8 @@ debug_val("Datarate = ", LMIC.datarate); // Check if we have a downlink on either Rx1 or Rx2 windows if ((LMIC.txrxFlags & (TXRX_DNW1 | TXRX_DNW2)) != 0) { - debug_val("LED2 = ", 1); - os_setTimedCallback(&rxLedJob, os_getTime() + ms2osticks(25), onRxLed); + //debug_val("LED2 = ", 1); + //os_setTimedCallback(&rxLedJob, os_getTime() + ms2osticks(25), onRxLed); if (LMIC.dataLen != 0) { // data received in rx slot after tx debug_buf(LMIC.frame + LMIC.dataBeg, LMIC.dataLen); processRxFrame();