TCP/IP AT command set

This chapter introduces the driver TCP/IP command set. This command set will be adapted differently for different modules. For specific differences, please move to:Firmware iterations and differences

AT+SOCKET Creates 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, this type is generated when the client connects to the module tcp server and cannot be created actively)

    • 6:SSLServer

    • 7:SSLClient

    • 8:SSLSeed(placeholder type, not available, this type is generated when the client connects to the module ssl server and cannot be created actively)

  • <remote host>:this parameter is required when type is the client, indicating the domain name or IP of the server to be connected. no setting is required when server is used (skip directly, eg:AT + SOCKET = 3,10086)

  • <port>:indicates the port number of the server to be connected when type is the client, and indicates the port number to be monitored by the local server when type is the server.

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

    • 1~7200 indicates detection interval, unit: second (reserved function, not implemented for the time being)

  • <conID>:specifies the ConID of 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 socket type.
    • 1:UDPServer

    • 2:UDPClient

    • 3:TCPServer

    • 4:TCPClient

    • 5:TCPSeed(for locally created TCPServer, another user will generate a TCPSeed after connecting with the tcpclient)

    • 6:SSLServer

    • 7:SSLClient

    • 8:SSLSeed(a SSLSeed will be created when ssl server with client connection module is generated)

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

    • 2:Disconnect

    • 3:Connecting

    • 4:ConnectFail

  • <remote host>:the remote address of the client mode connection. the server mode is not set yet.

  • <remote port>:the remote port connected in client mode. the server mode is not set yet. the default value -1 is displayed.

  • <local port>:the server mode displays the local listening port, the client mode is not set yet, and the default value -1 is displayed.

  • <server ConID>:when type is TCPSeed, this indicates which tcp server the connection was created from. the default for other types is -1

Description

  • Note:

Example

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

OK

AT+SOCKETSEND Sends Data via socket (Long Data Mode)

Execute command

Command:

AT+SOCKETSEND=<ConID>,<length>

Response:

OK

Parameters

  • <ConID>:the connection ID obtained after creating the SOCKET connection.
    • Note:The TCPServer connection cannot be sent, and data can only be sent to the seed created after the client connects to the TCPServer; UDP server must receive the client data before sending it. The sending object is the object that received the data for the first time.

  • <length>: the length of the data to be sent
    • after the instruction is executed, a ”>” will be displayed. after receiving this symbol, you can start inputting the data to be sent (you can enter any HEX data, not limited to strings). when you receive length data, you can start sending data.

Description

  • send data to the specified connection. when the instruction is executed, a “>” symbol will appear in the second line. after this symbol appears, you can start inputting data (you can enter any data without limiting the data content). when you receive length bytes of data, you will stop receiving and start sending (if the length exceeds the maximum length of a single packet, the data will be subcontracted, by default, data will be subcontracted after exceeding 1024 bytes) Features: This mode can send data of any length (super-long will be subcontracted) and can receive any character

Example

AT+SOCKETSEND=1,3
>123
OK

AT + SOCKETSENDLINE Sends Data via socket (Single Row Mode)

Execute command

Command:

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

Response:

OK

Parameters

  • <ConID>:the connection ID obtained after creating the SOCKET connection.
    • Note: The TCPServer connection cannot be sent, and data can only be sent to the seed created after the client connects to the TCPServer; UDP server must receive the client data before sending it. The sending object is the object that received the data for the first time.

  • <length>:the length of the data to be sent.

  • <data>:data content

Description

  • Features of sending data to a specified connection: This mode is relatively simple to use, but the length is limited (the maximum length of an AT instruction is limited). If there are special characters, the entire parameter needs to be enclosed in double quotation marks. If there are double quotation marks in the parameter, escape characters need to be added.

Example

AT+SOCKETSENDLINE=2,10,1234567890

OK

AT+SOCKETREAD reads data from socket

Execute command

Command:

AT+SOCKETREAD=<ConID>

Response:

OK

Parameters

  • <ConID>:ConID: the connection ID obtained after creating the SOCKET connection

    -Note that the TCPServer connection cannot send and receive data, and only the seed created after the client connects to the TCPServer can send and receive data; UDP Client needs to send data once before the server obtains the local port before sending data to the upd client.

Description

  • Read data from the specified connection. Note: When reading, it is read by package, one packet of data at a time.

Example

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

AT+SOCKETDEL deletes the specified socket connection

Execute command

Command:

AT+SOCKETDEL=<ConID>

Response:

OK

Parameters

  • <ConID>:the connection ID to delete.

Description

  • Deletes the specified socket connection. Note: because seed is initiated by the client and the server cannot be reconnected, the connection needs to be deleted manually after seed is disconnected (the data received after deleting the connection will also be cleared)

Example

AT+SOCKETDEL=1

OK

AT+SOCKETRECVCFG Set socket Receiving Mode

Execute command

Command:

AT+SOCKETRECVCFG=<mode>

Response:

OK

Parameters

  • <mode>

    • 0:Passive mode (default), in this mode, printing only prompts+EVENT:SocketDown,<ConID>,<length> does not print data content after receiving data

    • 1:Active mode, in which socket data is received, the received data is directly printed in the following format+EVENT:SocketDown,<ConID>,<length>,<date>

Description

  • Set the print mode for socket to receive data

Example

AT+SOCKETRECVCFG=0

OK

AT+SOCKETTT enters socket transparent mode

Execute command

Command:

AT+SOCKETTT

Response:

> // receiving this means that transparent transmission is turned on and data can be sent and received.
OK //continuous input of three plus sign +++ will exit transparent transmission, print \r\nOK\r\n when transparent transmission exits

Description

  • Entering transparent mode must meet any of the following conditions
    • Currently, there is only one client connection (via client pass-through)

    • There is only one server and one seed connection (the seed can be transmitted through the client connected to the module server. This mode must be entered manually and cannot be entered automatically)

    • There is only one UDPClient

    • There is only one UDPServer (note that UDP server is not recommended for transparent transmission mode. The default transparent transmission object is the client side of the first connection. If other connections initiate communication to the module, it may cause errors in subsequent transparent transmission objects)

Example

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

AT+SOCKETTT //Enter Transparent Mode
>send to module // the data sent at this time will be transmitted to the target, and the data sent by the target will be transmitted to the local
OK // Exit transparent mode after entering three consecutive plus marks

Execute command

Command:

// UDPServerTTMode: Set UDP server Transparent Mode
AT+SOCKETTT=UDPServerTTMode

Response:

> // receiving this means that transparent transmission is turned on and data can be sent and received.
OK //continuous input of three plus sign +++ will exit transparent transmission, print \r\nOK\r\n when transparent transmission exits

Parameters

  • <UDPServerTTMode>:UDP server transparent mode

    • 0:The transparent transmission object is fixed as the client for the first communication, and other client communication will not change the communication object.

    • 2:The transparent object will be dynamically modified as the client of the last communication

Description

  • Enter SOCKET transparent mode. Note: The default pass-through object of UDP server is the client client for the first communication.

Example

AT+SOCKETTT=2

AT+SOCKETAUTOTT automatically enters socket transparent transmission configuration

Execute command

Command:

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

Response:

OK

Parameters

  • <type>:socket socket type
    • 0:Disable automatic transparent transmission mode

    • 1:Automatically enter UDPServer transmission mode

    • 2:Automatically enter UDPClient transmission mode

    • 3:Occupancy type, not available

    • 4:Automatically enter TCPClient transmission mode

    • 5:Occupancy type, not available

    • 6:Occupancy type, not available

    • 7:Automatically enter SSLClient transmission mode

    • 8:Occupancy type, not available

  • <remote host>:When the type is client, this parameter is mandatory, indicating the domain name or IP of the server to be connected, and it is not necessary to set it for server (skip this parameter, eg:AT+SOCKETAUTOTT=1,10086)

  • <port>:When type is client, it indicates the port number of the server to be connected, when type is server, it indicates the port number that the local server needs to monitor

Description

  • After creating the corresponding socket connection, it will automatically enter the transmission mode. After the command is set, it needs to be used with AT+WAUTOCONN. After the configuration is completed, the reset will take effect. Automatically connect to Wi-Fi after power-on (AT+WAUTOCONN configuration) automatically create a socket connection after a successful Wi-Fi connection, and automatically enter transmission mode after a successful socket creation (set by 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 automatic transparent transmission mode

    • 1:Automatically enter UDPServer transmission mode

    • 2:Automatically enter UDPClient transmission mode

    • 3:Occupancy type, not available

    • 4:Automatically enter TCPClient transmission mode

    • 5:Occupancy type, not available

    • 6:Occupancy type, not available

    • 7:Automatically enter SSLClient transmission mode

    • 8:Occupancy type, not available

  • <remote host>:When the type is client, this parameter is mandatory, indicating the domain name or IP of the server to be connected, and it is not necessary to set it for server (skip this parameter, eg:AT+SOCKETAUTOTT=1,10086)

  • <remote port>:When type is client, it indicates the port number of the server to be connected, when type is server, it indicates the port number that the local server needs to monitor

  • <local port>:The server mode shows the local listening port, the client mode has not been set yet, and the default value -1 is displayed

Description

  • Query the current automatic transparent transmission configuration information

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:

> // Receiving this symbol indicates that you can start writing certificates
OK

Parameters

  • <type>:the certificate type of the operation.
    • 1:CA root certificate

    • 2:Client Public Key

    • 3:Client Private Key

  • <length>:the certificate length. if this parameter is omitted, the corresponding certificate is queried. if this parameter is included, the certificate length is set.

Description

  • Query and set the SSL certificate. When there is only one parameter, it means to query the content of the currently set certificate. When there are two parameters, it means that the certificate needs to be set. When the certificate is empty, the client does not load the certificate and obtains it automatically

Example

//Set Certificate
AT+SSLCRET=1,10
>1234567890
OK

// Query certificate
AT+SSLCRET=1
+SSLCRET:1,10,1234567890
OK

AT+WDOMAIN Query the IP address of a domain name by resolving it on the DNS server

executive command

command:

AT+WDOMAIN=<server name>

response:

+WDOMAIN:<IP>

OK

example

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

AT+WDNS Example Query or set the DNS server

inquiry command

describe

  • Querying the DNS resolution server

command:

AT+WDNS?

response:

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

example

AT+WDNS?
+WDNS:192.168.3.1,0.0.0.0
OK

executive command

describe

  • Set the DNS domain name resolution server

command:

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

response:

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

parameter

  • <DNS IP1/DNS IP2>:Domain name resolution server

example

AT+WDNS=114.114.114.114

+WDNS:114.114.114.114
OK