Sleep mode after join failed, without further attempts

hello everyone, I have a problem with one of my devices, everything works ok and the code is almost debugged, but I need that, when there is no signal coverage lora, once the function “LoRaWAN.join ();” has finished trying and the console message appears "join failed, join again at 30s later
"Go to the part of the code that sends the plate to sleep, and don’t try it more times. I don’t know how to do it really …

Blockquote
void loop()
{
switch ( deviceState )
{
case DEVICE_STATE_INIT:
{
#if(AT_SUPPORT)
getDevParam();
#endif
printDevParam();
LoRaWAN.init(loraWanClass, loraWanRegion);
deviceState = DEVICE_STATE_JOIN;
break;
}
case DEVICE_STATE_JOIN:
{
LoRaWAN.join();
break;
}
case DEVICE_STATE_SEND:
{
prepareTxFrame( appPort );
LoRaWAN.send();
deviceState = DEVICE_STATE_CYCLE;
break;
}
case DEVICE_STATE_CYCLE:
{
// Schedule next packet transmission
txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
LoRaWAN.cycle(txDutyCycleTime);
deviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
LoRaWAN.sleep();

    CySysTickSetCallback(4, &systemTimer);

    break;
  }
default:
  {
    deviceState = DEVICE_STATE_INIT;
    break;
  }

}
}

Blockquote

What frequency band are you using?

868 EU. thanks for your attention

Have you tried using the official LoRaWAN example?
https://github.com/HelTecAutomation/CubeCell-Arduino/blob/master/libraries/LoRa/examples/LoRaWAN/LoRaWan/LoRaWan.ino
Can work normally? First of all, we have to confirm whether this is a hardware problem or a code problem.

everything works fine, upload the payload to ttn3 and it works perfect. Maybe I did not explain it well, I need to change the code so that if at some point there is no coverage lora the plate is not trying to send the data every 30 seconds of retry, I want the plate to sleep and wake up an hour later for example. Connection retries consume a lot of battery power.

You can modify the time of join again in LoRaWan_APP.cpp, modify the “rejoin_delay” parameter.

1 Like

perfect shaffer, thanks so much for the hack. I’m going to try to put it directly into sleep mode to try and save even more energy. There are intervals of up to 5 hours without coverage on a daily basis.