Arduino LMIC and multitasking (on ESP32)

Thank you both for your help !

I had a look at the paxcounter, and found out that my code had two issues.

  • ttnTask never blocks, meaning that the IDLE task will never execute and will not feed the idle task watchdog. Solution is to add vTaskDelay(1) to the infinite loop (unless there is something cleaner).
    The serial port outputs the following:

Task watchdog got triggered. The following tasks did not reset the watchdog in time:
– IDLE (CPU 0)
Tasks currently running:
CPU 0: TTN Task
CPU 1: loopTask

  • ttnTask is running on core 0, arduino loop on core 1. I don’t know why this is a problem, but the solution is to pin ttnTask to core 1. (I also tried pinning it to core 0, it kept on sending multiple join requests even though the watchdog was not trigged anymore)

These are the two functions that I changed in my first example:

void setup() {
    xTaskCreatePinnedToCore(ttnTask, "ttnTask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
}

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

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

    for (;;) {
        os_runloop_once();
        vTaskDelay(1);
    }
}

It seems to work fine now, so I can carry on using freeRTOS. Thanks !