TCP/IP AT Command Set

This chapter introduces the TCP/IP AT command set. Adaptations may vary across different modules. For details, see Firmware Versions and Feature Differences.

AT+SOCKET create socket connection

Execute Command

Command:

AT+SOCKET=<type>[,<remote host>],<port>[,<keep alive>,<conID>]

Response:

OK

Parameters

  • <type>: Socket type.
    • 1: UDPServer

    • 2: UDPClient

    • 3: TCPServer

    • 4: TCPClient

    • 5: TCPSeed (placeholder type, not available; created when a client connects to the module’s TCP server; cannot be created actively)

    • 6: SSLServer

    • 7: SSLClient

    • 8: SSLSeed (placeholder type, not available; created when a client connects to the module’s SSL server; cannot be created actively)

  • <remote host>: Required when type is client; server domain name or IP to connect to. Not needed for server (skip directly, e.g. AT+SOCKET=3,10086)

  • <port>: When type is client, the server port to connect to; when type is server, the local port to listen on

  • <keep alive>: TCP keep-alive interval
    • 0: disabled

    • 1~7200: detection interval in seconds (reserved feature, not yet implemented)

  • <conID>: Specify ConID for the new connection

Description

  • Create a socket and initiate a connection.

Example

//UDPServer
AT+SOCKET=1,8001

//UDPClient
AT+SOCKET=2,192.168.31.239,23333

//TCPServer
AT+SOCKET=3,8888

//TCPClient
AT+SOCKET=4,192.168.31.239,60000

Query Command

Command:

AT+SOCKET?

Response:

<ConID>,<type>,<status>,<remote host>,<remote port>,<local port>,<server ConID>
OK

Parameters

  • <type>: Socket type.
    • 1: UDPServer

    • 2: UDPClient

    • 3: TCPServer

    • 4: TCPClient

    • 5: TCPSeed (locally created TCPServer; a TCPSeed is created when another user connects with TCPClient)

    • 6: SSLServer

    • 7: SSLClient

    • 8: SSLSeed (created when a client connects to the module’s SSL server)

  • <Status>: Connection status.
    • 1: Connected

    • 2: Disconnect

    • 3: Connecting

    • 4: ConnectFail

  • <remote host>: Remote address in client mode; not set in server mode

  • <remote port>: Remote port in client mode; not set in server mode, displays default -1

  • <local port>: Local listening port in server mode; not set in client mode, displays default -1

  • <server ConID>: When type is TCPSeed, indicates which TCP server created this connection; -1 for other types

Description

  • Note:

Example

AT+SOCKET?
1,4,3,192.168.31.239,60000,-1,0

OK

AT+SOCKETSEND send data via socket (long data mode)

Execute Command

Command:

AT+SOCKETSEND=<ConID>,<length>

Response:

OK

Parameters

  • <ConID>: Connection ID obtained after creating a SOCKET connection
    • Note: TCPServer connections cannot send data; only seeds created after a client connects to TCPServer can send. UDP server must receive client data first; the send target is the first received client

  • <length>: Length of data to send
    • After the command completes, a “>” is displayed. After receiving this symbol, start entering data to send (any HEX data allowed, not limited to strings). Data transmission starts after length bytes are received.

Description

  • Send data to the specified connection. After the command completes, a “>” appears on the second line. After this symbol appears, data input can begin (any data allowed). After length bytes are received, reception stops and transmission starts (if length exceeds the maximum packet size, data is split; default split threshold is 1024 bytes). Feature: this mode supports arbitrary-length data (long data is split) and accepts any characters.

Example

AT+SOCKETSEND=1,3
>123
OK

AT+SOCKETSENDLINE send data via socket (single-line mode)

Execute Command

Command:

AT+SOCKETSENDLINE=<ConID>,<length>,<data>

Response:

OK

Parameters

  • <ConID>: Connection ID obtained after creating a SOCKET connection
    • Note: TCPServer connections cannot send data; only seeds created after a client connects to TCPServer can send. UDP server must receive client data first; the send target is the first received client

  • <length>: Length of data to send.

  • <data>: Data content

Description

  • Send data to the specified connection. Feature: simpler to use but length-limited (maximum AT command length). Wrap the entire parameter in double quotes if it contains special characters; escape double quotes within the parameter.

Example

AT+SOCKETSENDLINE=2,10,1234567890

OK

AT+SOCKETREAD read data from socket

Execute Command

Command:

AT+SOCKETREAD=<ConID>

Response:

OK

Parameters

  • <ConID>: Connection ID obtained after creating a SOCKET connection
    • Note: TCPServer connections cannot send/receive data; only seeds created after a client connects to TCPServer can. UDP Client must send data once so the server learns the local port before sending to that UDP client.

Description

  • Read data from the specified connection. Note: reads are packet-based; one packet per read.

Example

+EVENT:SocketDown,1,21
AT+SOCKETREAD=1
+SOCKETREAD,1,21,Hello From TCP Server
OK

AT+SOCKETDEL delete specified socket connection

Execute Command

Command:

AT+SOCKETDEL=<ConID>

Response:

OK

Parameters

  • <ConID>: Connection ID to delete.

Description

  • Delete the specified socket connection. Note: seeds are client-initiated and the server cannot reconnect, so manually delete the connection after a seed disconnects (received data is also cleared).

Example

AT+SOCKETDEL=1

OK

AT+SOCKETRECVCFG set socket receive mode

Execute Command

Command:

AT+SOCKETRECVCFG=<mode>

Response:

OK

Parameters

  • <mode>:

    • 0: Passive mode (default); on data receipt, only prints +EVENT:SocketDown,<ConID>,<length> without data content

    • 1: Active mode; received socket data is printed directly as +EVENT:SocketDown,<ConID>,<length>,<date>

Description

  • Set the print mode for received socket data

Example

AT+SOCKETRECVCFG=0

OK

AT+SOCKETTT enter socket transparent transmission mode

Execute Command

Command:

AT+SOCKETTT

Response:

> //收到这个表示透传开启了,可以收发数据了
OK //连续输入三个加号+++会退出透传,透传退出时打印\r\nOK\r\n

Description

  • Transparent transmission mode requires one of the following conditions
    • Only one client connection exists (transparent transmission via client)

    • Only one server and one seed connection exist (transparent transmission via seed created when client connects to module server; must be entered manually, cannot auto-enter)

    • Only one UDPClient exists

    • Only one UDPServer exists (Note: UDP server transparent transmission is not recommended; default target is the first connected client; other connections may cause incorrect transparent transmission targets)

  • Enter +++ to exit transparent transmission mode and enter AT command mode

Example

AT+SOCKET=4,192.168.31.98,18 //创建 tcp client
connect success ConID=1
OK

AT+SOCKETTT //进入透传模式
>send to module //此时发送的数据会透传到目标,目标发送的数据会透传到本地
OK //当输入连续的三个加号后退出透传模式

Execute Command

Command:

// UDPServerTTMode:设置 UDP server 透传模式
AT+SOCKETTT=UDPServerTTMode

Response:

> //收到这个表示透传开启了,可以收发数据了
OK //连续输入三个加号+++会退出透传,透传退出时打印\r\nOK\r\n

Parameters

  • <UDPServerTTMode>: UDP server transparent transmission mode

    • 0: Transparent transmission target is fixed to the first communicating client; subsequent clients do not change the target

    • 2: Transparent transmission target dynamically changes to the last communicating client

Description

  • Enter SOCKET transparent transmission mode. Note: UDP server default target is the first communicating client.

Example

AT+SOCKETTT=2

AT+SOCKETAUTOTT auto-enter socket transparent transmission configuration

Execute Command

Command:

AT+SOCKETAUTOTT=<type>[,<remote host>],<port>

Response:

OK

Parameters

  • <type>: Socket type
    • 0: Disable auto-enter transparent transmission mode

    • 1: Auto-enter UDPServer transparent transmission mode

    • 2: Auto-enter UDPClient transparent transmission mode

    • 3: Placeholder type, not available

    • 4: Auto-enter TCPClient transparent transmission mode

    • 5: Placeholder type, not available

    • 6: Placeholder type, not available

    • 7: Auto-enter SSLClient transparent transmission mode

    • 8: Placeholder type, not available

  • <remote host>: Required when type is client; server domain name or IP. Not needed for server (skip, e.g. AT+SOCKETAUTOTT=1,10086)

  • <port>: When type is client, the server port to connect to; when type is server, the local port to listen on

Description

  • After creating the corresponding socket connection, automatically enter transparent transmission mode. After configuration, use with AT+WAUTOCONN; takes effect after reset. On power-up: auto-connect Wi-Fi (AT+WAUTOCONN) -> auto-create socket after Wi-Fi connects -> auto-enter transparent transmission mode (this command).

Example

AT+SOCKETAUTOTT=4,192.168.31.239,60000

OK

Query Command

Command:

AT+SOCKETAUTOTT?

Response:

+SOCKETAUTOTT:<type>,<remote host>,<remote port>
OK

Parameters

  • <type>: Socket type
    • 0: Disable auto-enter transparent transmission mode

    • 1: Auto-enter UDPServer transparent transmission mode

    • 2: Auto-enter UDPClient transparent transmission mode

    • 3: Placeholder type, not available

    • 4: Auto-enter TCPClient transparent transmission mode

    • 5: Placeholder type, not available

    • 6: Placeholder type, not available

    • 7: Auto-enter SSLClient transparent transmission mode

    • 8: Placeholder type, not available

  • <remote host>: Required when type is client; server domain name or IP. Not needed for server (skip, e.g. AT+SOCKETAUTOTT=1,10086)

  • <remote port>: When type is client, server port to connect to; when type is server, local listening port

  • <local port>: Local listening port in server mode; not set in client mode, displays default -1

Description

  • Query current auto transparent transmission configuration

Example

AT+SOCKETAUTOTT?

+SOCKETAUTOTT:4,192.168.31.239,60000
OK

AT+SSLCRET query and set SSL certificate

Execute Command

Command:

AT+SSLCRET=<type>[,<length>]

Response:

> //收到这个符号表示可以开始写证书了
OK

Parameters

  • <type>: Certificate type to operate on.
    • 1: CA root certificate

    • 2: Client public key

    • 3: Client private key

  • <length>: Certificate length. Omit to query the certificate; include to set certificate length

Description

  • Query and set SSL certificate. One parameter queries current certificate; two parameters set certificate. Empty certificate means client does not load certificate and obtains automatically.

Example

//设置证书
AT+SSLCRET=1,10
>1234567890
OK

//查询证书
AT+SSLCRET=1
+SSLCRET:1,10,1234567890
OK

AT+WDOMAIN query domain IP address via DNS resolution

Execute Command

Command:

AT+WDOMAIN=<server name>

Response:

+WDOMAIN:<IP>

OK

Example

AT+WDOMAIN=www.baidu.com
+WDOMAIN:14.119.104.189
OK

AT+WDNS query/set DNS resolution servers

Query Command

Description

  • Query DNS resolution servers

Command:

AT+WDNS?

Response:

+WDNS:<DNS IP1>,<DNS IP2>
OK

Example

AT+WDNS?
+WDNS:192.168.3.1,0.0.0.0
OK

Execute Command

Description

  • Set DNS resolution servers

Command:

AT+WDNS=<"DNS IP1">[,<"DNS IP2">]

Response:

+WDNS:<DNS IP1>[,DNS IP2]
OK

Parameters

  • <DNS IP1/DNS IP2>: DNS resolution servers

Example

AT+WDNS=114.114.114.114

+WDNS:114.114.114.114
OK