I use the Heltec Lora V2 with LMiC and the following code in the EU.
// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8] = { 0x15, 0x44, ..., 0x84, 0xEA };
void os_getArtEui(u1_t* buf){ memcpy_P(buf, APPEUI, 8); }
// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8] = { 0x2C, 0x4F, ..., 0x70, 0x00 };
void os_getDevEui(u1_t* buf){ memcpy_P(buf, DEVEUI, 8); }
// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
// The key shown here is the semtech default key.
static const u1_t PROGMEM APPKEY[16] = { 0x14, 0x5B, ..., 0xDD };
void os_getDevKey(u1_t* buf){ memcpy_P(buf, APPKEY, 16); }
static uint8_t Payload[] = "Hello, world!";
static osjob_t TransmitJob;
const lmic_pinmap lmic_pins = {
.nss = 18,
.rxtx = LMIC_UNUSED_PIN,
.rst = 14,
.dio = {26, 35, 34},
};
const uint8_t TX_INTERVAL = 60;
void Transmit(osjob_t* Job);
void printHex2(unsigned v) {
v &= 0xff;
if (v < 16)
Serial.print('0');
Serial.print(v, HEX);
}
void onEvent(ev_t Event)
{
Serial.print(os_getTime());
Serial.print(": ");
switch(Event)
{
case EV_SCAN_TIMEOUT:
Serial.println("EV_SCAN_TIMEOUT");
break;
case EV_BEACON_FOUND:
Serial.println("EV_BEACON_FOUND");
break;
case EV_BEACON_MISSED:
Serial.println("EV_BEACON_MISSED");
break;
case EV_BEACON_TRACKED:
Serial.println("EV_BEACON_TRACKED");
break;
case EV_JOINING:
Serial.println("EV_JOINING");
break;
case EV_JOINED:
Serial.println("EV_JOINED");
{
u4_t netid = 0;
devaddr_t devaddr = 0;
u1_t nwkKey[16];
u1_t artKey[16];
LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
Serial.print("netid: ");
Serial.println(netid, DEC);
Serial.print("devaddr: ");
Serial.println(devaddr, HEX);
Serial.print("AppSKey: ");
for(size_t i = 0; i < sizeof(artKey); ++i)
{
if(i != 0)
{
Serial.print("-");
printHex2(artKey[i]);
}
}
Serial.println("");
Serial.print("NwkSKey: ");
for (size_t i = 0; i < sizeof(nwkKey); ++i)
{
if(i != 0)
{
Serial.print("-");
}
printHex2(nwkKey[i]);
}
Serial.println();
}
// Disable link check validation (automatically enabled
// during join, but because slow data rates change max TX
// size, we don't use it in this example.
LMIC_setLinkCheckMode(0);
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_RFU1:
|| Serial.println(F("EV_RFU1"));
|| break;
*/
case EV_JOIN_FAILED:
Serial.println("EV_JOIN_FAILED");
break;
case EV_REJOIN_FAILED:
Serial.println("EV_REJOIN_FAILED");
break;
case EV_TXCOMPLETE:
Serial.println("EV_TXCOMPLETE (includes waiting for RX windows)");
if(LMIC.txrxFlags & TXRX_ACK)
{
Serial.println("Received ack");
}
if(LMIC.dataLen)
{
Serial.print("Received ");
Serial.print(LMIC.dataLen);
Serial.println(" bytes of payload");
}
os_setTimedCallback(&TransmitJob, os_getTime() + sec2osticks(TX_INTERVAL), Transmit);
break;
case EV_LOST_TSYNC:
Serial.println("EV_LOST_TSYNC");
break;
case EV_RESET:
Serial.println("EV_RESET");
break;
case EV_RXCOMPLETE:
Serial.println("EV_RXCOMPLETE");
break;
case EV_LINK_DEAD:
Serial.println("EV_LINK_DEAD");
break;
case EV_LINK_ALIVE:
Serial.println("EV_LINK_ALIVE");
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_SCAN_FOUND:
|| Serial.println(F("EV_SCAN_FOUND"));
|| break;
*/
case EV_TXSTART:
Serial.println("EV_TXSTART");
break;
case EV_TXCANCELED:
Serial.println("EV_TXCANCELED");
break;
case EV_RXSTART:
break;
case EV_JOIN_TXCOMPLETE:
Serial.println("EV_JOIN_TXCOMPLETE: no JoinAccept");
break;
default:
Serial.print("Unknown event: ");
Serial.println((uint8_t)Event);
break;
}
}
void Transmit(osjob_t* Job)
{
if(LMIC.opmode & OP_TXRXPEND)
{
Serial.println("OP_TXRXPEND, not sending");
}
else
{
LMIC_setTxData2(1, Payload, sizeof(Payload) - 1, 0);
Serial.println("Packet queued");
}
}
void setup()
{
Serial.begin(115200);
Serial.println("[INFO] Starting...");
os_init();
LMIC_reset();
Transmit(&TransmitJob);
}
void loop()
{
os_runloop_once();
}
A Dragino DLOS8 is used as a gateway and this gateway is integrated into TTN. The application prints
[INFO] Starting...
Packet queued
6709: EV_JOINING
67087: EV_TXSTART
460818: EV_JOIN_TXCOMPLETE: no JoinAccept
but TTN displays a successful join.
How can I fix this problem?