This is an old revision of the document!
Integration into other systems
WebHMI allows you to interact with other systems by running HTTP requests. For this, WebHMI has a library Lua-cURLv3. Using it you can easily send data to third-party systems and also request the necessary data from these systems.
This function is available since version 2.6.4520.
An example of a program executing an HTTPS request to send data as a file at URL https://demo.com/upload:
function main (userId) INFO("Doing CURL"); c = cURL.easy_init() c:setopt_url("https://demo.com/upload") c:setopt_timeout(5) postdata = { name = { file="dummy.html", data="<html><bold>bold</bold></html>", type="text/html" } } c:post(postdata) c:perform() c:close() INFO("CURL done"); end
Note that for SSL certificates correctly function, you need to have an exact local time. If there is a significant deviation of the local clock, https requests may not work. We recommend using time synchronization via NTP server.
Example of requesting a number in the GET request at URL http://demo.example.com/read-data?param=32 and writing it to the register with id=4356:
function main (userId) c = cURL.easy_init() c:setopt_timeout(5) c:setopt_url("http://demo.example.com/read-data?param=32") local res = ""; c:perform({ writefunction = function(str) res = res .. str; end}) c:close() WriteReg(4356, res); end
Example - connecting to a remote module via its web server
Most currently produced remote i/o modules have configuration and status web-page for diagnostic and setup. When you have a module which is not supported with WebHMI and using custom protocol is difficult, there is another option of accessing the module though its embedded webserver with HTTP requests.
For a example we have some remote I/O module UC20-FBC-MOD from Weidmuller. The module has web server for diagnostinc and setup:
On this page you press F12 to get necesssary information for the POST poll:
Then, use this information for POST poll in Lua script on the WebHMI: