[LMIC] EV_JOINED event never fires

Hello,

We are using an ESP32 (HELTEC) that is already integrated with a LORA chip.
We are using a gateway (RIESING RF RHF0M01 915 MHZ)

We are currently using the IBM LMIC library for testing (end-device).

We are using Loraserver and TTN to run the tests.

The situation that I am going to present is repeating for both TTN and LoraServer

The code we are using in the end-device: (We have already tested all the examples we found):

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

// 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] = { 0x13, 0xF9, 0x00, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
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] = { 0x56, 0x46, 0x54, 0x95, 0x78, 0x56, 0x34, 0x12 };
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] = { 0xFC, 0x64, 0xAD, 0xE6, 0x05, 0xF9, 0x69, 0x73, 0x5F, 0xD7, 0x12, 0x47, 0x7B, 0x1A, 0x89, 0xFC };
void os_getDevKey (u1_t* buf) {
memcpy_P(buf, APPKEY, 16);
}

static uint8_t mydata[] = “olá mundo lora!”;
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 6;

// Pin mapping
const lmic_pinmap lmic_pins = {
.nss = 18,
.rxtx = LMIC_UNUSED_PIN,
.rst = 14,
.dio = {26, 26, LMIC_UNUSED_PIN},
};

void onEvent (ev_t ev) {
Serial.print(os_getTime());
Serial.print(": ");
switch (ev) {
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_JOINING:
Serial.println(F(“EV_JOINING”));
break;
case EV_JOINED:
Serial.println(F(“EV_JOINED”));

  // Disable link check validation (automatically enabled
  // during join, but not supported by TTN at this time).
  LMIC_setLinkCheckMode(0);
  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;
  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"));
  }
  // Schedule next transmission
  os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);
  break;
case EV_LOST_TSYNC:
  Serial.println(F("EV_LOST_TSYNC"));
  break;
case EV_RESET:
  Serial.println(F("EV_RESET"));
  break;
case EV_RXCOMPLETE:
  // data received in ping slot
  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 do_send(osjob_t* j) {
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F(“OP_TXRXPEND, not sending”));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata) - 1, 0);
Serial.println(F(“Packet queued”));
}
// Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
Serial.begin(9600);
Serial.println(F(“Starting”));

#ifdef VCC_ENABLE
// For Pinoccio Scout boards
pinMode(VCC_ENABLE, OUTPUT);
digitalWrite(VCC_ENABLE, HIGH);
delay(1000);
#endif

// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();

LMIC_setLinkCheckMode(1);
LMIC_setAdrMode(1);
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);

// Start job (sending automatically starts OTAA too)
do_send(&sendjob);
}

void loop() {

os_runloop_once();
delay(5000);
}

The code we are using in GATEWAY (LORASERVER) is below:

{
“SX1301_conf”: {
“lorawan_public”: true,
“clksrc”: 1, /* radio_1 provides clock to concentrator /
“antenna_gain”: 0, /
antenna gain, in dBi /
“radio_0”: {
“enable”: true,
“type”: “SX1257”,
“freq”: 902700000,
“rssi_offset”: -166.0,
“tx_enable”: true,
“tx_freq_min”: 902000000,
“tx_freq_max”: 928000000
},
“radio_1”: {
“enable”: true,
“type”: “SX1257”,
“freq”: 903400000,
“rssi_offset”: -166.0,
“tx_enable”: false
},
“chan_multiSF_0”: {
/
Lora MAC channel, 125kHz, all SF, 902.3 MHz /
“enable”: true,
“radio”: 0,
“if”: -400000
},
“chan_multiSF_1”: {
/
Lora MAC channel, 125kHz, all SF, 902.5 MHz /
“enable”: true,
“radio”: 0,
“if”: -200000
},
“chan_multiSF_2”: {
/
Lora MAC channel, 125kHz, all SF, 902.7 MHz /
“enable”: true,
“radio”: 0,
“if”: 0
},
“chan_multiSF_3”: {
/
Lora MAC channel, 125kHz, all SF, 902.9 MHz /
“enable”: true,
“radio”: 0,
“if”: 200000
},
“chan_multiSF_4”: {
/
Lora MAC channel, 125kHz, all SF, 903.1 MHz /
“enable”: true,
“radio”: 1,
“if”: -300000
},
“chan_multiSF_5”: {
/
Lora MAC channel, 125kHz, all SF, 903.3 MHz /
“enable”: true,
“radio”: 1,
“if”: -100000
},
“chan_multiSF_6”: {
/
Lora MAC channel, 125kHz, all SF, 903.5 MHz /
“enable”: true,
“radio”: 1,
“if”: 100000
},
“chan_multiSF_7”: {
/
Lora MAC channel, 125kHz, all SF, 903.7 MHz /
“enable”: true,
“radio”: 1,
“if”: 300000
},
“chan_Lora_std”: {
/
Lora MAC channel, 500kHz, SF8, 903.0 MHz /
“enable”: true,
“radio”: 0,
“if”: 300000,
“bandwidth”: 500000,
“spread_factor”: 8
},
“chan_FSK”: {
/
FSK 100kbps channel, 903.0 MHz */
“enable”: false,
“radio”: 0,
“if”: 300000,
“bandwidth”: 250000,
“datarate”: 100000
},
“tx_lut_0”: {
“desc”: “TX gain table, index 0”,
“pa_gain”: 0,
“mix_gain”: 8,
“rf_power”: -6,
“dig_gain”: 0
},
“tx_lut_1”: {
“desc”: “TX gain table, index 1”,
“pa_gain”: 0,
“mix_gain”: 10,
“rf_power”: -3,
“dig_gain”: 0
},
“tx_lut_2”: {
“desc”: “TX gain table, index 2”,
“pa_gain”: 0,
“mix_gain”: 12,
“rf_power”: 0,
“dig_gain”: 0
},
“tx_lut_3”: {
“desc”: “TX gain table, index 3”,
“pa_gain”: 1,
“mix_gain”: 8,
“rf_power”: 3,
“dig_gain”: 0
},
“tx_lut_4”: {
“desc”: “TX gain table, index 4”,
“pa_gain”: 1,
“mix_gain”: 10,
“rf_power”: 6,
“dig_gain”: 0
},
“tx_lut_5”: {
“desc”: “TX gain table, index 5”,
“pa_gain”: 1,
“mix_gain”: 12,
“rf_power”: 10,
“dig_gain”: 0
},
“tx_lut_6”: {
“desc”: “TX gain table, index 6”,
“pa_gain”: 1,
“mix_gain”: 13,
“rf_power”: 11,
“dig_gain”: 0
},
“tx_lut_7”: {
“desc”: “TX gain table, index 7”,
“pa_gain”: 2,
“mix_gain”: 9,
“rf_power”: 12,
“dig_gain”: 0
},
“tx_lut_8”: {
“desc”: “TX gain table, index 8”,
“pa_gain”: 1,
“mix_gain”: 15,
“rf_power”: 13,
“dig_gain”: 0
},
“tx_lut_9”: {
“desc”: “TX gain table, index 9”,
“pa_gain”: 2,
“mix_gain”: 10,
“rf_power”: 14,
“dig_gain”: 0
},
“tx_lut_10”: {
“desc”: “TX gain table, index 10”,
“pa_gain”: 2,
“mix_gain”: 11,
“rf_power”: 16,
“dig_gain”: 0
},
“tx_lut_11”: {
“desc”: “TX gain table, index 11”,
“pa_gain”: 3,
“mix_gain”: 9,
“rf_power”: 20,
“dig_gain”: 0
},
“tx_lut_12”: {
“desc”: “TX gain table, index 12”,
“pa_gain”: 3,
“mix_gain”: 10,
“rf_power”: 23,
“dig_gain”: 0
},
“tx_lut_13”: {
“desc”: “TX gain table, index 13”,
“pa_gain”: 3,
“mix_gain”: 11,
“rf_power”: 25,
“dig_gain”: 0
},
“tx_lut_14”: {
“desc”: “TX gain table, index 14”,
“pa_gain”: 3,
“mix_gain”: 12,
“rf_power”: 26,
“dig_gain”: 0
},
“tx_lut_15”: {
“desc”: “TX gain table, index 15”,
“pa_gain”: 3,
“mix_gain”: 14,
“rf_power”: 27,
“dig_gain”: 0
}
},

"gateway_conf": {
	"gateway_ID": "AA555A0000000000",
	/* change with default server address/ports, or overwrite in local_conf.json */
	"server_address": "localhost",
	"serv_port_up": 1700,
	"serv_port_down": 1700,
	/* adjust the following parameters for your network */
	"keepalive_interval": 10,
	"stat_interval": 30,
	"push_timeout_ms": 100,
	/* forward only valid packets */
	"forward_crc_valid": true,
	"forward_crc_error": false,
	"forward_crc_disabled": false,
	/* GPS configuration */
	/* GPS reference coordinates */
	"ref_latitude": 0.0,
	"ref_longitude": 0.0,
	"ref_altitude": 0,
	/* Beaconing parameters */
	"beacon_period": 128,
	"beacon_freq_hz": 923300000,
	"beacon_freq_nb": 8,
	"beacon_freq_step": 600000,
	"beacon_datarate": 12,
	"beacon_bw_hz": 500000,
	"beacon_power": 14,
	"beacon_infodesc": 0
}

}

Our main doubts:

Should not the console return “EV_JOINED”? And after doing this send the package?

In the case of loraserver - Should not the server return this? (application / [applicationID] / device / [devEUI] / rx)

After the data has been sent, what would be the procedure to obtain it in TTN and LORASERVER?

Be sure to have the DEVEUI and APPEUI in little indian. And you can have some debug verboose if you change your config.h in LMIC library which will help you a lot. You should also check your logs for the bridge, the loraserver and the lora-app-server. I had a similar problem and one log just warned me that my DEVEUI wasn’t correct.

1 Like

I performed the indicated procedure

But I still have the same situation

Would you mind editing your post and add wrap your code in code blocks? E.g.

```c
// for c code
```

or

```json
{"json": "object"}
```

That make it easier for others to review your code :slight_smile: