HTTP_COMMAND  URL_string, http_request, Cust_Fn (only available on Wx PLC firmware >= F94.4)
Purpose Connect to the web server specified in the URL_string and send the http_request. When the command is completed the callback custom function Cust_Fn will be called where you can process the response data.
Examples
   HTTP_COMMAND "tri-plc.com/xxx.php", "GET", 10	
   HTTP_COMMAND "tri-plc.com/xxx.php", "POSTFILE:report.csv", ISR
Demo programs: C:\TRiLOGI\TL75\usr\samples\Wx_Specifics\HTTPS_Examples.PC7 and HTTP (non_TLS)Examples.PC7
Comments:

  1. The URL_string is the full URL that comprises the server domain name, directory path and the filename of the file to be requested.

    Note: if you use TLS, then the domain name is also the CN name contained in the CA cert. If the broker does not have a domain name and only has an IP address then you disable the broker's CNname check. (see HTTP_CONFIG 4,"0") or else it may fail the verification of the CA cert.
  2. We recommend that you do not prefix "http://" or "https://" to the URL_string but depend on the HTTP_CONFIG 1, n$ command to define the connection security type (i.e. whether to use TLS or just plain connection). However, if you do prefix "http://" or "https://" to the URL_string then TBASIC will ignore the HTTP_CONFIG 1, n$ command and directly select the connection security type based on the prefix.
  3. The http_request - is a string which may be one of the following:
    • "GET"
    • "HEAD"
    • "POST"
    • "POSTFILE:xxxxxxxxx.yyy"

    Note:
    a) Use the HTTP_POST_BUF command to transfer the data to be posted to the server before running the HTTP_COMMAND with "POST" request.

    b) The "POSTFILE:" request must be followed by the filename of the file to be posted to the web server. This function deploy the multi-part HTTP POST protocol, allowing the PLC to upload a file to a server running a PHP script that can accept the file and store in the appropriate location on the server or append the data to a database.
  4. Due to the significant time it takes to complete the network communication (especially when TLS connection is used), the HTTP_COMMAND designed to be launched as a separate running in the background to avoid blocking the program execution for too long. When the HTTP_COMMAND has completed successfully (i.e. the server has responded) or has failed, the callback Cust_Fn will be called as an interrupt service routine, allowing your program to process the returned data or to confirm that the command was success or failed. The response status code can be read using the HTTP_STATUS(1) command and the response data can be read using the HTTP_INPUT$(1) command.
  5. However, the TBASIC program may also poll the "HTTP_STATUS(3)" function to wait for the HTTP_COMMAND execution to end before proceeding further with the program. HTTP_STATUS(3) will return a "0" when the HTTP_COMMAND is in progress. It will return a "1" when the command executed successfully and a "-1" when the command failed. The demo program "HTTPS_Examples.PC7" has a circuit that demonstrates the polling method.


Note:

  1. The same HTTP_COMMAND can be used for both non-encrypted and encrypted (TLS) connection to the web server. The program can select TLS connection by running the command
    	HTTP_CONFIG 1,"1"
    or select non-TLS connection running the command
    	HTTP_CONFIG 1, "0"
    before calling the HTTP_COMMAND. If TLS connection is selected, you also have the option to decide whether your program should perform "CA cert check" during the connection. To enable "CA cert check" you must first install the CA certificate for the web server on your PLC's local file space. You can optionally also require the PLC to verify the CNname of the remote server. See HTTP_CONFIG command for more details.
See Also HTTP_CONFIG, HTTP_STATUS(n), HTTP_POST_BUF, HTTP_INPUT$(1)

backbutton.gif (507 bytes)  Basic to TBASIC Reference Manual