![]() |
Synergy Software Package User's Manual
|
The NetX Web HTTP/HTTPs Client module provides a high-level API for Hyper Text Transport Protocol(HTTP) for transferring content on the web. The HTTP protocol utilizes Transmission Control Protocol (TCP) services to perform its content transfer function. HTTPs is the secure version of the HTTP protocol which uses HTTP on top of the Transport Layer Security (TLS) protocol to secure underlying TCP connection.
HTTP/HTTPs client is implemented on top of NetX Duo IP and NetX Duo Packet Pool. NetX Duo IP attaches itself to appropriate link layer driver such ethernet/Wi-Fi/cellular. HTTP client can optionally connect to HTTP server over secure connection and in such case, it uses service provided by NetX Duo TLS Common
Unsupported Features
The NetX Duo Web HTTP/HTTPs Client module defines APIs for creating, deleting, getting and putting. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
NetX Duo Web HTTP/HTTPs Client Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| nx_web_http_client_connect | nx_web_http_client_connect(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, ULONG wait_option);Open a plaintext socket to an HTTP server for custom requests. |
| nx_web_http_client_create | nx_web_http_client_create(NX_WEB_HTTP_CLIENT*client_ptr, CHAR *client_name, NX_IP *ip_ptr,NX_PACKET_POOL *pool_ptr, ULONG window_size);Create an HTTP Client Instance. |
| nx_web_http_client_delete | nx_web_http_client_delete(NX_WEB_HTTP_CLIENT*client_ptr);Delete an HTTP Client Instance. |
| nx_web_http_client_delete_start | nx_web_http_client_delete_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS ip_address, UINTserver_port, CHAR *resource, CHAR *host, CHAR*username, CHAR *password, ULONG wait_option);Start a plaintext HTTP DELETE request. |
| nx_web_http_client_delete_secure_start | nx_web_http_client_delete_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESSip_address, UINT server_port, CHAR *resource, CHAR*host, CHAR *username, CHAR *password, UINT(*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr,NX_SECURE_TLS_SESSION *tls_session), ULONGwait_option);Start an encrypted HTTPS DELETE request. |
| nx_web_http_client_get_start | nx_web_http_client_get_start(NX_WEB_HTTP_CLIENT*client_ptr, NXD_ADDRESS ip_address, UINTserver_port, CHAR *resource, CHAR *host, CHAR*username, CHAR *password, ULONG wait_option);Start a plaintext HTTP GET request. |
| nx_web_http_client_get_secure_start | nx_web_http_client_get_secure_start( NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESSip_address, UINT server_port, CHAR *resource, CHAR*host, CHAR *username, CHAR *password, UINT(*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr,NX_SECURE_TLS_SESSION *tls_session), ULONGwait_option);Start an encrypted HTTPS GET request. |
| nx_web_http_client_head_start | nx_web_http_client_head_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS ip_address, UINTserver_port, CHAR *resource, CHAR *host, CHAR*username, CHAR *password, ULONG wait_option);Start a plaintext HTTP HEAD request. |
| nx_web_http_client_head_secure_start | nx_web_http_client_head_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESSip_address, UINT server_port, CHAR *resource, CHAR*host, CHAR *username, CHAR *password, UINT(*tls_setup)(NX_WEB_HTTP_CLIENT *client_ptr,NX_SECURE_TLS_SESSION *tls_session), ULONGwait_option);Start an encrypted HTTPS HEAD request. |
| nx_web_http_client_post_start | nx_web_http_client_post_start(NX_WEB_HTTP_CLIENT*client_ptr, NXD_ADDRESS ip_address, UINTserver_port, CHAR *resource, CHAR *host, CHAR*username, CHAR *password, ULONG total_bytes,ULONG wait_option);Start an HTTP POST request. |
| nx_web_http_client_post_secure_start | nx_web_http_client_post_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESSip_address, UINT server_port, CHAR *resource, CHAR*host, CHAR *username, CHAR *password, ULONGtotal_bytes, UINT (*tls_setup)(NX_WEB_HTTP_CLIENT*client_ptr, NX_SECURE_TLS_SESSION *tls_session),ULONG wait_option);Start an encrypted HTTPS POST request. |
| nx_web_http_client_put_start | nx_web_http_client_put_start(NX_WEB_HTTP_CLIENT*client_ptr, NXD_ADDRESS ip_address, UINTserver_port, CHAR *resource, CHAR *host, CHAR*username, CHAR *password, ULONG total_bytes,ULONG wait_option);Start an HTTP PUT request. |
| nx_web_http_client_put_secure_start | nx_web_http_client_put_secure_start(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESSip_address, UINT server_port, CHAR *resource, CHAR*host, CHAR *username, CHAR *password, ULONGtotal_bytes, UINT (*tls_setup)(NX_WEB_HTTP_CLIENT*client_ptr, NX_SECURE_TLS_SESSION *tls_session),ULONG wait_option);Start an encrypted HTTPS PUT request. |
| nx_web_http_client_put_packet | nx_web_http_client_put_packet(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET *packet_ptr, ULONGwait_option);Send next resource data packet. |
| nx_web_http_client_request_header_add | nx_web_http_client_request_header_add(NX_WEB_HTTP_CLIENT *client_ptr, CHAR *field_name,UINT name_length, CHAR *field_value, UINTvalue_length, UINT wait_option);Add a custom header to a custom HTTP request. |
| nx_web_http_client_request_initialize | nx_web_http_client_request_initialize (NX_WEB_HTTP_CLIENT *client_ptr, UINT method,CHAR *resource, CHAR *host, UINT input_size, UINTtransfer_encoding_trunked, CHAR *username, CHAR*password, UINT wait_option);Initialize a custom HTTP request. |
| nx_web_http_client_request_send | nx_web_http_client_request_send(NX_WEB_HTTP_CLIENT *client_ptr, UINT wait_option);Send a custom HTTP request. |
| nx_web_http_client_response_body_get | nx_web_http_client_response_body_get(NX_WEB_HTTP_CLIENT *client_ptr, NX_PACKET**packet_ptr, ULONG wait_option);Get next resource data packet. |
| nx_web_http_client_response_header_callback_set | nx_web_http_client_response_header_callback_set(NX_WEB_HTTP_CLIENT *client_ptr, VOID(*callback_function)(NX_WEB_HTTP_CLIENT*client_ptr, CHAR *field_name, UINT field_name_length,CHAR *field_value, UINT field_value_length));Set callback to invoke when processing HTTP headers. |
| nx_web_http_client_secure_connect | nx_web_http_client_secure_connect(NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINTserver_port, UINT (*tls_setup)(NX_WEB_HTTP_CLIENT*client_ptr, NX_SECURE_TLS_SESSION *tls), ULONGwait_option);Open a TLS session to an HTTPS server for custom requests. |
Status Return Values
| Name | Description |
|---|---|
| NX_SUCCESS | Successful connection of TCP socket. |
| NX_PTR_ERROR | Invalid pointer input. |
| NX_WEB_HTTP_NOT_READY | Another request is already in progress. |
| NX_WEB_HTTP_POOL_ERROR | Invalid payload size in packet pool |
| NX_CALLER_ERROR | Invalid caller of this service. |
| NX_HTTP_PASSWORD_TOO_LONG | Password exceeded expected length |
| NX_WEB_HTTP_ERROR | Internal HTTP Client error. |
| NX_WEB_HTTP_NOT_READY | HTTP Client not ready. |
| NX_WEB_HTTP_FAILED | HTTP Client error communicating with the HTTP Server. |
| NX_WEB_HTTP_AUTHENTICATION_ERROR | Invalid name and/or password. |
| NX_WEB_HTTP_USERNAME_TOO_LONG | Username too large for buffer. |
| NX_SIZE_ERROR | Invalid total size of resource. |
| NX_WEB_HTTP_REQUEST_UNSUCCESSFUL_CODE | Received Server error code |
| NX_WEB_HTTP_BAD_PACKET_LENGTH | Invalid packet length. |
| NX_WEB_HTTP_INCOMPLETE_PUT_ERROR | Server responds before PUT is complete. |
| NX_INVALID_PACKET | Packet too small for TCP header. |
| NX_WEB_HTTP_METHOD_ERROR | Some required information was missing (e.g. input_size for PUT or POST). |
| NX_WEB_HTTP_GET_DONE | HTTP Client get packet is done. |
HTTP (Hyper Text Transport Protocol) is used to exchange hypertext between HTTP client and server. An HTTP client initiates a HTTP request such as Get/POST/HEAD/PUT/DELETE by establishing a TCP connection to particular port on HTTP server e.g. port 80, port 443. An HTTP server listening on that port waits for a client’s request message. Upon receiving the request, the server sends back a status message such as "HTTP/1.1 200 ok" followed by a message of its own.
The NetX Web HTTP/HTTPs client module can be used in the normal mode or secure mode
NetX Web HTTP/HTTPs client module Normal Mode Operational Description
In normal mode, the communication between HTTP client and server is not secure.
Netx Web HTTP/HTTPs client module Secure Mode Operational Description
In Secure mode, the communication between HTTP client and server is secured using the TLS protocol. In the thread pane, TLS protocol is represented by "Add NetX Duo TLS common [Optional]" block as shown in the figure below
Adding NetX Duo TLS Common block enables TLS support and internally defines the NX_SECURE_ENABLE macro. The figure below shows the thread pane view of HTTP client with TLS support enabled.
The NetX Web HTTP/HTTPs Client component is added by clicking on the (+) sign in the thread pane window -> Azure RTOS -> NetX Duo -> Protocols -> NetX Web HTTP/HTTPs Client.
Adding the NetX Web HTTP/HTTPs Client component to a project automatically adds the option to add the NetX Duo TLS component required for secure HTTP client.
The NetX Web HTTP/HTTPs Client properties are listed in the following table:
In the figure above, "Common" properties are those configurable options in the NetX Web HTTP/HTTPs Client that are common to all instances of the HTTP/HTTPs client in the project. The "Module" properties are specific to each instance of HTTP/HTTPs Client in the project.
Common Properties
Module Properties
web_http_client_init0.nx_web_http_client_create() API before using any NetX Web HTTP/HTTPs Client services.NetX Duo Web HTTP Common Configurable Properties
The common properties are listed in the following table:
This section describes how to include either or both the NetX Duo Web HTTP/HTTPs Client module in an application using the SSP configurator.
To add the NetX Duo Web HTTP/HTTPs Client module to an application, simply add it to a thread using the stacks selection sequence given in the following table.
NetX Duo Web HTTP/HTTPs Client Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_web_http_client0 NetX Duo Web HTTP/HTTPs Client | Threads | New Stack> X-Ware> NetX Duo> Protocols> NetX Duo Web HTTP/HTTPs Client |
When the NetX Duo Web HTTP/HTTPs Client module is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower-level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
In the stack above, the NetX Duo Network Driver has not been populated yet. There are multiple possible selections for the Network Driver; they are not all provided so as not to needlessly complicate the figure and the following configuration tables. The available options depend on the MCU target, but some typical options include:
The NetX Duo Web HTTP/HTTPs Client module must be configured by the user for the desired operation. The SSP configuration window automatically identifies (by highlighting the block in red) any required configuration selections, such as interrupts or operating modes, which must be configured for lower-level modules for successful operation. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the NetX Duo Web HTTP/HTTPs Client Module
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | Enable, Disable, BSP Default: BSP | Selects if code for parameter checking is to be included in the build. |
| Minimum packet size (bytes) | 300 | Select the minimum packet size in bytes. |
| HTTPS Support | Enable, Disable Default: Disable | Select whether to enable HTTPS support. |
| Name | g_web_http_client0 | Module name. |
| TCP socket window size (bytes) | 1024 | Select the TCP socket window size in bytes. |
| Name of generated initialization | web_http_client_init0 | Name of generated initialization selection. |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection. |
In some cases, settings other than the defaults for lower-level modules can be desirable. For example, it might be useful to select different pins for the Ethernet peripheral. The configurable properties for the lower-level stack modules are provided in the following sections for completeness and as a reference.
Only a small number of settings must be modified from the default for the IP layer and lower-level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and are locked to prevent user modification. The following table identifies all the settings within the properties section for the module:
Configuration Settings for the NetX Duo IP Instance
| ISDE Property | Value | Description |
|---|---|---|
| Name | g_ip0 | Module name |
| IPv4 Address (use commas for separation) | 192,168,0,2 | IPv4 Address selection |
| Subnet Mask (use commas for separation) | 255,255,255,0 | Subnet Mask selection |
| Default Gateway Address (use commas for separation) | 0,0,0,0 | Default gateway address selection |
| IPv6 Global Address (use commas for separation) | 0x2001, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 | IPv6 global address selection |
| IPv6 Link Local Address (use commas for separation, All zeros means use MAC address) | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 | IPv6 link local address selection |
| IP Helper Thread Stack Size (bytes) | 2048 | IP Helper Thread Stack Size (bytes) selection |
| IP Helper Thread Priority | 3 | IP Helper Thread Priority selection |
| ARP | Enable | ARP selection |
| ARP Cache Size in Bytes | 512 | ARP Cache Size in Bytes selection |
| Reverse ARP | Enable, Disable Default: Disable | Reverse ARP selection |
| TCP | Enable, Disable Default: Disable | TCP selection |
| UDP | Enable, Disable Default: Disable | UDP selection |
| ICMP | Enable, Disable Default: Disable | ICMP selection |
| IGMP | Enable, Disable Default: Disable | IGMP selection |
| IP fragmentation | Enable, Disable Default: Disable | IP fragmentation selection |
| Name of generated initialization function | ip_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization function |
| Link status change callback | NULL | Link status change callback selection |
Configuration Settings for the NetX Duo Web HTTP Common Instance
| ISDE Property | Value | Description |
|---|---|---|
| Type of Service | Normal, Minimum delay, Maximum data, Maximum reliability, Minimum cost Default: Normal | Type of service selection. |
| Fragmentation option | Don't fragment, Fragment okay Default: Don't fragment | Fragmentation option selection. |
| MD5 Support | Enable, Disable Default: Disable | MD5 support selection. |
| Time to live | 128 | Time to live selection. |
| Maximum password length (bytes) | 20 | Maximum password length in bytes. |
| Maximum username length (bytes) | 20 | Maximum username length in bytes. |
Configuration Settings for the NetX Duo Common Instance
| ISDE Property | Value | Description |
|---|---|---|
| Name of generated initialization function | nx_common_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection |
Configuration Settings for the NetX Duo Packet Pool Instance
| ISDE Property | Value | Description |
|---|---|---|
| Name | g_packet_pool0 | Module name |
| Packet Size in Bytes | 640 | Packet size selection |
| Number of Packets in Pool | 16 | Number of packets in pool selection |
| Name of generated initialization function | packet_pool_init0 | Name of generated initialization function selection |
| Auto Initialization | Enable, Disable Default: Enable | Auto initialization selection |
Configuration Settings for the NetX MD5 Instance
| ISDE Property | Value | Description |
|---|---|---|
| No configurable properties |
The ETHERC peripheral module uses the PCLKA as its clock source. The PCLKA frequency is set using the SSP configurator Clock tab prior to a build or by using the CGC interface at run-time.
The ETHERC peripheral module uses pins on the MCU device to communicate to external devices. I/O pins must be selected and configured by the external device as required. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the I2C pins.
Pin Selection for the ETHERC Module
| Resource | ISDE Tab | Pin Selection Sequence |
|---|---|---|
| ETHERC | Pins | Select Peripherals > Connectivity:ETHERC > ETHERC1.RMII |
Pin Configuration Settings for the ETHERC1
| Property | Value | Description |
|---|---|---|
| Operation Mode | Disabled, Custom, RMII Default: Disabled | Select RMII as the Operation Mode for ETHERC1 |
| Pin Group Selection | Mixed, _A only Default: _A only | Pin group selection |
| REF50CK | P701 | REF50CK Pin |
| TXD0 | P700 | TXD0 Pin |
| TXD1 | P406 | TXD1 Pin |
| TXD_EN | P405 | TXD_EN Pin |
| RXD0 | P702 | RXD0 Pin |
| RXD1 | P703 | RXD1 Pin |
| RX_ER | P704 | RX_ER Pin |
| CRS_DV | P705 | CRS_DV Pin |
| MDC | P403 | MDC Pin |
| MDIO | P404 | MDIO Pin |
Once the module has been configured and the files auto generated, the NetX Web HTTP/HTTPs client Module is ready to be used in an application. Note that the auto generated code includes the initialization function with the name specified under the Name of generated initialization function property. This function internally calls the nx_web_http_client_create() API to create a HTTP/HTTPs client instance with the name specified under the Name property. Calls to this initialization function will be enabled or disabled depending the Auto Initialization property value. Once the client instance is created, the typical steps in using the module in an application are:
nx_web_http_client_connect(). If the application needs to use secure connection, it can connect to a secure HTTP server by invoking nx_web_http_client_secure_connect(). Note that application needs to implement the TLS setup callback function for secure connection. If needed, the application can include additional server certificate validation using DNS validation, certificate revocation and certificate policy enforcement. This can be done by invoking nx_secure_tls_session_certificate_callback_set() inside the TLS setup callback function. A reference implementation of TLS setup callback function is provided in Figure 1 of appendix.These APIs just opens a plain or secure connection to server but does not send any request.nx_web_http_- client_request_initialize(). nx_web_http_client_request_header_add()API. nx_web_http_client_request_send() API.nx_web_http_client_response_body_get() API until the entire response is retrieved.nx_web_http_client_delete() to delete all the resources associated with HTTP client instance. nx_web_http_*_start() APIs to send a standard request. For example, to send a standard GET request to plain text server, the application can use nx_web_http_client_get_start(). Similarly, the application can use nx_web_http_client_get_secure_start() to send a standard GET request over a secure channel to server. The nx_web_http_*_start() APIs internally uses nx_web_http_client_request_initialize() to create and send the desired HTTP request.
The following figure illustrates common steps in a typical operational flow diagram: