Main Content

HTTP Client

Send and receive data from HTTP server over URL connection

Since R2023b

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

  • Raspberry Pi HTTP Client Block

Libraries:
Simulink Support Package for Raspberry Pi Hardware / Network

Description

Use the HTTP Client block to send and receive data from the remote server using the HTTP protocol. You can send data in the text or JSON formats. The Raspberry Pi® hardware acts as a client and can send HTTP requests to the remote server over a uniform resource locator (URL) connection. The block supports the HTTP GET, POST, and PUT methods.

Ports

Input

expand all

Specify the URL of the server at this port as a uint8 vector input.

Tip

If you are using the String library blocks to create a URL, use a String to ASCII block to convert the string to a uint8 vector.

Data Types: uint8

Specify at this port the data that you want the Raspberry Pi hardware to send as part of an HTTP request to the remote server.

Dependencies

  • To enable this port, select Request has payload input.

Data Types: uint8

Output

expand all

This port outputs the status of the HTTP request to the remote server.

  • 0 — Indicates a failure in sending the request to the server.

  • 1 — Indicates that the Raspberry Pi hardware successfully sent the request to the server.

  • 2 — Indicates an invalid request. The block waits to make the next HTTP request to the server.

Data Types: uint8

This port outputs the error message from the server related to all communication failures. If the Status port outputs 0 or 2, then the Error port outputs the corresponding error message.

Dependencies

  • To enable this port, clear Request has response output.

Data Types: uint8

This port outputs the response message from the server related to all successful HTTP requests. If the Status port outputs 0, then the Error port outputs the error message. If the Status port outputs 1, then the Response port outputs the response message.

Dependencies

  • To enable this port, select Request has response output.

Data Types: uint8

This port outputs the size of the response message data received from the server.

Dependencies

  • To enable this port, select Request has response output.

Data Types: int32

Parameters

expand all

Main

Select the HTTP request method.

  • GET — This method requests data from a specified resource.

  • POST — This method sends data to a server to create a resource.

  • PUT — This method sends data to a server to update a resource.

Specify the number of seconds to wait between subsequent HTTP requests.

Select this option if the HTTP request contains payload data in the JSON or text formats.

Select the content type of the payload input in the HTTP request. If you select the POST or PUT request methods, the client sends the content type information to the server directly based on the data.

Dependencies

  • To enable this parameter, select Request has payload input.

Select this option if the HTTP response from the server contains payload data.

Enter the maximum length of the expected payload data.

Dependencies

  • To enable this parameter, select Request has response output.

Select the format of the output payload data.

Dependencies

  • To enable this parameter, select Request has response output.

Select this option to print diagnostic messages for each HTTP request on the Raspberry Pi serial port.

Advanced

Select the number of custom HTTP request headers. You can customize a header that contains one or more key-value pairs to provide more information about the request. The value 0 indicates that the HTTP request has no custom header. Similarly, the value 2 indicates that the HTTP request has two custom headers.

Specify the key of the HTTP request header. The number of Key parameter boxes in the block dialog box depends on the number of headers you specify in the Number of custom headers parameter. For example, if you set Number of custom headers to 2, the block generates two Key parameters.

Dependencies

  • To enable this parameter, set Number of custom headers to 1, 2, or 3.

Specify the value of the custom HTTP request header key. The number of Value parameter boxes in the block dialog box depends on the number of headers you specify in the Number of custom headers parameter. For example, if you set Number of custom headers to 3, the block generates three Value parameters.

Dependencies

  • To enable this parameter, set Number of custom headers to 1, 2, or 3.

Version History

Introduced in R2023b