AN4965 Application note

Similar documents
STSW-BLUENRG1-DK. BlueNRG-1, BlueNRG-2 DK SW package

UM2167 User manual. OrCAD PSpice model usage instructions

AN4491 Application note

Dynamic Electro-Thermal simulator for VIPower products. Description

STSW-STWBCFWDT. STWBC firmware downloader tool. Description. Features

RN0084 Release note. ST-LINK/V2 firmware upgrade. About this release note

L9958 Evaluation board for high current (8.6A) DC and Stepper Motors. Description

AN4696 Application note

ST Payment Secure Solution Java Card platform with up to 100 Kbytes of user NVM for AMEX payment applications

How to work with HTTP requests and responses

Wi-Fi expansion board based on SPWF01SA module for STM32 Nucleo. Description

STSW-BNRGUI. BlueNRG GUI SW package. Data brief. Features. Description

Bluetooth low energy profiles for the X-CUBE-BLE1 expansion for STM32Cube. Description

Using the GPIOs and interrupt controller to drive LEDs on STM8 Nucleo-64 boards

300 ma triple DC-DC converter for powering AMOLED displays. Description. Table 1: Device summary Negative voltage. Auxiliary positive voltage

STSW-L9960, STSW-L9960T Graphical User Interface (GUI) for EVAL-L9960 & EVAL-L9960T

UM1844 User manual. EVAL-L9958 Graphical user interface (GUI) Introduction

TN1235 Technical note

Motor control power board based on the SLLIMM-nano 2 nd series

UM2255 User manual. SPC58NG-DISP user manual. Introduction

AN4782 Application note

Description. July 2016 DocID Rev 2 1/6

AN4820 Application note

Description. January 2019 DB2381 Rev 3 1/5

AN4045 Application note

P-NUCLEO-USB001. STM32 Nucleo pack for USB Type-C and Power Delivery. Features. Description

AN4872 Application note

EVLKSTCOMET10-1. STCOMET smart meter system-on-chip development kit. Features

EVAL6494L. Demonstration board for L6494L gate driver. Description. Features

X-NUCLEO-53L0A1. Ranging and gesture detection sensor expansion board based on VL53L0X for STM32 Nucleo. Description. Features

UM2119 User manual. Graphical user interface (GUI) for EVAL-L9907-H. Introduction

ST25DV-DISCOVERY. Discovery kit for the ST25DV04K dynamic NFC/RFID tag. Features

Getting started with MotionPM real-time pedometer library in X CUBE-MEMS1 expansion for STM32Cube

NUCLEO-L496ZG. STM32 Nucleo-144 board. Features. Description

AN2261 APPLICATION NOTE

STEVAL-IPMnM2N. Motor control power board based on the SLLIMM-nano 2 nd series. Description. Features. RoHS compliant

UM1641 User manual. Sampling rate conversion SRC236 library software expansion for STM32Cube. Introduction

P-NUCLEO-IKA02A1. STM32 Nucleo pack: electrochemical toxic gas sensor expansion board with CO sensor. Description. Features

ST Payment Secure Solution - Java Card platform with up to 90 Kbytes of user NVM for Visa, MasterCard, AMEX, Discover and Interac applications

X-NUCLEO-53L1A1. Long distance ranging Time-of-Flight sensor expansion board based on VL53L1X for STM32 Nucleo. Description.

UM2361. Getting started with the ST BlueNRG-Mesh ios application. User manual. Introduction

Getting started with the digital MEMS microphone expansion board based on MP34DT01-M for STM32 Nucleo

STM32 Trusted Package Creator tool software description

AN5224. STM32 DMAMUX: the DMA request router. Application note. Introduction

A scalable approach to your body, networking and security platforms. Description

TN1234 Technical note

STSW-BNRG-Mesh. Mesh over Bluetooth low energy. Features. Description. Applications

AN5171 Application note

AN3281 Application note

P-NUCLEO-USB001. STM32 Nucleo pack for USB Type-C and Power Delivery Data brief. Features. Description

NUCLEO-L433RC-P NUCLEO-L452RE-P

STM32 embedded target for MATLAB and Simulink release 3.1. Summary for STM32 embedded target for MATLAB and Simulink release 3.1:

UM1893 User Manual. STSW-RFSOL001 STWPLLSim simulation tool for STW81200/STuW Introduction

USB Type-C and Power Delivery Nucleo pack with NUCLEO-F072RB expansion board based on STUSB1602. Description

UM2216 User manual. Getting started with MotionFA fitness activity library in X CUBE MEMS1 expansion for STM32Cube. Introduction

UM0401 User manual. User manual for eight bit port expander STMPE801 demonstration board. Introduction

AN2143 Application note

UM2375 User manual. Linux driver for the ST25R3911B/ST25R391x high performance NFC frontends. Introduction

AN2667 Application note

COSC 2206 Internet Tools. The HTTP Protocol

UM1572 User manual. STEVAL-IPE020V1: ST energy meter application based on the Android platform. Introduction

AN4624 Application note

Getting started with X-CUBE-LED channel LED driver software expansion based on LED1642GW for STM32Cube

STEVAL-SPBT4ATV3. USB dongle for the Bluetooth class 1 SPBT2632C1A.AT2 module. Features. Description

Getting started with STEVAL-IDB007V1 and STEVAL-IDB008V1 evaluation boards

32L476GDISCOVERY. Discovery kit with STM32L476VG MCU. Features. Description

EMIF06-HSD04F3. 6-line low capacitance IPAD for micro-sd card with EMI filtering and ESD protection. Features. Application.

P-NUCLEO-53L1A1. VL53L1X nucleo pack with X-NUCLEO-53L1A1 expansion board and STM32F401RE nucleo board. Description. Features

Getting started with osxmotiongc gyroscope calibration library for X-CUBE-MEMS1 expansion for STM32Cube

EV-VNH7040AY. VNH7040AY Evaluation Board. Features. Description

Table 1: Device summary Part numbers Device info (stored in register 0xF0 and 0xF1) Comment SPIRIT1QTR 0x0130 Cut 3.0

UM2330 User manual. ST8500 boot. Introduction

Description SPC564A-DISP. March 2014 DocID Rev 3 1/5

AN4440 Application note

P-NUCLEO-6180X2. Proximity, gesture, ambient light sensor expansion board based on VL6180X for STM32L053R8. Description. Features

UM2350. Getting started with MotionPW real-time pedometer for wrist library in X-CUBE-MEMS1 expansion for STM32Cube. User manual.

EVALSTGAP1AS. Demonstration board for STGAP1AS galvanically isolated single gate driver. Description. Features

UM2092 User manual. Basic metrology firmware for the STM32F103RD and the STPM32 devices. Introduction

Getting started with X-NUCLEO-IHM06A1 low voltage stepper motor driver expansion board based on STSPIN220 for STM32 Nucleo

AN4274 Application note

Software GUI user guide for STEVAL-ISV021V1, STEVAL- IDS002V1 and STEVAL-IDS003V1 evaluation boards

World Wide Web, etc.

P-NUCLEO-53L0A1. VL53L0X Nucleo pack with ranging, gesture detection sensor expansion board and STM32F401RE. Description. Features

AN4515 Application note

AN4464 Application note

AN4869 Application note

UM0693 User manual. 1 Introduction. STM8L101-EVAL demonstration firmware

32F412GDISCOVERY. Discovery kit with STM32F412ZG MCU. Features. Description

Getting started with MotionMC magnetometer calibration library in X-CUBE-MEMS1 expansion for STM32Cube

Getting started with osxmotionmc magnetometer calibration library for X-CUBE-MEMS1 expansion for STM32Cube

STEVAL-PCC010V1. ST802RT1A Ethernet PHY demonstration board with STM32F107 controller add-on board. Features. Description

AN2825 Application Note

STM32L4R9I-EVAL. Evaluation board with STM32L4R9AI MCU. Features

Getting started with the FP-IND-PLCWIFI1 function pack for PLC management via Wi-Fi

UM2343 Application note

UM2194. Getting started with MotionAW activity recognition for wrist library in X-CUBE-MEMS1 expansion for STM32Cube. User manual.

UM2276. Getting started with MotionSD standing vs sitting desk detection library in X-CUBE-MEMS1 expansion for STM32Cube. User manual.

What to shove up your.htaccess

AN4749 Application note

Getting started with MotionPM real-time pedometer library in X-CUBE-MEMS1 expansion for STM32Cube

Transcription:

Application note WebServer on SPWF04S module Introduction The HTTP protocol is an excellent solution for communication between humans and embedded devices because of the ubiquitous presence of browsers. This SPWF04S HTTP server application note is for developers seeking to implement Webservices and Webpages with static or dynamic content in their embedded products. It includes: an introduction to SPWF04S HTTP server, including server capabilities server side information built-in functionality information November 2017 DocID030069 Rev 2 1/15 www.st.com

Contents AN4965 Contents 1 Features overview... 4 2 Introduction into SPWF04S HTTP server... 5 2.1 Using multiple connections... 5 2.2 Supported HTTP methods... 5 2.3 Generating HTTP responses... 5 2.4 HTTP protocol 1.1... 5 2.5 Get HTTP header content... 5 2.6 Receiving POST data... 6 2.7 Selecting the homepage... 6 2.8 Favicon-support... 6 2.9 Using MIME types... 6 2.10 Compressing resources (GZIP)... 7 2.11 Controlling the browser cache (date/time)... 7 3 Server-side-includes (SSI / Dyn-HTML)... 8 4 Built-in functionalities... 12 5 Revision history... 14 2/15 DocID030069 Rev 2

List of tables List of tables Table 1: Example of marker replacement... 8 Table 2: List of the possible dynamic marker types and their parameters in templates... 9 Table 3: List of built-in functions... 12 Table 4: Document revision history... 14 DocID030069 Rev 2 3/15

Features overview AN4965 1 Features overview The SPWF04S HTTP server features: HTTP 1.1 support HTTPS support (on top of TLS 1.2) HTTP 1.0 methods GET, POST (RFC 1945) HTTP 1.1 method OPTIONS (RFC 2616) Delivering static responses based on filesystem access Ability to deliver dynamic, application-generated responses based on server-sideincludes and fully application-generated content 4/15 DocID030069 Rev 2

Introduction into SPWF04S HTTP server 2 Introduction into SPWF04S HTTP server This chapter describes some of the product packages and protocols supported by the SPWF04S HTTP Server. It includes a basic setup of protocols, which should be sufficient for an embedded device to provide Webservices capability via HTTP. 2.1 Using multiple connections The HTTP server is able to manage up to four multiple HTTP connections in parallel. 2.2 Supported HTTP methods The HTTP supports the following HTTP methods: GET: to request a resource from the HTTP server POST: to deliver data to the HTTP server OPTIONS: to request the HTTP header only from the HTTP server. 2.3 Generating HTTP responses When delivering web pages over HTTP, there are two main ways to generate responses for a request: With a static resource (a file). With a program the HTTP server calls after receiving the request. On larger web servers, this is usually done by spawning an additional process that handles the request by executing a program written in a scripting language like PHP, Perl or ruby. Both methods are supported by the SPWF04S HTTP server, but the generation of dynamic responses requires server side include (SSI) tags (see ). 2.4 HTTP protocol 1.1 With HTTP 1.1, the SPWF04S HTTP server: Can parse out the content of the request when it is transferred in chunks (chunked encoding) Can send the content of the response in chunks (chunked encoding) Doesn't close the TCP connection immediately after a sent response, but after a timeout when no further request is received over the TCP connection 2.5 Get HTTP header content The following HTTP header fields are evaluated internally: Content-Length: length of received HTTP content (to determine the end of the request for HTTP content). Content-Type: type of HTTP content (e.g., multipart/form-data or application/xwwwform-urlencoded). If-Modified-Since: whether the browser should only receive modified files, in order to determine whether to transfer the file or the status code 304 (Not Modified) in the response. User-Agent: name of user agent which sent the HTTP request; the name is saved and used internally. Content-Transfer-Encoding: encoding of received HTTP content to determine whether the content is encoded in chunks ("chunked encoding"). DocID030069 Rev 2 5/15

Introduction into SPWF04S HTTP server 2.6 Receiving POST data AN4965 Data that are received with a POST request are normally delivered to the filesystem, with two exceptions: When the content type is "application/x-www-form-urlencoded", the content contains name/value pairs and every pair is notified. When the content type is "multipart/form-data", an uploaded file is embedded in one of the multiple parts and the content of the received file is notified. See Section 4: "Built-in functionalities" for a detailed description of available built-in actions. 2.7 Selecting the homepage If the user of a HTTP client (browser) only requests the host name (or IP address) of the device with the HTTP server without specifying a page name, the HTTP server returns a default page, usually index.html. For example, if the user requests http://device77, the server returns http://device77/index.html. 2.8 Favicon-support Most browsers request a file named "favicon.ico" which represents a Favicon, a small logo displayed left in the address row of the browser. If such a file is found in the local file system, the content of the file is returned in the HTTP response, with Content-Type "image/x-icon". Normally, if a requested file is not found, the SPWF04S HTTP server returns a page with status code 404 (File Not Found) unless it is a Favicon file, in which case an empty file is returned with status code 200 (OK) and Content-Type "image/x-icon". 2.9 Using MIME types For every HTTP response, the type of the returned file has to be declared so the browser knows how to handle/display the file. These are declared as Multipurpose Internet Mail Extensions (MIME) types: a set of strings, primarily declared for email exchange, in the Content-Type HTTP header field. Since the content of the file to be returned in the HTTP response is read via filesystem, the associated MIME type is also returned from filesystem (as index) when opening the file. The following MIME types are supported by the SPWF04S HTTP server: application/font-woff application/json application/vnd.ms-fontobject application/x-java-applet application/x-javascript application/x-raw-stuff application/x-shockwave-flash application/x-www-form-urlencoded audio/midi audio/mpeg audio/mpeg3 audio/wav audio/x-ms-wma 6/15 DocID030069 Rev 2

image/bmp image/gif image/jpg image/png image/tiff image/x-icon image/x-pcx multipart/form-data multipart/x-mixed-replace text/css"video/mpeg text/html text/plain text/xsl text/xml video/x-ms-asf video/x-ms-wmv video/x-msvideo Introduction into SPWF04S HTTP server 2.10 Compressing resources (GZIP) If a requested file from a HTTP client cannot be found via filesystem, the server also checks for a corresponding gzip compressed file by inserting ".gz" before the last dot in the name of the requested file. Resources containing SSI (refer to Section 4: "Built-in functionalities") cannot be compressed. Example: When a user requests "http://device77/large.txt" with a browser and the SPWF04S HTTP server cannot large.txt via filesystem, it checks for large.gz.txt and, if found, transfers it in its response. In this case, the Content-Transfer-Encoding header field is also delivered with the value "gzip" to alert the browser that it is receiving a gzip compressed file. 2.11 Controlling the browser cache (date/time) The SPWF04S HTTP server can control the browser cache by sending the Expires field with an appropriate date/time stamp: in the future (year 2100) if a file must be cached in the past (year 2000) if a file must not be cached The caching property is defined per MIME type. The default values are chosen so that files of all types can be cached except for: text/html (when the content is dynamic HTML) text/plain text/xml application/json application/x-raw-stuff DocID030069 Rev 2 7/15

Server-side-includes (SSI / Dyn-HTML) AN4965 3 Server-side-includes (SSI / Dyn-HTML) Server-side-Includes files are dynamically generated from a template file. A template file is a file that is post-processed by the SPWF04S HTTP server. To indicate that a HTML source file contains dynamic HTML data, the HTML file must have a.fhtml extension instead of HTML. It contains special markers that are replaced dynamically with data coming from the application. These markers are HTML comments with the following format: <!-- code parameter1 parameter2 parameter3 parameter4 --> The code determines the resulting string type and parameters 1 to 4 may be used to define certain substrings of that tag; mostly attributes. Not all possible types use all the parameters; only the necessary parameters need to be provided. See Table 2: "List of the possible dynamic marker types and their parameters in templates" for a complete code list and corresponding parameters. Using the following tokens buffer, filled by AT+S.INPUTSSI command (Ref. to UM2114): aname y avalue sometext y aname avalue sometext some short examples of marker replacement are following: Template text <!-- 00 SelStart 0 --> <!-- 01 Select 3 --> <!-- 02 SelEnd --> <!-- 03 CheckBox 2 --> <!-- 03 CheckBox 6 --> <!-- 06 Input 4 --> <!-- 06 Peers rx_rssi 0 --> -57 Table 1: Example of marker replacement Generated HTML code <select name= aname MULTIPLE> <option SELECTED value= avalue >sometext </select> <input type= checkbox name= value= avalue CHECKED>someText <input type= checkbox name= aname value= avalue >sometext SomeText No close tag </option> is generated for <option> filed, as these are not mandatory for HTML syntax. The other marker types follow along these lines. 8/15 DocID030069 Rev 2

Server-side-includes (SSI / Dyn-HTML) Table 2: List of the possible dynamic marker types and their parameters in templates Code Description Parameters 00 Start tag of a select box Parameter 1: Must be SelStart Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the select box If given (any value), multiple selections are allowed. 01 Option tag Parameter 1: Must be Select Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Value of the option Label of the option If given (any value), this options is marked as Selected. 02 End tag of a select box Parameter 1: Must be SelEnd 03 A check box 04 A radio button 05 A text area start tag Parameter 1: Must be CheckBox Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the check box Value of the check box Label of the check box If given (any value), the check box is initially checked. Parameter 1: Must be RadioButton Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the radio button (radio buttons with the same name cannot be checked at the same time). Value of the radio button Label of the radio button If given (any value), the radio button is initially checked. Parameter 1: Must be TextArea Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the text area Number of columns of the text area Number of rows of the text area DocID030069 Rev 2 9/15

Server-side-includes (SSI / Dyn-HTML) AN4965 Code Description Parameters 06 Raw text Parameter 1: Must be one of the following, to recall proper SPWF04S Web Server actions: Input replace with raw text (use Parameter 2) DevConf replace with configuration variable (use Parameter 2) DevSts replace with status variable (use Parameter 2) Peers replace with peer status variable (use Param. 2 and 3) ADC replace with ADC value (use Parameter 2) GpioR replace with GPIO status (use Parameter 2) Parameter 2: Token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Configuration variable Status variable Peer status variable ADC number GPIO number Parameter 3: Peer number 07 A text area end tag Parameter 1: Must be TextEnd 08 A text field 09 A submit button 10 A reset button 11 A password field Parameter 1: Must be TextField Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the text field The initial value of text field Size of text field Parameter 1: Must be Button Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the submit button Value (displayed text) of the submit button Parameter 1: Must be Reset Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the reset button Value (displayed text) of the reset button Parameter 1: Must be Password Parameter 2: Starting token index inside buffer filled from application via AT+S.INPUTSSI command. Ref. to UM2114. Name of the password field The initial value of password field Size of password field 10/15 DocID030069 Rev 2

Server-side-includes (SSI / Dyn-HTML) For the <select> element, currently the argument "size = x" is not supported. So actual browsers will not display the option elements in a multiline rectangle, but in a dropdown-box only. DocID030069 Rev 2 11/15

Built-in functionalities AN4965 4 Built-in functionalities The single or multipart form data in the HTTP POST stream trigger specific actions when they are read, as described in the following table. POST information name Table 3: List of built-in functions POST information value HTTP server action (1) Output SomeText +WIND:57: Output from remote:%u:%s Key Ssid Pwd WpaeId WpaeAnonId WpaeType Ip Netmask Gateway Dns1 Dns2 Dhcp IbssAuth Auth Mode Scfg_* GpioC_* GpioW_* DAC PWM_* Sleep Must be user_desc configuration variable to allow remote configuration SSID WPA PSK WPA-E identity WPA-E anonymous identity WPA-E EAP type IPv4 static address IPv4 static netmask IPv4 static gateway IPv4 static primary DNS IPv4 static secondary DNS DHCP mode (0: static, 1: dynamic, 2: Auto IP) Authentication type (0: shared, 1: open) Authentication mode (0: open, 1: WEP, 2: WPA, 3: WPA-E) SPWF04S mode (0: idle, 1: STA, 2: IBSS, 3: miniap) Value of the variable to be set Value of the GPIO to configure (out, in, in_r, in_f, in_b) Value of the GPIO to set (0: low, 1: high) Value of the DAC to set on GPIO15 (0 to 3300mV) Value of the PWM and duty cycle to set (KHz_dc) on GPIO2 or GPIO4 Enter or Exit (1 or 0) sleep power mode +WIND:64: Remote configuration:%s:%s (only shown if it is wrong) +WIND:64: Remote configuration:%s:%s (only allowed if Key was previously accepted) 12/15 DocID030069 Rev 2

POST information name Reboot - POST information value HTTP server action (1) Built-in functionalities Save the configuration set to the Flash, and reboot the SPWF04S module (only allowed if key was previously accepted) Notes: (1) (ref. to UM2114 on www.st.com) DocID030069 Rev 2 13/15

Revision history AN4965 5 Revision history Table 4: Document revision history Date Revision Changes 17-Jan-2017 1 Initial release. 17-Nov-2017 2 Updated Section 2.9: "Using MIME types". Updated Section 4: "Built-in functionalities". Minor text changes. 14/15 DocID030069 Rev 2

IMPORTANT NOTICE PLEASE READ CAREFULLY STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST s terms and conditions of sale in place at the time of order acknowledgement. Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of Purchasers products. No license, express or implied, to any intellectual property right is granted by ST herein. Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product. ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners. Information in this document supersedes and replaces information previously supplied in any prior versions of this document. 2017 STMicroelectronics All rights reserved DocID030069 Rev 2 15/15