Function Blocks
LLHttpServer
Host a Http(s) Server on specified port.
Direction | Name | Type | Description |
---|---|---|---|
In | enable | BOOL | Spin up server |
In | bufferSize | UDINT | Size of send / receive buffers. Can not be modified after first call |
In | numClients | UINT | Max number of simultaneous clients. Can not be modified after first call |
In | ipAddress | STRING | Local IP (OPTIONAL) |
In | port | UDINT | Server local port (OPTIONAL). Defaults to 80 for HTTP and 443 for HTTPS |
In | https | BOOL | Enable HTTPS encryption |
In | sslIndex | UINT | SSL index for HTTPS |
Out | ident | UDINT | Ident of server for connecting FUBs |
Out | numConnectedClients | UINT | Number of clients currently connected |
Out | error | BOOL | An error has occurred |
Out | errorID | UINT | Error ID, refer to HttpLib_ERR_eum |
LLHttpClient
Connects to a Http(s) Server.
Direction | Name | Type | Description |
---|---|---|---|
In | enable | BOOL | Spin up server |
In | bufferSize | UDINT | Size of send / receive buffers. Can not be modified after first call |
In | hostname | STRING | IP address or name of server |
In | port | UDINT | Server port |
In | localIPAddress | STRING | Local IP (OPTIONAL) |
In | localPort | UDINT | Client local port |
In | https | BOOL | Enable HTTPS encryption |
In | sslIndex | UINT | SSL index for HTTPS |
Out | ident | UDINT | Ident of server for connecting FUBs |
Out | connected | bool | Connected to server |
Out | error | BOOL | An error has occurred |
Out | errorID | UINT | Error ID, refer to HttpLib_ERR_eum |
LLHttpRequest
Sends a HTTP request and parses the response.
Direction | Name | Type | Description |
---|---|---|---|
In | ident | UDINT | Client ident |
In | method | [HttpMethod_enum] | Request method, Get, Put… |
In | uri | STRING | URI to send request |
In | send | BOOL | Send request |
In | pUserHeader | UDINT | Pointer to an array of HttpHeaderLine_typ (OPTIONAL) |
In | numUserHeaders | UDINT | Number of elements in pUserHeader array (OPTIONAL) |
In | pContent | UDINT | Pointer to content of request (OPTIONAL) |
In | contentType | STRING | Content type (OPTIONAL) |
In | contentLength | UDINT | Length of provided content (OPTIONAL) |
In | pResponse | UDINT | Pointer to container for response body (OPTIONAL) |
In | responseSize | UINT | Size of container for response body (OPTIONAL) |
Out | header | HttpHeader_typ | Response header |
Out | responseLength | bool | Response body length |
Out | busy | BOOL | Request is being sent or awaiting response |
Out | done | BOOL | Response received |
Out | error | BOOL | An error has occurred |
Out | errorID | UINT | Error ID, refer to HttpLib_ERR_eum |
LLHttpResponse
Listens for a HTTP request and sends response.
Direction | Name | Type | Description |
---|---|---|---|
In | ident | BOOL | Send request |
In | method | [HttpMethod_enum] | Method to listen for |
In | uri | STRING | URI to listen for. * is a single item wildcard, ** is match anything after |
In | enable | BOOL | Enable FUB and start listening |
In | send | BOOL | Send response message |
In | pUserHeader | UDINT | Pointer to an array of HttpHeaderLine_typ (OPTIONAL) |
In | numUserHeaders | UDINT | Number of elements in pUserHeader array (OPTIONAL) |
In | status | UDINT | Response status |
In | contentType | STRING | Content type (OPTIONAL) |
In | pContent | UDINT | Pointer to content of request (OPTIONAL) |
In | contentLength | UDINT | Length of provided content (OPTIONAL) |
In | pRequest | UDINT | Pointer to container for response body (OPTIONAL) |
In | requestSize | UINT | Size of container for response body (OPTIONAL) |
Out | header | HttpHeader_typ | Response header |
Out | responseLength | bool | Response body length |
Out | busy | BOOL | Request is being sent or awaiting response |
Out | done | BOOL | Response received |
Out | error | BOOL | An error has occurred |
Out | errorID | UINT | Error ID, refer to HttpLib_ERR_eum |
LLHttpParse
Parse Http request or response message.
Direction | Name | Type | Description |
---|---|---|---|
In | data | UDINT | Pointer to message |
In | dataLength | UDINT | Length of data |
Out | header | HttpHeader_typ | Response header |
Out | partialPacket | BOOL | Partial message |
Out | partialContent | BOOL | Partial message body |
Out | contentPresent | BOOL | Message contains body and not partial |
Out | content | UDINT | Pointer to start of message body |
Out | error | BOOL | An error has occurred |
Out | errorID | UINT | Error ID, refer to HttpLib_ERR_eum |
LLHttpHeaderContains
Searches header list and checks for key (value)
Direction | Name | Type | Description |
---|---|---|---|
In | headerlines | UDINT | Pointer to array of HttpHeaderLine_typ to be searched |
In | name | UDINT | Pointer key to be found |
In | value | UDINT | Pointer value to be found (OPTIONAL) |
Return | found | BOOL | Key (value) was found |
LLHttpGetHeaderIndex
Gets index of header key (value)
Direction | Name | Type | Description |
---|---|---|---|
In | headerlines | UDINT | Pointer to array of HttpHeaderLine_typ to be searched |
In | name | UDINT | Pointer key to be found |
In | value | UDINT | Pointer value to be found (OPTIONAL) |
Return | index | INT | Key (value) index. -1 if not found |
LLAddHeaderField
Adds name, value to header lines array.
Direction | Name | Type | Description |
---|---|---|---|
In | headerlines | UDINT | Pointer to array of HttpHeaderLine_typ |
In | numLines | UDINT | Number of elements in header array |
In | name | UDINT | Pointer to a string containing key to be added |
In | value | UDINT | Pointer to a string containing value to be added (OPTIONAL) |
Return | match | BOOL | Returns true if selector matches URI |
LLHttpUriMatch
Compares URI selector and URI. Selectors support wild cards: * & **. ‘*’ will match one path element while ‘**’ will match any remaining path elements.
Direction | Name | Type | Description |
---|---|---|---|
In | selector | UDINT | Pointer to URI selector |
In | uri | UDINT | Pointer to URI |
Return | match | BOOL | Returns true if selector matches URI |
Example Selectors
Selector: "/file/*"
- ✅ /file/index.html
- ✅ /file/app.js
- ✅ /file/
- ❌ /file/subFolder/index.html
Selector: "/files/*/"
- ❌ /files/
- ❌ /files/test
- ❌ /files/test.cpp
- ✅ /files/deeper
- ❌ /files/deeper/test.cpp
Selector: "/files/**"
- ✅ /files/
- ✅ /files/test
- ✅ /files/test.cpp
- ✅ /files/deeper/
- ✅ /files/deeper/test.cpp
- ❌ /other
Selector: "/files/test.cpp"
- ❌ /files/
- ❌ /files/test
- ✅ /files/test.cpp
LLHttpMethodMatch
Compares 2 methods, if they are the same or either one is LLHTTP_METHOD_ANY then they match.
Direction | Name | Type | Description |
---|---|---|---|
In | a | LLHttpMethod_enum | Method |
In | b | LLHttpMethod_enum | Method |
Return | match | BOOL | Returns true if methods match |
LLHttpBuildResponse
Direction | Name | Type | Description |
---|---|---|---|
OUT | data | UDINT | Pointer to buffer to be populated with response message |
In | response | Pointer to [LLHttpServiceResponse_typ] | |
In | dataSize | UDINT | Size of data buffer |
OUT | pLen | UDINT | Pointer to UDINT to be populated with length of data (OPTIONAL) |
Return | status | DINT | Returns status of response |
LLHttpAddHandler
Adds handler to LLHttpServer ident. Handler will listen for requests.
Direction | Name | Type | Description |
---|---|---|---|
In | ident | UDINT | Server ident |
In | pHandler | Pointer to LLHttpHandler_typ to be added | |
Return | status | BOOL | Returns 0 if successful |
LLHttpAddHandler
Removes handler to LLHttpServer ident.
Direction | Name | Type | Description |
---|---|---|---|
In | ident | UDINT | Server ident |
In | pHandler | Pointer to LLHttpHandler_typ to be removed | |
Return | status | BOOL | Returns 0 if successful |
LLHttpStatus_isX
Checks status to see if it is X. X can any of the following: Error, ServerError, ClientError, Redirection, Successful, or Informational.
Direction | Name | Type | Description |
---|---|---|---|
In | code | INT | Status code LLHttpStatusCode_enum |
Return | is | BOOL | Returns true if status code is X |
LLHttpStatus_getDescription
Gets string description of status code.
Direction | Name | Type | Description |
---|---|---|---|
In | code | INT | Status code LLHttpStatusCode_enum |
In | dest | UDINT | Pointer to destination where description should be copied. Must be at least 32 bytes |
Return | is | BOOL | Returns 0 if successful |