Send text with LoRaWAN.
Dependencies: LMiC SX1276Lib mbed
Fork of LoRaWAN-lmic-app by
main.cpp
00001 // License: Revised BSD License, see LICENSE.TXT, (c)2015 Semtech 00002 00003 #include "mbed.h" 00004 #include "lmic.h" 00005 #include "debug.h" 00006 00007 #define LORAWAN_NET_ID (uint32_t) 0x00000000 00008 // TODO: enter device address below, for TTN just set ??? 00009 #define LORAWAN_DEV_ADDR (uint32_t) 0x5A480??? 00010 #define LORAWAN_ADR_ON 1 00011 #define LORAWAN_CONFIRMED_MSG_ON 1 00012 #define LORAWAN_APP_PORT 3//15 00013 00014 static uint8_t NwkSKey[] = { 00015 // TODO: enter network, or use TTN default 00016 // e.g. for 2B7E151628AED2A6ABF7158809CF4F3C => 00017 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 00018 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C 00019 }; 00020 00021 static uint8_t ArtSKey[] = { 00022 // TODO: enter application key, or use TTN default 00023 // e.g. for 2B7E151628AED2A6ABF7158809CF4F3C => 00024 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 00025 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C 00026 }; 00027 00028 osjob_t initjob; 00029 osjob_t sendFrameJob; 00030 u1_t n = 0; 00031 00032 void os_getArtEui (uint8_t *buf) {} // ignore 00033 void os_getDevEui (uint8_t *buf) {} // ignore 00034 void os_getDevKey (uint8_t *buf) {} // ignore 00035 00036 void onSendFrame (osjob_t* j) { 00037 const char* message = "Hello"; // ASCII only 00038 int frameLength = strlen(message); // keep it < 32 00039 for (int i = 0; i < frameLength; i++) { 00040 LMIC.frame[i] = message[i]; 00041 } 00042 int result = LMIC_setTxData2(LORAWAN_APP_PORT, LMIC.frame, 00043 frameLength, LORAWAN_CONFIRMED_MSG_ON); // calls onEvent() 00044 } 00045 00046 void onInit (osjob_t* j) { 00047 LMIC_reset(); 00048 LMIC_setAdrMode(LORAWAN_ADR_ON); 00049 LMIC_setDrTxpow(DR_SF12, 14); 00050 LMIC_setSession(LORAWAN_NET_ID, LORAWAN_DEV_ADDR, NwkSKey, ArtSKey); 00051 onSendFrame(NULL); 00052 } 00053 00054 void onEvent (ev_t ev) { // called by lmic.cpp, see also oslmic.h 00055 debug_event(ev); 00056 if (ev == EV_TXCOMPLETE) { 00057 os_setCallback(&sendFrameJob, onSendFrame); 00058 } 00059 } 00060 00061 int main (void) { 00062 debug_str("main\r\n"); 00063 os_init(); 00064 os_setCallback(&initjob, onInit); 00065 os_runloop(); // blocking 00066 }
Generated on Sat Jul 16 2022 03:13:53 by 1.7.2