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:
- 7:4adfa7248a0b
- Parent:
- 6:fbfc95b5c979
- Child:
- 8:747796516a2f
--- a/main.cpp Mon Sep 14 09:26:25 2015 +0000 +++ b/main.cpp Mon Sep 14 14:26:55 2015 +0000 @@ -11,20 +11,7 @@ #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 -}; - -static const u1_t DevEui[8] = { - 0xF0, 0x3D, 0x29, 0x10, 0x00, 0x00, 0x10, 0x56 -}; - -static const uint8_t DevKey[16] = { - 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, - 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C -}; +#define LORAWAN_APP_DATA_SIZE 32 //6 // max 51 static uint8_t NwkSKey[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -38,67 +25,46 @@ osjob_t sendFrameJob; -static bool AppLedStateOn = false; - int32_t randr (int32_t min, int32_t max) { return (int32_t) rand() % (max - min + 1) + min; } -void os_getArtEui (uint8_t *buf) { - debug_str("os_getArtEui\r\n"); - memcpy(buf, AppEui, 8); -} - -void os_getDevEui (uint8_t *buf) { - debug_str("os_getDevEui\r\n"); - memcpy(buf, DevEui, 8); -} - -void os_getDevKey (uint8_t *buf) { - debug_str("os_getDevKey\r\n"); - memcpy(buf, DevKey, 16); -} +void os_getArtEui (uint8_t *buf) {} // ignore +void os_getDevEui (uint8_t *buf) {} // ignore +void os_getDevKey (uint8_t *buf) {} // ignore static void prepareTxFrame (void) { debug_str("prepareTxFrame\r\n"); 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; +// 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; } void processRxFrame (void) { debug_str("processRxFrame\r\n"); 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) { - AppLedStateOn = LMIC.frame[LMIC.dataBeg] & 0x01; - debug_val("LED3 = ", AppLedStateOn); - } - break; - default: - break; + debug_val("rxPort", rxPort); + for (int i = 0; i < LMIC.dataLen; i++) { + debug_hex(LMIC.frame[LMIC.dataBeg + i]); + debug_char(' '); } } static void onSendFrame (osjob_t* j) { debug_str("onSendFrame\r\n"); prepareTxFrame(); - // 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("result = ", result); + LORAWAN_CONFIRMED_MSG_ON); // calls onEvent() + debug_val("LMIC_setTxData2, result = ", result); } static void onInit (osjob_t* j) { @@ -112,7 +78,6 @@ NwkSKey, ArtSKey); onSendFrame(NULL); - // onEvent() callback will be invoked... } int main (void) {