Please enable JavaScript to view this site.

Navigation: ESP32 target > Block references > IOT

HTTP server block

Scroll Prev Top Next More

How this block appears in a Simulink model?

http_server_block_1

What can be configured?

HTTP server setup block

http_server_setup_block_2

Configuration Parameter

Selectable Option/Value

Description

Enable wildcard

True--False

Enable or disable wildcard. By enabling this, server accepts multiple uri s in a single handler

Port number

 

Specify the port number which the server operates

Core ID

0--1--ANY

Select which core the server should operate

Stack size

 

Specify the stack size for the server task

HTTP post handler block

http_server_block_3

Configuration Parameter

Selectable Option/Value

Description

Name of the handler

 

Specify the name for the current handler. When multiple blocks are used, It should not be repeated.

URI

 

Specify the uri for the handler. In case the enable waildcard for this handler is enabled specify the base uri here.

Enable wildcard for this handler

Check--Uncheck

Enable or disable the wildcard for this current handler.

Number of requests

1 to 12

Number of requests handle using the current handler. This will be always 1 when the wildcard is false in HTTP Server Setup block.

Output request data

Check--Uncheck

Enable this option to get the POST request body from the output port.

If request is

 

Specify the request to be handle (POST request body)

Compare the whole request

Check--Uncheck

Compare the POST request body with the specified partially or fully

Set header type

.html--.css--.png--.ico--.txt--.js--.ttf--.woff2--.json

Select the correct data type of the response data

Serve data from

SD card--Static text input--Dynamic text input

The data source. Whether the response data from the sd card or static text from the mask text box or dynamic text from input port

File location

 

Full file path. This option is enabled when the data is served from the SD card

Contains .gz compressed files

Check--Uncheck

Check, when the files are gz compressed files

Text input

 

This enables when the data is served from a static text input. Insert the data on the text area

INPUT/ OUTPUT Port

Port Name

Port Type

Date Type

Description

Res for Req

Scalar/Vector

uint8

Data transmitted to the server

HTTP get handler block

http_server_block_4

Configuration Parameter

Selectable Option/Value

Description

Name of the handler

 

Specify the name for the current handler. When multiple blocks are used it should not be repeated.

URI

 

Specify the uri for the handler. In case the enable waildcard for this handler is enabled specify the base uri here.

Enable wildcard for this handler

Check--Uncheck

Enable or disable the wildcard for this current handler.

Number of requests

1 to 12

Number of requests handle using the current handler. This will be always 1 when the wildcard is false in HTTP Server Setup block.

If request is

 

Specify the request to be handle (uri)

Compare the whole request

Check--Uncheck

Compare the request uri with the specified partially or fully

Set header type

.html--.css--.png--.ico--.txt--.js--.ttf--.woff2--.json

Select the correct data type of the response data

Serve data from

SD card--Static text input--Dynamic text input

The data source. Whether the response data from the sd card or static text from the mask text box or dynamic text from input port

File location

 

Full file path. This option is enabled when the data is served from the SD card

Contains .gz compressed files

Check--Uncheck

Check, when the files are gz compressed files

Text input

 

This enables when the data is served from a static text input. Insert the data on the text area

INPUT/ OUTPUT Port

Port Name

Port Type

Date Type

Description

Res for Req

Scalar/Vector

uint8

Data transmitted to the server

When to use this block?

HTTP server setup block

Use this block for the application which need to implement a custom http server using ESP32.

 

HTTP post handler block

This block is used when there are POST requests from the client.

 

HTTP get handler block

This block is used when there are GET requests from the client.

How does this block work?

HTTP server setup block

This block will initialize the http server with the given configuration.

 

HTTP post handler block

This block handles the POST requests from the client. Before using this block, first initialize the server using HTTP server setup block. The data to the input ports should be in string format.

 

HTTP get handler block

This block handles the GET requests from the client. Before using this block, first initialize the server using HTTP server setup block. The data to the input ports should be in string format.

Demo 1

Demo file : esp32_http_server_demo.slx

http_server_get_post_demo_1
http_server_get_post_demo_2

Description

This demo shows how to use HTTP server setup block, HTTP get handler block and HTTP post handler block by using the custom html web pages. Addition to this blocks, the WiFi block is used to initialize the WIFI in AP mode to access the http server and SD card block is used to initialize the SD card to serve the files (.html, ,css and .png).

Note : First copy the Simple_GET_POST.7z and extract the files to the SD card and insert in to the ESP32 module.

This example is compatible for hardware that allow SD card mount.

What should be happening?

Once the WIFI is initialize WIFI in AP mode use the following information to connect to the ESP32.

IP : 192.168.20.21

SSID : Test_http_server

Password : 00000000

Once the IP address is accessed using the web browser, the web page is as below

Action: On page load

http_server_get_post_demo_3

The client will sends GET/POST requests according to the button

Load image button : Show an image from the SD card using GET method

http_server_get_post_demo_4

Send POST Request button : Send POST request to to server and shows the response data in the text area

http_server_get_post_demo_5

Next page button : Redirect to another html page using GET method

 

Source files : Simple_GET_POST.7z

Demo 2

Demo file : esp32_http_server_demo_2.slx

http_server_block_10
http_server_block_11

Description

This demo shows how to use HTTP server setup block, HTTP get handler block and HTTP post handler block by using the custom html web pages. Addition to this blocks, the WiFi block is used to initialize the WIFI in AP mode to access the http server and SD card block is used to initialize the SD card to serve the files (.html, ,css and .png). ADC block is used to read analog voltage measurement from GPIO36. Connect a potentiometer to GPIO36

Note : First download the line_graph.rar and extract the files to the SD card and insert in to the ESP32 module.

This example is compatible for hardware that allow SD card mount.

What should be happening?

Once the WIFI is initialize WIFI in AP mode use the following information to connect to the ESP32.

IP : 192.168.0.235

SSID : Test_http_server

Password : 123456789

 

Once the web page is loaded, the ADC Reading graph will be plotted the data according to the reading from the GPIO36 as in the following figure.

http_server_block_12

Source files : line_graph.rar

 

Copyright 2022 Aimagin Co.,Ltd. Rev.339