Porting the LMIC library to ESP32

Hi all!

Recently I started using an Espressif ESP32 (DevKitC) and the Dragino Lora Shield to make a node that can be connected to TTN. At the moment I would really like the IBM LMIC library to work on the ESP32 while still using the esp-idf (so not the Arduino Core).

I tried porting the LMIC library to the ESP32 environment. Some successes have been made (SPI connection works) but I’m afraid there are some timing issues. Since I’m on a fairly tight schedule I have to make decisions pretty fast. Is there anyone out there that tried to do the same as I did? Or am I bound to use the Arduino Core if I want to use the ESP32?

Hi,

Trying the same, esp idf is much reliabler than arduino.

Currently have the following issue. It seems to send something but I can’t get something on my gateway. Can you share your code?

run
Fired IRQ0
run
run
run
Fired IRQ1
run
run
Fired IRQ1
run
run
8321714: EV_TXCOMPLETE (includes waiting for RX windows)
run
8352972: Unknown event: 17
Packet queued

Benjamin

Hi Benjamin,

It seems like you are further with your implementation than I currently am. Unfortunately I haven’t been able to get the EV_TXCOMPLETE event yet. At the moment my code is in a bit of a mess because of all the prototyping and trying to make it work. I’ll refactor it and post a link to the github page soon.

Few questions for you though. How are you handling the timing? Did you implement a timer? Are you currently running it with FreeRTOS as well?

Regards,

also a Benjamin

@mars, see also https://thethingsnetwork.slack.com/archives/C44HFUG9G/p1493297631401881 (if you don’t have access, then request an invite on https://account.thethingsnetwork.org/) For future reference, I hope the two of you will keep things updated here as well… (If only as Slack messages expire quickly.)

Yep, it’s technically running in FreeRTOS. But it is really biting into it, it doesn’t run when it’s a alone task. Don’t ask why.

You can see how I realised the timing in the hal.c: https://github.com/berkutta/esp32_lmic/blob/master/main/hal.c#L227
I don’t know if that’s the proper way. Just copied over from the esp32 arduino thing.

Hi Benjamin,

I just uploaded the the code I currently have on GitHub. You can find it on here:
https://github.com/Benjamin1231/esp-idf-lmic

I tried to implement the LMIC library as a component in the esp-idf environment. That way it keeps my main nice and clean. In the lmic folder you will find a config file that defines the necessary pins for SPI and GPIO. After the os_init() and LMIC_reset() call I create a task called os_loop_task which is defined in oslmic.h/c.

The timer functionality is currently not implemented since I’m fairly sure the previous solution was not the way to go. Not really sure how to go forward from here and if the LMIC library can run with esp-idf without making big changes to the library.

I’m pleased to announce ttn-esp32, a new TTN device library for ESP32 and SX127x LoRa chips, implemented as an ESP-IDF component. The library builds on IBM’s LMIC code and provides a much simpler API taking full advantage of FreeRTOS’ task scheduling.

Please check it out. It’s free and open source. Your feedback is very welcome.

6 Likes