Send text with LoRaWAN.
Dependencies: LMiC SX1276Lib mbed
Fork of LoRaWAN-lmic-app by
main.cpp
- Committer:
- tamberg
- Date:
- 2015-10-21
- Revision:
- 12:020ffc39a19e
- Parent:
- 11:0cc0f7b84c72
- Child:
- 13:d2eb917f9883
File content as of revision 12:020ffc39a19e:
// License: Revised BSD License, see LICENSE.TXT, (c)2015 Semtech #include "mbed.h" #include "lmic.h" #include "debug.h" #define LORAWAN_NET_ID (uint32_t) 0x00000000 // TODO: enter your device address below, e.g. for DevAddr 01234567 => #define LORAWAN_DEV_ADDR (uint32_t) 0x01234567 // the 0x.. is important #define LORAWAN_ADR_ON 1 #define LORAWAN_CONFIRMED_MSG_ON 1 #define LORAWAN_APP_PORT 3 static uint8_t NwkSKey[] = { // TODO: enter your NwkSKey below, // e.g. for 00112233445566778899AABBCCDDEEFF => 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; static uint8_t ArtSKey[] = { // TODO: enter your AppSKey below, // e.g. for 00112233445566778899AABBCCDDEEFF => 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 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 void onSendFrame (osjob_t* j) { const char* message = "Hello"; // ASCII only 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() } void onInit (osjob_t* j) { LMIC_reset(); LMIC_setAdrMode(LORAWAN_ADR_ON); 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_event(ev); // log incoming event, e.g. TXCOMPLETE if (ev == EV_TXCOMPLETE) { os_setCallback(&sendFrameJob, onSendFrame); } } int main (void) { debug_str("main\r\n"); os_init(); os_setCallback(&initjob, onInit); os_runloop(); // blocking }