Join to lorawan even if its a while(1) condition

Hello friends,

I have a working code in Arduino Framework that uses RAK4631 Core, RAK12500 GPS and RAK1904 Accelerometer. My code it’s based in Lorawan Low Power Examples from Beegee Tokyo.

In some critical scenery, my code get into a while(true) condition that sends periodically the gps position assuming that the Wisbox was stole.
The problem it’s that if go into this critical scenery when i’m not connected to lorawan, i can’t to make a new connection to Chirpstack using lmh_join because the callbacks and Lorawan Functions doesn’t works inside the while(true) scenery. Chirpstack creates a new dev address but my Wisblock never recieve it because it’s busy in my while(true) condition.

When a run lmh_join outside the while(true), the new connection to Chirpstack works flawlessly.

¿it’s there any way to make a connection in my while(true) scenery?
¿maybe running something like that after the lmh_join?
// Give the semaphore, so the loop task will continue
xSemaphoreGiveFromISR(taskEvent, pdFALSE);

The problem is that if you block the MCU in a while loop, it cannot process the Join Accept messages, even if it receives them.

Do you have at least a delay(100) in your while loop to allow other tasks to run?
The LoRaWAN stack events are handled in a separate FreeRTOS task, so you have to allow it to run.

1 Like

Thanks Mr Beegee, i tried with delay(100) and delay(200) with no sucess, in both scenary i can’t to process the Join Accept messages.

This it’s the function that has the while(true) condition:

void sendGPSPeriodically() {

//We send a keepalive to know if we are connected to GW or Chirpstack
delay(1000);
sendLoraKeepAlive(loraFlagsPackaged(), readBatteryLevel());

unsigned long intervalReviewConnection = 120000;
unsigned long previousMillisReviewConnection = 0;

while (1) {

unsigned long currentMillis = millis();

if ((currentMillis - previousMillisSendGpsPosition) >= intervalSendGpsPosition) {

  #ifndef MAX_SAVE
  Serial.print("We send GPS every "); Serial.print(PERIODICITYSENDGPSPOSITION/1000); Serial.println(" seconds");
  #endif

  delay(2000); //to let lorawan make internal tasks.

  #ifndef USINGRAK12500
  updateGpsPositionRak1910();
  #endif

  #ifdef USINGRAK12500
  updateGpsPositionRak12500();
  #endif

  sendLoraPackage(loraFlagsPackaged(), readBatteryLevel(), latitude, longitude);
  previousMillisSendGpsPosition = currentMillis;
}

if ((currentMillis - previousMillisReviewConnection) >= intervalReviewConnection) {


    delay(2000); //to let lorawan make internal tasks.

   if (lmh_join_status_get() != LMH_SET) {

    //Not joined, make a new join request

    #ifndef MAX_SAVE
    Serial.println("We are disconnected from lorawan network, lets try a Join ");
    #endif
  
    lmh_join();

    previousMillisReviewConnection = currentMillis;

  }

  previousMillisReviewConnection = currentMillis;
}

}
}

EDIT: Was solved adding more time to the delay, with delay(30000) it has enough time to process the join.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.