The SPWF04Sx series of Wi-Fi modules integrate a complete TCP/IP protocol stack and a rich set of applications including, but
not limited to, web server, web client RESTful API, TFTP, MQTT and SMTP.
Security is added in the multiple layers of Wi-Fi and peer-to-peer protocols. The stack implements the WPS protocol, WPA2 in
both the Personal and Enterprise options, and the TLS for end-to-end secure transactions.
Users access the features of the SPWF04Sx modules via UART using the simple AT command syntax, or via SPI using a
custom packet format and protocol.
To enable a complete customization of the application on the module, the SPWF04Sx software integrates a MicroPython
interpreter that provides the user with MicroPython standard libraries and a customized set of classes to export the specific
SPWF04Sx features.
The diagram below summarizes the possible integrations of an SPWF04Sx module in a target application.
Figure 1. SPWF04Sx user integration modes
This user manual is intended as a guide to the set of commands available on the UART or the SPI console. A description and
explanation of the configuration variables, status variables and asynchronous indication messages is available in the Appendix
of the manual.
This manual is not intended as a technical guide of Wi-Fi and TCP/IP, or other technologies available in the module.
UM2114 - Rev 3 - November 2018
For further information contact your local STMicroelectronics sales office.
www.st.com
SPWF04Sx software architecture description
1SPWF04Sx software architecture description
The complete SW architecture of SPWF04S is shown in the diagram below.
Figure 2. SPWF04Sx software architecture
UM2114
A block diagram of the SPWF04Sx protocol stack is provided in Figure 3. SPWF04Sx protocol stack diagram.
UM2114 - Rev 3
page 2/66
SPWF04Sx software architecture description
Figure 3. SPWF04Sx protocol stack diagram
UM2114
UM2114 - Rev 3
page 3/66
2Interface and message types
As shown in Figure 1. SPWF04Sx user integration modes, the SPWF04Sx enables three options for integration of
the device in the final user application. Refer to the SPWF04Sx datasheet for information useful for
implementation, such as the pinout. The configuration variable, “console_enabled”, is used to define the module
interface to use.
•UART interface
“console_enabled=1”
The UART console provides a user-friendly interface built on a set of AT commands that allow an external
microcontroller connected to the SPWF04Sx UART to access the functions integrated in SPWF04Sx device.
UART is set as the module's default interface.
•SPI interface
“console_enabled=0”
The device can be connected as a slave to the SPI interface of an external microcontroller. An ad hoc SPI
protocol and corresponding packet format are defined.
•MicroPython scripting
"console_enabled=2” - to use Python together with AT commands over UART.
"console_enabled=3” - to use MicroPython only.
The device implements a scripting methodology based on an integrated MicroPython interpreter.
MicroPython scripts can map a target application, making it unnecessary to integrate the device with an
external processor.
The following four message types represent the type of data exchanged over the interfaces.
•Commands
Used to activate a feature defined within the stack. The list of commands supported is specified in
Table 1. SPWF04Sx commands.
•Command return messages
Synchronous messages that report the status of the execution of a command. The list of synchronous error
codes is reported in Section 8 in the Appendix.
•WINDs
Asynchronous messages reporting a network or radio status at the application level. The list of WIND
messages is reported in Section 8 in the Appendix.
•Data
Data sent to, or received (data payload) from, a remote device.
UM2114
Interface and message types
UM2114 - Rev 3
Table 1. SPWF04Sx commands
Command ID
Utils: commands for debugging and retrieving module status
0x01ATNull command
0x02AT+S.HELPHelp command
0x05AT+S.STSStatus configuration
0x35AT+S.PEERSPeers configuration
Management: commands for module management and configuration
0x03AT+S.RESETSW reset
0x04AT+S.PMSSet power mode
0x08AT+S.PYTHONEnter MicroPython execution
0x09AT+S.GCFGRead Configuration status
AT commandDescription
page 4/66
Command IDAT commandDescription
0x0AAT+S.SCFGSet configuration variables
0x0BAT+S.WCFGSave configuration to Flash
0x0CAT+S.FCFGRestore factory configuration
0x57AT+S.FSWRITEFS update via serial UART/SPI
0x58AT+S.FSUPDATEFS download
0x56AT+S.FWUPDATEFW download
STM32 peripherals: commands to manage the peripherals and related values
0x13AT+S.GPIOCConfigure GPIO
0x14AT+S.GPIORRead GPIO
0x15AT+S.GPIOWWrite GPIO
0x16AT+S.DACDisable/Enable DAC
0x17AT+S.ADCRead ADC value
0x18AT+S.PWMSet PWM
0x11AT+S.TIMEGet/Set time
0x12AT+S.RANDOMProvide random number
File system management
0x21AT+S.FSMMount volume
0x22AT+S.FSUUmount/Erase volume
0x23AT+S.FSCCreate file, append data
0x25AT+S.FSDDelete file
0x26AT+S.FSRRename file
0x27AT+S.FSLList existing files
0x28AT+S.FSPPrint file content
0x29AT+S.HASHCompute digest
Security: commands to interact with the security features
0x42AT+S.SOCKQQuery a socket client for pending data
0x43AT+S.SOCKCClose a socket client
0x44AT+S.SOCKWWrite data to a socket server
0x45AT+S.SOCKRRead data from a socket client
0x46AT+S.SOCKLList opened socket clients
UM2114
Interface and message types
UM2114 - Rev 3
page 5/66
Interface and message types
Command IDAT commandDescription
0x47AT+S.SOCKDONOpen a socket server
0x48AT+S.SOCKDQQuery socket server for pending data
0x49AT+S.SOCKDCClose a socket server
0x4AAT+S.SOCKDWWrite data to a socket server
0x4BAT+S.SOCKDRRead data from a socket server
0x4CAT+S.SOCKDLList bound socket clients
Web sockets
0x61AT+S.WSOCKONOpen a web socket client
0x62AT+S.WSOCKQQuery a web socket client for pending data
0x63AT+S.WSOCKCClose web socket client
0x64AT+S.WSOCKWWrite data to a web socket client
0x65AT+S.WSOCKRRead data from web socket client
0x66AT+S.WSOCKLList open web socket client
Trivial FTP
0x51AT+S.TFTPGETGet request to a TFTP server
0x52AT+S.TFTPPUTPut request to a TFTP server
SMTP
0x53AT+S.SMTPSend an email
HTTP
0x54AT+S.HTTPGETGet a request to an HTTP server
0x55AT+S.HTTPPOSTPost request to an HTTP server
0x59AT+S.INPUTSSIFill buffer for raw text input SSI
MQTT
0x5AAT+S.MQTTCONNMQTT connect
0x5BAT+S.MQTTSUBMQTT subscribe
0x5CAT+S.MQTTPUBMQTT publish
0x5DAT+S.MQTTUNSUBMQTT unsubscribe
0x5EAT+S.MQTTDISCMQTT disconnect
UM2114
UM2114 - Rev 3
page 6/66
3AT commands over the UART
The factory module configuration sets the UART console mode as the default interface for the SPWF04Sx. This
corresponds to the configuration variable “console_enabled” being set to 1.
AT commands over the UART have a max length of 512 bytes; they are case insensitive and are always in the
form of:
AT+S. <cmd-parameters><cr>[data]
Note: Any command requiring data after the <cr> is not reentrant. If bytes are lost during data transfer over the
UART, the module remains in the waiting stage for incoming bytes.
A command is followed by a variable number of response lines that have the following format:
AT-S. <response-string><optional-parameters>
The AT command line, up to the terminating <cr>, is sent from the host. Response lines are sent from the module
to the host.
AT-S.OK:<free_heap>:<wifi_state>
AT-S.ERROR:<error-code>:<error-string>
UM2114
AT commands over the UART
returned when a command is successfully executed.
Note that free_heap and wifi_state are shown depending on
the "console_verbose" configuration variable value (0 to 2).
qualifies a synchronous error. The <error-code> field of each
asynchronous indication type is unique. The descriptive string
may be safely ignored.
Note that error_code and error_string are shown depending
on the "console_errs" configuration variable value (0 to 2).
Command parameters
A command can require parameters that follow an “=” character. The parameters are positional and separated by
a configurable separator (by default, a comma).
Parameters can require mandatory or optional values. In the latter case, if the value is not specified a default
value will be used. In the format of the command, an optional parameter is represented in squared brackets.
Asynchronous indications
Asynchronous indications may arrive at any time (except as noted below), and have the format:
The <number> field of each asynchronous indication type is unique. The descriptive string may be safely ignored.
Note that number and descriptive strings are shown depending on the "console_winds" configuration variable
value (0 to 2).
Refer to Section 8 in the Appendix for a complete list of WIND messages.
Note: Immediately after reset, no commands should be sent and only asynchronous indications are present until
the indication “+WIND:0:Console active<cr><lf>” is received. After this event, AT commands may be safely sent to
the device.
UM2114 - Rev 3
page 7/66
4SPI protocol
By setting to 0 the configuration variable "console_enabled", the module is enabled to use the SPI interface in
place of the UART.
The data transferred over the MISO and MOSI signals are packed using a well-defined API packet format as
represented below.
UM2114
SPI protocol
Figure 4. SPI packet formats
Table 2. KindOfEvent Byte SubField
Bits 0:3
Bits 4:7
Bits
Status variable wifi_state values range. Refer to
Table 8. Status variables.
Allowed values are:
•0x01 for common indications like WIND or action
confirmations
•0x02 for critical error notifications
•0x03 for incoming data sent over the SPI (in this case
normally data are filled into payload field)
Event type
Table 3. Indication number field
Event type Bits 4:7
0x01Refer to Table 14. WIND messages.
0x02
0x03Data payload.
Refer to Table 10. AT-S.ERROR:=ERROR ID= =ERROR
String=.
Indication number
Commands over the SPI have a max length of 512 bytes.
To map an AT command in the equivalent SPI command, the following procedure applies:
1.Use the corresponding CMD ID specified in Table 1. SPWF04Sx commands and fill the 4th bytes of the
master packet.
2.If optional parameters are available, count the number of comma-separated items after the “=” character and
with that number the 6th byte of the message. Starting from the 7th byte, start to write 1 byte containing the
field lengths and then copy the field bytes. Then continue with the remaining parameters.
UM2114 - Rev 3
page 8/66
UM2114
SPI protocol
3.Once the full payload has been filled, calculate the full message payload lengths and accordingly fill bytes 1
and 2 in the SPI message packet request.
The SPWF04Sx supports the MicroPython modes represented in Figure 5. MicroPython modes. The configuration
variable “console_enabled” identifies the use of the console together with MicroPython. In detail:
•"console_enabled" set to 2: this setting allows using both AT commands over the UART and MicroPython
REPL shell.
•"console_enabled" set to 3: this setting allows only a MicroPython preloaded script to be executed. No
UART/SPI communication is allowed to/from a host processor.
Consequently, the following Python modes are defined:
•Python Interactive Console (REPL – Read Evaluation Print Loop). Mainly used for debugging purposes,
it is activated by the AT+S.Python (Python command) launched without parameters. The REPL is exited by
using a CTRL-D escape character.
•Run Time Script execution. Activated with the Python command, it allows to execute the script specified as
parameter. After script execution, control returns to the AT console.
•DefaultScript Hard Execution. By using the GPIO(8) set to high at boot time, or when "console_enabled" is
set to 3, the module automatically enters the execution of the script specified by the variable “python_script”.
This mode allows the use of the module without a connected host. Note that "console_enabled" is not
changed by GPIO(8) access: this means that on the subsequent reboot, accessing Python mode again will
require GPIO(8) to be high.
UM2114
MicroPython scripting
Figure 5. MicroPython modes
UM2114 - Rev 3
page 10/66
6Command reference guide
This section details each of the SPWF04Sx commands listed in Table 1. SPWF04Sx commands, including a brief
description of its behavior and complete list of parameters. Examples and syntax are described in the “AT” format
introduced in Section 3 AT commands over the UART. The mapping mechanism described in Section 4 SPI
protocol is used to map the AT command in the packet format used by the SPI.
6.1AT
AT, by itself, is a null command that always returns an OK result code. It is useful for testing the module interface
for readiness.
Usage:
AT<cr>
UM2114
Command reference guide
Parameters:
None
6.2AT+S.HELP
AT+S.HELP prints the list of all the AT commands supported with a brief help text for each of them. Refer to
Table 1. SPWF04Sx commands for a complete list of the commands available.
Usage:
1) AT+S.HELP<cr>
2) AT+S.HELP=<keyword><cr>
Parameters:
<keyword>
Result:
to get the full list of commands
to get the list of commands containing the specified keyword
Specifies the name of a keyword
AT-S.Command:<command> -- <help>
<command>
<help>
6.3AT+S.STS
AT+S.STS displays the current values of all the status variables.
UM2114 - Rev 3
Specifies the command
Specifies the description of the command
page 11/66
Usage:
UM2114
AT+S.PEERS
1) AT+S.STS<cr>
2) AT+S.STS=<variable><cr>
Parameters:
<variable>
Result:
AT-S.Var:<var>=<value>
<var>
<value>
6.4AT+S.PEERS
AT+S.PEERS displays the current values of the peer table. These values are useful to obtain additional
information about the module connected to the AP or about the client connected to the module when it is
configured in Mini AP mode.
Usage:
to get the full list of configuration variables
to get the value of the specified variable
Specifies the name of a variable. See Table 8. Status
variables for a list of the available status variables
Specifies the status variable name
Specifies the status variable value
1) AT+S.PEERS<cr>
2) AT+S.PEERS=<peer_number><cr>
3) AT+S.PEERS=<peer_number>,<peer_var><cr>
Parameters:
<peer_number>
<peer_var>
Result:
AT-S.Var:<id>.<var>=<value>
<id>
returns the list of peers variable
returns the list of peers variable for the peer_number peer
returns the specific value of a peer_variable
identifier of the peer
displays the current value of the specified peer variable. Refer
to Table 9. Peer variables in the Appendix for a complete list
of the peer variables
Specifies the peer number
UM2114 - Rev 3
page 12/66
UM2114
AT+S.RESET
<var>
<value>
6.5AT+S.RESET
Command used to provide a SW reset to the module.
Usage:
AT+S.RESET<cr>
Parameters:
None
6.6AT+S.PMS
The SPWF04Sx features different power states as a consequence of the different operating modes of the radio
and the STM32 microcontroller. This command is used to manage the module power state.
The table that follows summarizes the power state conditions supported by the module. The values of the
variables affecting the output of the command are also reported in the following table.
1. Variables wifi_beacon_wakeup, wifi_operational_mode, and wifi_listen_interval, need to be set to the desired value.
2. The variable standby_time to be set to the desired value.
(2)
1RunPS or Fast PS
2StopPS or Fast PS
3StandbyOff
Rx Active
Tx Active
AT+S.SCFG=sleep_enabled,0
AT+S.SCFG=wifi_powersave,0
AT+S.SCFG=standby_enabled,0
AT+S.SCFG=sleep_enabled,0
AT+S.SCFG=standby_enabled,0
AT+S.SCFG=wifi_powersave,1
AT+S.SCFG=sleep_enabled,1
AT+S.SCFG=standby_enabled,0
AT+S.SCFG=wifi_powersave,1
AT+S.SCFG=standby_enabled,1
AT+S.SCFG=sleep_enabled,0
Usage:
AT+S.PMS=[<mode>]<cr>
UM2114 - Rev 3
Parameters:
page 13/66
<mode>
6.7AT+S.PYTHON
The command has a Python script executed when the file name is specified or allows to enter a Python shell
when the option is not used.
Usage:
UM2114
AT+S.PYTHON
Default value: 0
Possible values:
•0 → active mode
•1 → powersave mode
•2 → stop mode
•3 → standby mode
1) AT+S.PYTHON<cr>
2) AT+S.PYTHON=<filename><cr>
Parameters:
<filename>
6.8AT+S.GCFG
This command lists all the configuration variables together with their current value.
Usage:
1) AT+S.GCFG<cr>
2) AT+S.GCFG=<cfg_var><cr>
Parameters:
to enter the MicroPython REPL shell.
to execute the specified script.
specifies the Python script to be executed. After the execution
of the script the command returns to the AT console.
to get the full list of configuration variables
to get the value of the specified variable
UM2114 - Rev 3
<cfg_var>
Result:
AT-S.Var:<var>=<value>
<var>
<value>
configuration variable. Refer to Table 7. Configuration
variables for a complete list of the configurable variables.
Specifies the configuration variable name
Specifies the configuration variable value
page 14/66
6.9AT+S.SCFG
Command to set the value of the named configuration variable. The value is saved in the RAM until the command
AT+S.WCFG is used.
Usage:
AT+S.SCFG=<key>,<value><cr>
Parameters:
UM2114
AT+S.SCFG
<key>
<value>
6.10AT+S.WCFG
Command to save the configuration set to the Flash.
Usage:
AT+S.WCFG<cr>
Parameters:
None
6.11AT+S.FCFG
Command to restore the factory configuration variables from the Flash. It is mandatory to run a reset (HW or SW)
after a factory restore.
Usage:
variable to configure
value to be set
AT+S.FCFG<cr>
Note:HW factory restore of the variables is performed by pulling the pin GPIO0 high at power-up (until the
“+WIND:1:Poweron” indication is printed). In order to use the HW factory reset (GPIO0 enabled) and
FWUPDATE at the same time, see Section 6.13 AT+S.FSUPDATE.
Parameters:
None
6.12AT+S.FSWRITE
The command is used to update the external volume via serial interface.
Note:The HW flow control MUST be enabled in order to use the command via UART.
Usage:
UM2114 - Rev 3
page 15/66
AT+S.FSWRITE=<length><cr>{data}
Parameters:
<length> Data length to send (in bytes)
6.13AT+S.FSUPDATE
To download an updated file system from the named host and path. The downloaded image overwrites the
existing one. In this case, the user needs to perform a backup of the current file system.
This command downloads an updated firmware image located at the named host and path. The downloaded
image is temporary stored in the internal Flash. The user should perform a procedure to save the content of the
file system that will be overwritten during the process.
Note:FWUPDATE can be invalidated by pulling GPIO0 high during the first reset after the execution of AT
+S.FWUPDATE command. In this case, the external filesystem is erased and the FW update is not performed.
Usage:
Note:The HW factory reset pin (GPIO0) must be tight low during F/W update. The HW factory reset can be used after
Command used to configure the function of the various GPIOs on the module. GPIOs can be configured as inputs
or outputs. When used as inputs, they generate an interrupt when the state changes that can be configured on
the signal edge.
Usage:
1) AT+S.GPIOC=<number>,out<cr>
2) AT+S.GPIOC=<number>,in,
[<interrupt>]<cr>
Parameters:
Default: /fw.fota. Document path and optional query
arguments. If a secure FOTA is required, the extension of the
file needs to be “.sfota”.
AT+S.GPIOR is used to read the value and the direction of a previously-configured GPIO.
Usage:
AT+S.GPIOR=<num><cr>
Parameters:
<num>
Result:
GPIO Number (see Datasheet)
Default: No interrupt (turn it off, if enabled). It can assume one
of the following values:
•R → Rising edge
•F → Falling edge
•B → Both rising and falling edges
specifies the GPIO to read
UM2114 - Rev 3
AT-S.Value:<num>:<level>:<direction>
page 17/66
UM2114
AT+S.GPIOW
<num>
<level>
<direction>
6.17AT+S.GPIOW
AT+S.GPIOW is used to set the value of a previously-configured output GPIO.
Usage:
AT+S.GPIOW=<num>,<level><cr>
Parameters:
<num>
<level>
6.18AT+S.DAC
The DAC command enables DAC on GPIO15.
Usage:
Specifies the number of GPIO read
0 (low) or 1 (high)
0 (output pullup) or 1 (input)
specifies the GPIO to be set
specifies one possible value(0|1) for the specified GPIO.
AT+S.DAC=<value><cr>
Parameters:
<value>
6.19AT+S.ADC
AT+S.ADC returns ADC value on the selected GPIO. The value range is between 0 and 3300 mV with a
measurement accuracy of 10 mV.
Usage:
AT+S.ADC=<num><cr>
Parameters:
<num>
must be set in mV (between 1 and 3300). The value=0
disables DAC on GPIO15
specifies the GPIO to be used for conversion. Available
GPIOs are 0, 1 and 16
UM2114 - Rev 3
page 18/66
Result:
AT-S.Value:<value>
UM2114
AT+S.PWM
<value>
6.20AT+S.PWM
The PWM command enables PWM on the selected GPIO, with a specified frequency and duty-cycle.
Usage:
AT+S.PWM=<num>,<frequency>[,<duty_cycle>]<cr>
Parameters:
<num>
<frequency>
<duty_cycle>
6.21AT+S.TIME
Command to get or set the time (date, time)
Usage:
Specifies the ADC value
specifies the GPIO to be used for PWM. Available GPIOs are
2 and 4
value between 1 and 10 kHz. The value=0 disables PWM
default: 50%. The value is in the 0 - 100 range.
1) AT+S.TIME<cr>
2) AT+S.TIME=<time>
Parameters:
<time>
Result:
AT-S.Date:<yy>.<mo>.<dd>:<day>
AT-S.Time:<hh>.<mi>.<ss>
<yy>
returns the current date in the format “ATS.Date:yy.mm.dd:nn” and the current time in the format “ATS.Time:hh:mm:ss”. The time refers to UTC format and must
be expressed as the time in seconds since 1970-Jan-01.
sets the time as specified by the parameter
value to set the time. The time refers to UTC format and it
must be expressed in seconds since 1970-Jan-01.
Specifies the year
UM2114 - Rev 3
page 19/66
UM2114
AT+S.RANDOM
<mo>
<dd>
<day>
<hh>
<mi>
<ss>
6.22AT+S.RANDOM
Command that provides a random number generated by the peripheral integrated in the STM32.
Usage:
AT+S.RANDOM<cr>
Parameters:
None
Specifies the month
Specifies the day
Specifies the year of the week
Specifies the hours
Specifies the minutes
Specifies the seconds
Result:
AT-S.Number:<value>
<value>
6.23AT+S.FSC
This command has effect in the RAM memory volume and external SD card volume. The command creates a file
in the selected volume or appends the data following the command in case the file already exists. The space
available in the file system in RAM can be set using ramdisk_memsize configuration variable. Minimum size is 2
Kb, resulting in maximum 2 files.
Usage:
AT+S.FSC=<filename>,<datalen><cr>{data}
Parameters:
<filename>
<datalen>
Specifies the 32-bit random number
name of the file. Max size is 64 bytes
amount of space in bytes to allocate for the file
6.24AT+S.FSD
The command has effect in the RAM memory volume and external SD card volume. The command deletes an
existing file.
UM2114 - Rev 3
page 20/66
Loading...
+ 46 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.