System.sleep(SLEEP_MODE_DEEP,5) doesn't put the device to sleep mode

Hi,
I have electron device, i wrote a sample code for testing. i try to put the device sleep mode every after 30 sec for 5 sec. Initially it was working but after doing multiple time OTA, it doesn’t work.
Device kind of get struck i wont able to see any output. and red led glows some time then whole led turn OFF. compiling and flashing is success full
my code snippet:

uint16_t WAIT_INTERVAL = 30000;

int ledb = D7;
int ledc = D6;
//String Input;
uint32_t Start_time;
uint32_t end_time;
double value;

int command(String );
void measure_cell(void);
void radio_down(void);

Timer timer(WAIT_INTERVAL, radio_down, false);

void sleep_mode(){
}

SYSTEM_MODE(AUTOMATIC);

void setup(){
  
    Particle.variable("cell", &value, DOUBLE);
    Particle.function("cmd", command);
    pinMode(ledb, OUTPUT);
   
    digitalWrite(ledb, LOW);
    
    if(Particle.connected()){
    Particle.publish("radio_on", "0", PUBLIC);
    }
    Serial.begin(9600);
    timer.start();
    Start_time = System.ticks();
}

void loop(){
    if(Particle.connected()){
        digitalWrite(ledb, HIGH);
    }
}

int command (String cmd){
    if(cmd == "reset"){
       if(Particle.connected()){
        Particle.publish("Restting", "1",PUBLIC);
       }
        delay(1000);
        System.reset();
        return 1;
    } else if(cmd == "cell"){
        measure_cell();
        return -1; 
    } else{
    
      if(Particle.connected()){
        Particle.publish("call function", "0", PUBLIC);
      }
        return 0;
    }
}

void radio_down(void){
    end_time = System.ticks();
    uint32_t duration = (((end_time - Start_time) / System.ticksPerMicrosecond()) / 1000000);
    Serial.println(duration);

    delay(1000);
   System.sleep( SLEEP_MODE_DEEP, 5);           //THIS CAUSE DEVICE TO STRUCK.
}

void measure_cell(void){
    FuelGauge fuel;
    value = fuel.getVCell();
   if(Particle.connected()){
    Particle.publish("fuel-level", String(value));
   }
}  

please help me with it, as i am new to electron

Calling sleep from a Software Timer callback is not advisable.
Also calling delay() inside a SW Timer callback is a bad idea.

So can you please tell me what will be the correct approach. as in my code i want to sleep the device after X second (60 secs) for Y seconds (5 seconds).

I have modify the code a bit. i added SYSTEM_THREAD(ENABLED); in code and it seems device is not hanging but the event like:radio_on doesn’t show when i use: particle subscribe oni my linux machine.

If i try to publish any event in radio_down function it didn’t work

The timer callback runs on a separate thread with limited stack space, so you should not do any heavy lifiting in there (Particle.publish() would be considered that).

To be on the safe side treat a timer callback almost as careful as one would treat an ISR.

The common approach would be to extract the “heavy lifting” parts into a dedicated function, set a flag inside the timer callback and call the dedicated function from loop() when the state of that flag calls for it.

Thanks for help issue is resolved.