mcci-catena / arduino-lmic

LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
https://forum.mcci.io/c/device-software/arduino-lmic/
MIT License
643 stars 210 forks source link

EV_JOINED never triggered #432

Closed Spomky closed 5 years ago

Spomky commented 5 years ago

Hi,

The example using ABP works fine on a Heltec Lora v2 and packets are correctly received on my TTN console. When using it with OTAA, I can see activation packets that indicate the node is correctly registered, but the EV_JOINED is never triggered and thus no payload is sent.

Note: for information, the working PIN map I use for the Heltec Lora v2 is the following one:

const lmic_pinmap lmic_pins = {
  .nss = 18,
  .rxtx = LMIC_UNUSED_PIN,
  .rst = 14,
  .dio = {26, 34, 35},
};
cyberman54 commented 5 years ago

Wrong pin mapping.

change .dio = {26, 34, 35}, to .dio = {26, 35, 34},

Spomky commented 5 years ago

…no effect…. The activation packets are still there, but no payload is received. The console displays:

Starting
Packet queued
2968: EV_JOINING
328911: EV_TXSTART
4691684: EV_TXSTART
9025098: EV_TXSTART
14003346: EV_TXSTART
cyberman54 commented 5 years ago

Then check if you have a Heltec V2 board, or if it's a V1 (which has other pin mapping). Or do you perhaps use a single channel gateway (e.g. Dragino)? This won't work with OTAA. This sure won't be an issue of this library, since i am using this code on different Heltec boards, and all work.

Spomky commented 5 years ago

I am sure it is a v2. It is clearly written on the board. With the v1 pin mapping nothing works. With the v2 pin mapping it works fine with ABP but not with OTAA. So no doubt for the version of the board.

The gateway is a brand new TTIG so 8 channels.

Do you think it may come from the project_config/lmic_project_config.h file?

#define CFG_eu868 1
#define CFG_sx1276_radio 1
#define LMIC_USE_INTERRUPTS //Tried with and without this line
cyberman54 commented 5 years ago

Don't use interrupts as long as you have not the current version of this library. The function was broken for ESP32 in the past.

Spomky commented 5 years ago

Unfortunately, nothing changes with and without the interrupts

cyberman54 commented 5 years ago

Look here:

https://github.com/mcci-catena/arduino-lmic/issues/277

Spomky commented 5 years ago

That’s great thank you! I added the line LMIC_setClockError(10 * MAX_CLOCK_ERROR / 100); after LMIC_reset(); and it works fine now.

I am not sure to clearly understand what’s the behaviour of this function but it solves the issue. Thank you so much. Would you like I create a PR in the doc to mention that for this board?

cyberman54 commented 5 years ago

This is a workaround. Your application is likely causing timing problems breaking the lmic timing. This is usually not a hardware / board specific problem.

Spomky commented 5 years ago

Well… I just opened the ttn-otaa example, changed the PIN mapping, app eui, dev eui and app key values. Nothing more, nothing less.

cyberman54 commented 5 years ago

Yes, but using a Heltec board means you're obviously using ESP32-arduino framework, thus running LMIC on top of freeRTOS, while the LMIC library is intended to run on single core systems without RTOS. So timing can be different.