FB_IotHttpClient

This function block enables communication with a HTTP server.
A client function block is responsible for the connection to exactly one server. The Execute() method of the function block must be called cyclically to enable the functionality of the HTTP client. The exact resource on the server is specified with the sUri property of the function block FB_IotHttpRequest.
All connection parameters exist as input parameters and are evaluated when a connection is established.
Syntax
Definition:
FUNCTION BLOCK FB_IotHttpClient
VAR_INPUT
//default is local host
sHostName : STRING((ParameterList.cSizeOfHttpClientHostName-1)) :=’127.0.0.1’;
//default is 80
nHostPort : UINT :=80;
bKeepAlive : BOOL :=TRUE;
tConnectionTimeout : TIME :=T#10s;
//optional parameter
stTLS : ST_IotSocketTls;
END_VAR
VAR_OUTPUT
bError : BOOL;
hrErrorCode : HRESULT;
bConfigured : BOOL;
//TRUE if connection to server is established
bConnected : BOOL;
END_VAR
Inputs
Name | Type | Description |
---|---|---|
sHostName | STRING (255) | sHostName can be specified as a name or as an IP address. If no information is provided, the local host is used. |
nHostPort | UINT | The host port can be specified here. The default value is 80 mm. |
bKeepAlive | BOOL | Specifies whether the connection to the server should be maintained until either the server or client terminates it. Please note that not every server supports this function. |
tConnectionTimeout | TIME | Specifies the connection timeout. |
stTLS | If the server offers a TLS-secured connection, the required configuration can be implemented here. |
Outputs
Name | Type | Description |
---|---|---|
bError | BOOL | Becomes TRUE when an error situation occurs. |
hrErrorCode | HRESULT | Returns an ADS return code. An explanation of the possible ADS return codes can be found in the Appendix. |
bConfigured | BOOL | Becomes TRUE when the initial configuration is complete. |
bConnected | BOOL | Becomes TRUE if a connection to the host is established. Please note that the connection is usually closed after each request, depending on the input parameter bKeepAlive. |
Methods
Name | Description |
---|---|
Disconnect | Disconnects the client from the server if there is an active connection. |
Execute | Method for background communication with the TwinCAT driver. The method must be called cyclically for every function block instance. If the method is called for the first time before the parameters are changed, default values are used. In this case, the parameters can only be changed by Re-parameterization. |
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4024.7 or higher | IPC or CX (x86, x64, ARM) | Tc3_IotBase |