1 - This is the code running on my end-device
#include <stdio.h>
#include "lmic.h"
#include "debug.h"
// sensor functions
extern void initsensor(void);
//extern u2_t readsensor(void);
//////////////////////////////////////////////////
// CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
//////////////////////////////////////////////////
//NOTE: these values are used for testing on my local LoraWAN server
static const u1_t APPEUI[8] = { 0x6B, 0xF3, 0x00, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
static const u1_t DEVEUI[8] = { 0xFF, 0x85, 0xEF, 0xFF, 0xFF, 0xEB, 0x27, 0xB8 };
static const u1_t DEVKEY[16] = { 0x4A, 0x10, 0xBA, 0x2E, 0x74, 0x3D, 0x28, 0xDF, 0x9C, 0xA9, 0xA2, 0xC2, 0x27, 0xE2, 0xAD, 0x2B };
static const u1_t ARTKEY[16] ={ 0x36, 0x2F, 0x66, 0x8D, 0x1C, 0xC4, 0x08, 0x5C, 0x11, 0x31, 0x66, 0x91, 0xC4, 0xC1, 0x3D, 0xB3 };
static const u4_t DEVADDR = 0x011793AA; // <-- Change this address for every node!
// provide application router ID (8 bytes, LSBF)
void os_getArtEui (u1_t* buf)
{
memcpy(buf, APPEUI, 8);
}
// provide device ID (8 bytes, LSBF)
void os_getDevEui (u1_t* buf)
{
memcpy(buf, DEVEUI, 8);
}
// provide device key (16 bytes)
void os_getDevKey (u1_t* buf)
{
memcpy(buf, DEVKEY, 16);
}
void setup()
{
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
// by joining the network, precomputed session parameters are be provided.
LMIC_setSession (0x1, DEVADDR, (u1_t*)DEVKEY, (u1_t*)ARTKEY);
// Disable data rate adaptation
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);
LMIC_setAdrMode(0);
// Disable link check validation
LMIC.dn2Dr = DR_SF9;
LMIC_setLinkCheckMode(0);
// Disable beacon tracking
LMIC_disableTracking ();
// Stop listening for downstream data (periodical reception)
LMIC_stopPingable();
//LMIC_setClockError(MAX_CLOCK_ERROR * 10 / 100); <------------------------Not implemented
// Set data rate and transmit power (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7,14);
}
//////////////////////////////////////////////////
// UTILITY JOB
//////////////////////////////////////////////////
static osjob_t reportjob;
// report sensor value every minute
static void reportfunc (osjob_t* j)
{
// read sensor
//u2_t val = readsensor();
u2_t val = 0x0; // This is for testing only. this function will send the state(e.g 0%,30%, or 100%) of a
//component it will be connected to.
debug_val("val = ", val);
// prepare and schedule data for transmission
LMIC.frame[0] = val >> 8;
LMIC.frame[1] = val;
LMIC_setTxData2(1, LMIC.frame, 2, 0); // (port 1, 2 bytes, unconfirmed)
// reschedule job in 60 seconds
os_setTimedCallback(j, os_getTime()+sec2osticks(60), reportfunc);
}
void onEvent (ev_t ev)
{
debug_event(ev);
switch(ev) {
case EV_TXCOMPLETE:
// switch on LED
debug_led(1);
if (LMIC.txrxFlags & TXRX_ACK)
{
fprintf(stdout, "ACK RECEIVED\n");
}
fprintf(stdout, "TX COMPLETE\n");
if(LMIC.dataLen)
{ // data received in rx slot after tx
//debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
fprintf(stdout, "Data Received!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
}
break;
default:
break;
}
}
void loop()
{
reportfunc(&reportjob);
while(1)
{
os_runloop();
}
}
int main()
{
setup();
while (1)
{
loop();
}
return 0;
}
2- The screenshot of logs on the End-device
2- The output on my gateway