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 3 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, where socket id is the BSD standard unique numeric socket identifier returned by the socket API of the WiSeConnect 3 SDK. The socket id is passed in subsequent socket-related commands to operate on the specific socket just created.

  • ERROR <error code> in case of failure, where error code corresponds to one of the BSD standard errno values set by the socket API of the WiSeConnect 3 SDK.

Examples#

// Create a TCP socket
at+socket=2,1,6  
OK 1

setsockopt#

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 3 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 3 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 3 SDK setsockopt API, the following are supported with AT commands:

  • SO_RCVTIMEO

  • SO_KEEPALIVE

  • SO_MAX_RETRAINSMISSION_TIMEOUT_VALUE

  • TCP_ULP

  • SL_SO_HIGH_PERFORMANCE_SOCKET (this is a Silicon Labs-specific option)

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 3 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 following option-values are passed: <seconds>,<microseconds> (see example below) where:

    • seconds is the seconds portion of the socket receive timeout,

    • microseconds is the microseconds portion of the socket receive timeout

  • For all other options, only one option-value is passed as described in the WiSeConnect 3 SDK's setsockopt API documentation.

Response#

  • OK on success

  • ERROR <error code> in case of failure, where <error code> corresponds to one of the BSD standard errno values set by the setsockopt API of the WiSeConnect 3 SDK.

Examples#

// Configure Keep Alive to 30 seconds for Socket ID 1
at+setsockopt=1,65535,8,30 
// Configure Socket Receive Timeout to 5.5 seconds for Socket ID 1
at+setsockopt=1,65535,4102,5,500000    

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 3 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#

  • OK on success

  • ERROR <error code> in case of failure, where <error code> corresponds to one of the BSD standard errno values set by the connect API of the WiSeConnect 3 SDK.

Examples#

// Connect over Socket ID 1 to remote host 192.168.10.14 to remote port 1024
at+connect=1,"192.168.10.14",1024      

send#

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 3 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 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 send data to over a UDP socket.

data-length#

The length of the data to be transmitted.

data#

The actual data to be sent. This parameter value must contain the exact number of bytes indicated in the data-length parameter. Unlike other commands, the send command is not terminated by <CR><LF> but instead by the transmision of this exact number of bytes in the data parameter.

Response#

  • OK <bytes-sent> on success

  • ERROR <error code> in case of failure, where <error code> corresponds to one of the BSD standard errno values set by the send API of the WiSeConnect 3 SDK.

Examples#

// Send the string "Hello" to the remote TCP host over Socket ID 1
at+send=1,,,5,Hello
OK 5
     
// Send the string "Hello" to the remote UDP host 192.168.10.1 over port 2000 over Socket ID 2
at+send=2,"192.168.10.1",2000,5,Hello  
OK 5

close#

Close a TCP or UDP socket.

Command Format#

at+close=<socket>

Related SDK API#

close API of WiSeConnect 3 SDK

Pre-conditions#

None

Parameters#

socket-id#

The unique BSD standard numeric socket identifier returned by the socket command.

Response#

  • OK on success

  • ERROR <error code> in case of failure, where <error code> corresponds to one of the BSD standard errno values set by the close API of the WiSeConnect 3 SDK.

Examples#

// Close the socket with ID 1
at+close=1