BSD Socket AT Commands#
Commands#
socket#
Create a BSD socket to establish a TCP or UDP connection.
Command Format#
at+socket=<domain>,<type>,<protocol>Related SDK API
socket API of WiSeConnect SDK
Pre-conditions#
None
Parameters#
domain#
The addressing domain used by the socket. Contains a numeric value that corresponds to one of the values of the BSD standard Socket Address Family macros. Note some values are not currently supported, as indicated in the linked documentation.
type#
The type of socket to be opened. Contains a numeric value that corresponds to one of the values of the BSD standard Socket Type macros. Note some values are not currently supported, as indicated in the linked documentation.
Note: A value of 1 (SOCK_STREAM) is used to open TCP sockets, and 2 (SOCK_DGRAM) to open UDP sockets.
protocol#
The protocol to be used for the specified type. Contains a numeric value that corresponds to one of the values of the BSD standard Socket Protocol macros. Note some values are not currently supported, as indicated in the linked documentation.
Response#
OK <socket id>in case of success, wheresocket idis the BSD standard unique numeric socket identifier returned by the socket API of the WiSeConnect SDK. Thesocket idis passed in subsequent socket-related commands to operate on the specific socket just created.ERROR <error code>in case of failure, whereerror codecorresponds to one of the BSD standarderrnovalues set by the socket API of the WiSeConnect SDK.
Examples#
at+socket=2,1,6 # Create a TCP socket
OK 1setsockopt#
Configure options for a specific socket or at the TCP protocol level.
Command Format#
at+setsockopt=<socket-id>,<option-level>,<option>,<option-value-1>,<option-value-2>,...Related SDK API
setsockopt API of WiSeConnect SDK
Pre-conditions#
None
Parameters#
socket-id#
The unique BSD standard numeric socket identifier returned by the socket command.
option-level#
The level at which the option or parameter is to be set (that is, for the specific socket or at the TCP protocol level). Contains a numeric value that corresponds to one of the values of the BSD standard Socket Option Level macros.
option#
The specific option to be configured. Contains a numeric value that corresponds to one of the values of the BSD standard Socket Option Name macros. Out of these, only a few options are supported by the WiSeConnect SDK setsockopt API as indicated in the linked documentation (option is referred to as option_name in the linked documentation). Out of the option's supported by the WiSeConnect SDK setsockopt API, the following are supported with AT commands:
SO_RCVTIMEOSO_KEEPALIVESO_MAX_RETRAINSMISSION_TIMEOUT_VALUETCP_ULPSL_SO_HIGH_PERFORMANCE_SOCKET(this is a Silicon Labs-specific option)SL_SO_SOCK_VAP_ID(Associate the socket with a specific interface)
option-value-n#
One or more option-value parameters specifying the value to be set for the specified option. Tbe number of option-value parameters depends on the option specified. See the WiSeConnect SDK setsockopt API documentation for the option-value that can be set for each supported option (referred to as option_name in the linked documentation).
When option is set to
SO_RCVTIMEO, the followingoption-values are passed:<seconds>,<microseconds>(see example below) where:secondsis the seconds portion of the socket receive timeout,microsecondsis the microseconds portion of the socket receive timeout
For all other options, only one
option-valueis passed as described in the WiSeConnect SDK's setsockopt API documentation.
Response#
OKon successERROR <error code>in case of failure, where<error code>corresponds to one of the BSD standarderrnovalues set by the setsockopt API of the WiSeConnect SDK.
Examples#
at+setsockopt=1,65535,8,30 # Configure Keep Alive to 30 seconds for Socket ID 1
at+setsockopt=1,65535,4102,5,500000 # Configure Socket Receive Timeout to 5.5 seconds for Socket ID 1 connect#
Establish a client connection over a socket.
Command Format#
at+connect=<socket-id>,<remote-ip-address>,<remote-port>Related SDK API
connect API of WiSeConnect SDK
Pre-conditions#
None
Parameters#
socket-id#
The unique BSD standard numeric socket identifier returned by the socket command.
remote-ip-address#
A string specifying the IPv4 or IPv6 address of the remote host to connect to. The type of address (IPv4 or IPv6) should correspond to the domain value specified in the socket command.
remote-port#
A number specifying the port number of the remote host to connect to.
Response#
OKon successERROR <error code>in case of failure, where<error code>corresponds to one of the BSD standarderrnovalues set by the connect API of the WiSeConnect SDK.
Examples#
at+connect=1,"192.168.10.14",1024 # Connect over Socket ID 1 to remote host 192.168.10.14 to remote port 1024
OKsend#
Send data over a connected socket.
Command Format#
at+send=<socket-id>,<remote-ip-address>,<remote-port>,<data-length>[,<data>]Related SDK API
send API of WiSeConnect SDK
Pre-conditions#
None
Parameters#
socket-id#
The unique BSD standard numeric socket identifier returned by the socket command.
remote-ip-address#
Optional. A string specifying the IPv4 or IPv6 address of the remote host to send data to a UDP socket. The type of address (IPv4 or IPv6) should correspond to the domain value specified in the socket command.
remote-port#
Optional. A number specifying the port number of the remote host to send data to over a UDP socket.
data-length#
The length of the data to be transmitted in bytes.
data#
Optional. Must contain data-length number of bytes of data to send over the socket. This must not contain a carriage return-line feed (CR-LF) sequence as it will result in terminating the command.
Response#
When the
dataparameter is provided, the send API is invoked and one of the following responses is returned:OK <bytes-sent>on success, where<bytes-sent>is the number of bytes successfully sentERROR <error-code>in case of failure, where<error-code>corresponds to one of the BSD standarderrnovalues set by the send API of the WiSeConnect SDK
When the
dataparameter is omitted, the SiWx91x device enters data mode and sends one of the following responses:ERROR 1on failing to enter data modeOKon successfully entering data modeOn receiving this response, you must transmit
data-lengthnumber of charactersAs soon as the given number of characters are transmitted, the send API will be invoked and one of the aforementioned responses is sent back (see the first bullet point above).
Examples#
# Send 5 bytes to the remote TCP host over Socket ID 1 using data mode
at+send=1,,,5
OK
# Transmit 5 characters of data (e.g., "Hello")
OK 5
# Send 5 bytes to the remote TCP host over Socket ID 1 with data parameter (immediate send)
at+send=1,,,5,Hello
OK 5
# Send 5 bytes to the remote UDP host 192.168.10.1 over port 2000 over Socket ID 2 using data mode
at+send=2,"192.168.10.1",2000,5
OK
# Transmit 5 characters of data (e.g., "Hello")
OK 5
# Send 5 bytes to the remote UDP host 192.168.10.1 over port 2000 over Socket ID 2 with data parameter (immediate send)
at+send=2,"192.168.10.1",2000,5,Hello
OK 5recv#
Receive data from a connected socket.
Command Format#
at+recv=<socket-id>[,<remote-ip-address>][,<remote-port>],<bytes-to-read>,<flags>Related SDK API
recv API of WiSeConnect SDK
Pre-conditions#
None
Parameters#
socket-id#
The unique BSD standard numeric socket identifier returned by the socket command.
remote-ip-address#
Optional. A string specifying the IPv4 or IPv6 address of the remote host to receive data from over a UDP socket. The type of address (IPv4 or IPv6) should correspond to the domain value specified in the socket command.
remote-port#
Optional. A number specifying the port number of the remote host to receive data from over a UDP socket.
bytes-to-read#
The number of bytes to read from the socket.
flags#
Reserved. Currently ignored if specified. This will be used in future to specify data receive options.
Response#
OK <data-length> <data>on success, wheredata-lengthis the number of bytes received anddatais the received data.datais not terminated by aCR-LFsequence but instead contains exactlydata-lengthnumber of characters.ERROR <error-code>in case of failure, where<error-code>corresponds to one of the BSD standarderrnovalues set by therecvAPI of the WiSeConnect SDK.
Examples#
at+recv=1,,,50,0 # Receive up to 50 bytes from connected socket ID 1 (TCP)
OK 11 Hello World
at+recv=2,"192.168.1.100",2000,50,0 # Receive up to 50 bytes from UDP socket ID 2 at 192.168.1.100:2000
OK 11 Hello Worldclose#
Close a TCP or UDP socket.
Command Format#
at+close=<socket>Related SDK API
close API of WiSeConnect SDK
Pre-conditions#
None
Parameters#
socket-id#
The unique BSD standard numeric socket identifier returned by the socket command.
Response#
OKon successERROR <error code>in case of failure, where<error code>corresponds to one of the BSD standarderrnovalues set by the close API of the WiSeConnect SDK.
Examples#
at+close=1 # Close the socket with ID 1
OK