AT Response Message Format Control Examples

[中文]

Enable the system message filter to download files in HTTP passthough mode

This example describes how to download an image file in PNG format. The image link is https://www.espressif.com/sites/default/files/home/hardware.png.

  1. Restore your device to factory settings.

    Command:

    AT+RESTORE
    

    Response:

    OK
    
  2. Set the Wi-Fi mode to station.

    Command:

    AT+CWMODE=1
    

    Response:

    OK
    
  3. Connect to the router.

    Command:

    AT+CWJAP="espressif","1234567890"
    

    Response:

    WIFI CONNECTED
    WIFI GOT IP
    
    OK
    

    Note:

    • The SSID and password you entered may be different from those in the above command. Please replace the SSID and password with those of your router settings.

  4. Configure the first system message filter to filter out the header and tail from each HTTP data.

    Command:

    AT+SYSMSGFILTERCFG=1,18,3
    

    Response:

    OK
    
    >
    

    Enter ^+HTTPCGET:[0-9]*, (18 bytes in total) and \r\n$ (3 bytes in total, the \r\n character corresponds to carriage return and line feed character, i.e. 0D 0A). Response:

    OK
    

    Note:

    • ^+HTTPCGET:[0-9]*, is the regular expression for headers. It means the string starts with +HTTPCGET:, followed by a string of numbers, and ends with a comma.

    • \r\n$ is the regular expression of tail. It means the string ends with \r\n.

  5. Configure the second system message filter to filter out the OK system message returned after the picture is downloaded.

    Command:

    AT+SYSMSGFILTERCFG=1,0,7
    

    Response:

    OK
    
    >
    

    At this time, enter \r\nOK\r\n$ (7 bytes in total, where \r\n corresponds to line feed and carriage return in ASCII code, i.e. 0D 0A). Response:

    OK
    

    Note:

    • \r\nOK\r\n$ is the regular expression for tails. It means the string ends with \r\nOK\r\n.

  6. Enable system message filter

    Command:

    AT+SYSMSGFILTER=1
    

    Response:

    OK
    

    Note:

    • The filters set above will take effect only after system message filtering is enabled.

  7. Turn off echo

    Command:

    ATE0
    

    Response:

    OK
    
  8. Download the picture

    Set the sending and receiving buffer size to 2048 bytes, and set the network timeout to 5000 ms. Note that the network timeout is not the command timeout. The 5-second network timeout means closing the network connection if no data is received from the server side for 5 consecutive seconds. In a poor network environment where the server-side data is received every second, the network connection will not be closed, resulting in a long command timeout.

    Command:

    AT+HTTPCGET="https://www.espressif.com/sites/default/files/home/hardware.png",2048,2048,5000
    

    Response:

    // Here, the MCU transparently receives the entire picture resource from https://www.espressif.com/sites/default/files/home/hardware.png.
    

    Note:

    • If the picture download fails, AT will still send a \r\nERROR\r\n (9 bytes in total) system message to MCU.

  9. Clear the filter

    Command:

    AT+SYSMSGFILTERCFG=0
    

    Response:

    OK
    
  10. Disable the system message filter

    Command:

    AT+SYSMSGFILTER=0
    

    Response:

    OK
    
  11. Switch echo on

    Command:

    ATE1
    

    Response:

    OK