Hello,
I use the LMiC library with an ESP32 development board and the following code:
#include <lmic.h>
#include <hal/hal.h>
uint8_t NWKSKEY[16] = ...;
uint8_t APPSKEY[16] = ...;
uint32_t DEVADDR = ...;
// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain).
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
static uint8_t mydata[] = "Hello, world!";
static osjob_t SendJob;
const lmic_pinmap lmic_pins = {
.nss = 5,
.rxtx = LMIC_UNUSED_PIN,
.rst = 14,
.dio = {24, 33, 32},
};
void onEvent(ev_t Event)
{
Serial.print(os_getTime());
Serial.print(": ");
Serial.println("Event");
switch(Event)
{
case EV_JOINING:
Serial.println(F("EV_JOINING"));
break;
case EV_JOINED:
Serial.println(F("EV_JOINED"));
break;
case EV_SCAN_TIMEOUT:
Serial.println(F("EV_SCAN_TIMEOUT"));
break;
case EV_BEACON_FOUND:
Serial.println(F("EV_BEACON_FOUND"));
break;
case EV_BEACON_MISSED:
Serial.println(F("EV_BEACON_MISSED"));
break;
case EV_BEACON_TRACKED:
Serial.println(F("EV_BEACON_TRACKED"));
break;
case EV_RFU1:
Serial.println(F("EV_RFU1"));
break;
case EV_JOIN_FAILED:
Serial.println(F("EV_JOIN_FAILED"));
break;
case EV_REJOIN_FAILED:
Serial.println(F("EV_REJOIN_FAILED"));
break;
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
if(LMIC.txrxFlags & TXRX_ACK)
{
Serial.println(F("Received ack"));
}
if(LMIC.dataLen)
{
Serial.println(F("Received "));
Serial.println(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
}
break;
case EV_LOST_TSYNC:
Serial.println(F("EV_LOST_TSYNC"));
break;
case EV_RESET:
Serial.println(F("EV_RESET"));
break;
case EV_RXCOMPLETE:
Serial.println(F("EV_RXCOMPLETE"));
break;
case EV_LINK_DEAD:
Serial.println(F("EV_LINK_DEAD"));
break;
case EV_LINK_ALIVE:
Serial.println(F("EV_LINK_ALIVE"));
break;
default:
Serial.println(F("Unknown event"));
break;
}
}
void SendJob_Callback(osjob_t* Job)
{
// Check if there is not a current TX/RX job running
if(LMIC.opmode & OP_TXRXPEND)
{
Serial.println(F("OP_TXRXPEND, not sending"));
}
else
{
Serial.println(F("Packet queued"));
}
LMIC_setTxData2(1, mydata, sizeof(mydata) - 1, 0);
// Reschedule the job every 120 seconds
os_setTimedCallback(Job, os_getTime() + sec2osticks(10), SendJob_Callback);
}
void ttnTask(void* Context)
{
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
LMIC_setSession(0x1, DEVADDR, NWKSKEY, APPSKEY);
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI);
// Disable link check validation
LMIC_setLinkCheckMode(0);
// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7, 14);
LMIC_startJoining();
SendJob_Callback(&SendJob);
for(;;)
{
os_runloop_once();
vTaskDelay(1);
}
}
void setup()
{
Serial.begin(115200);
xTaskCreatePinnedToCore(ttnTask, "ttnTask", 2048, NULL, 5, NULL, 1);
}
void loop()
{
}
The first transmission is transmitted successfully, but all other messages don´t get sent.
OP_TXRXPEND, not sending
103140753: engineUpdate, opmode=0x888
103140787: Scheduled job 0x3ffc011c, cb 0x400d0e64 at 103765786
103765810: Running job 0x3ffc011c, cb 0x400d0e64, deadline 103765786
I read this article and the author says that this will happen when the DI1 isn´t connected, but I have connected DI0 - DI2.
What is wrong with this code?
Thank you!