Xinyuan-LilyGO / LilyGo-T-SIM7080G

42 stars 22 forks source link

No ">" prompt following +CASEND after wakeup from sleep (DRX) #48

Closed btuysser closed 3 weeks ago

btuysser commented 3 months ago

My project is based on MinimalModemNBIOTExample. I am transmitting a ~28 byte UDP datagram every 60s and I want the modem to sleep. I am using DRX as opposed to eDRX or PSM due to future requirements.I added some UDP code (as that is not supported by TinyGSM), set +SCLKC=1 and I'm controlling DTR. The code was compiled with (-DARDUINO_USB_CDC_ON_BOOT=0) and the board is connected to a wall power supply. No UART connection.

In the setup function I acquire NB-IOT, register and open a UDP connection.

Here is my loop function and a modifed TinyGsmSim7080::modemSend :

 int16_t modemSend(const void* buff, size_t len, uint8_t mux) {

    while(waitResponse(5,GF(">")) != 1) {
      sendAT(GF("+CASEND="), mux, ',', (uint16_t)len);
    }

    stream.write(reinterpret_cast<const uint8_t*>(buff), len);
    stream.flush();

    // OK after posting data
    if (waitResponse() != 1) { return 0; }

    return len;
  }

void loop()
{
    static int cnt = 0;
    long t0 = millis();
    // pull DTR low in case we were sleeping
    digitalWrite(BOARD_MODEM_DTR_PIN, LOW);
    // send UDP datagram
    modem.modemSend(msg.c_str(), msg.length(), 0);
    // get to rrc idle asap
    modem.sendAT("+CRAI=1");
    modem.waitResponse(5);
    // we can go back to sleep now
    digitalWrite(BOARD_MODEM_DTR_PIN, HIGH);
    Serial.printf("\n\r--------------  SLEEP AFTER %d --------------\n\r", millis() - t0);
    delay(60000);
}

When I call +CASEND immediately after wakeup there is no ">" prompt in the modem serial stream. I added retries in the modemSend method and with a timeout of 5ms it takes 3 tries to get a ">" prompt. This results in an awake time of ~24ms instead of an ideal ~15ms. When increasing the waitResponse timeout to 50ms I would expect the number of tries to go down but it remains between 1 and 3 tries for an awake time of 65-117ms.

Another workaround is to add a 300ms delay after pulling DTR low but the impact on awake time is unacceptable.

Am I doing anything wrong or have others come across this issue?

Log :

AT+CPSI?
+CPSI: LTE NB-IOT,Online,310-260,0xF300,7573966,450,EUTRAN-BAND4,2038,0,0,-11,-98,-87,13
OK

AT+CSCLK=1
OK
AT+CACLOSE=0

AT+CACID=0
OK

AT+CAOPEN=0,0,"UDP","<IP>",<PORT>
OK

AT+CASEND=0,26
>012345678 UDP test Count 0 
OK
AT+CRAI=1
OK

--------------  SLEEP AFTER 21 ms --------------
AT+CASEND=0,26
AT+CASEND=0,26
AT+CASEND=0,26
>012345678 UDP test Count 1 
OK
AT+CRAI=1
OK
--------------  SLEEP AFTER 32 ms --------------
AT+CASEND=0,26
AT+CASEND=0,26
AT+CASEND=0,26
>012345678 UDP test Count 2 
OK
AT+CRAI=1
OK
--------------  SLEEP AFTER 32 ms --------------
.....
btuysser commented 3 months ago

Firmware Revision : 1951B12SIM7080

lewisxhe commented 3 months ago

Are you referring to the wake-up reaction time being too long?

btuysser commented 3 months ago

Since there is almost no information in the low power application note I hoped that the wakeup reaction time would be be transparent to the user. After pulling DTR low I expected the modem to execute any serial command after finishing its own internal wakeup sequence.

If that is not the case then how does a user determine the earliest time it's safe to interact with the modem (in this case sending a UDP packet via +CASEND)?

btuysser commented 2 months ago

Would it be possible to extend the MinimalModemSleepMode.ino example by doing multiple sleeps?

My current sequence is

I just don't know if this is the optimal sequence.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 3 weeks ago

This issue was closed because it has been inactive for 14 days since being marked as stale.