Sleep and Wake-up Service

Last Updated on : 2025-02-18 01:59:52download

This topic describes how to implement the sleep and wake-up service.

Select low power mode

  • Modules support four working modes: always-powered, power-off, deep sleep, and keep-alive (set the dtm to 10).
  • The always-powered mode is used by default. If you want the device to work in low power mode, you can configure the sm field in the Query product information command.
  • If you want the device to be always online in power-off mode or deep sleep mode, you must enable the always online in low power mode capability for the specific product ID (PID).

Power-off

Set sm to 0. The MCU controls the module’s power-on and power-off logic.

Deep sleep

Set sm to 1. Also, you need to configure wk and wkp to wake up the module. If the wake-up GPIO (wk) is at an active level, the module will not enter sleep mode. If the wake-up GPIO (wk) is at an inactive level, check whether an OTA update (or file download) task is in progress. If no OTA update (or file download) task is in progress, the module enters sleep mode. When the module is woken up after sleeping in this mode, it will restart.

Keep-alive

Set sm to 2. Also, you need to configure wk and wkp to wake up the module.

  • If the wake-up GPIO (wk) is at an active level, the module will not enter sleep mode.
  • If the wake-up GPIO (wk) is at an inactive level, check whether an OTA update (or file download) task is in progress.
    If no OTA update (or file download) task is in progress, the MCU is notified to enter sleep and the serial port communication is closed. To wake up the module, the MCU pulls the wake-up GPIO (wk) to an active level. The MCU can communicate with the module only after receiving the module’s wake-up status notification. If the MCU supports sleep mode, you can configure mwk and mwkpt to allow the module to wake up the MCU.

Things to note

  • In low power mode (power-off, deep sleep, and keep-alive), Bluetooth is only used for pairing. Control over a local area network (LAN), control over Bluetooth, and Bluetooth remote control features are unavailable. Pair over Bluetooth due to unavailable Wi-Fi is not supported.
  • In keep-alive mode, the self-processing working mode is not supported (after the device enters sleep mode, the peripherals will be turned off, and the buttons and LEDs will not work properly).
  • In keep-alive mode, disable the application Wi-Fi low power logic (by setting the low field).
  • In keep-alive mode, after the module enters sleep mode, the serial port will be closed. If the MCU wants to communicate with the module, it must first set the wake-up GPIO to an active level and wait for the module’s wake-up notification before communicating with the module via the serial port.
  • In keep-alive mode, it is recommended to set the query product information field m to 1 and use timeout pairing to reduce standby power consumption.
  • After waking up from deep sleep mode, the module restarts without any wake-up notification.

Commands

The following table lists commands used in the sleep and wake-up service.

Command Description
0x91 (subcommand: 0x00) Send a sleep status notification
0x91 (subcommand: 0x01) Send a wake-up status notification
0x91 (subcommand: 0x02) Request to enter sleep mode

Send a sleep status notification (0x9100)

Notify the MCU that the module will enter sleep mode, and the MCU will reply whether the module can enter sleep mode. If the MCU does not return a response, the module will automatically enter sleep mode after five seconds.

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x91
Data length 2 0x0001
Data 1 Subcommand: 0x00
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x91
Data length 2 0x0002
Data 1 Subcommand: 0x00
1
  • 0: Do not allow sleep. There is still data to be synchronized. Wait for 5 seconds.
  • 1: Allow sleep. Enter sleep immediately.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Send a wake-up status notification (0x9101)

After being woken up, the module proactively sends the wake-up status to the MCU.

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x91
Data length 2 0x0001
Data 1 Subcommand: 0x01
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x91
Data length 2 0x0001
Data 1 Subcommand: 0x01
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Request the module to enter sleep mode (optional) (0x9102)

The MCU can use this command to quickly request the module to enter sleep mode.

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x91
Data length 2 0x0001
Data 1 Subcommand: 0x02
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The module returns the following data.

Field Length Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x91
Data length 2 0x0002
Data 1 Subcommand: 0x02
1 The 8 bits in 1 byte indicate different tasks. 0 means allowing to enter sleep mode, and the device will enter sleep mode after one second. Other bits indicate that a task is being processed and sleep is not allowed. Please try again after five seconds.
  • Bit 0: The wake-up GPIO is not set to an inactive level. 1: A task is being processed. 0: No task is being processed.
  • Bit 1: An over-the-air (OTA) update task. 1: A task is being processed. 0: No task is being processed.
  • Bit 2: Sync the device status. 1: A task is being processed. 0: No task is being processed.
  • Bit 3: Other tasks. 1: A task is being processed. 0: No task is being processed.
  • Bit 4 to bit 7: reserved, populated with 0.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.