integration_with_other_systems
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
integration_with_other_systems [2019/09/03 15:08] – emozolyak | integration_with_other_systems [2024/04/04 10:18] (current) – [Troubleshooting CURL requests from WebHMI] emozolyak | ||
---|---|---|---|
Line 7: | Line 7: | ||
===== POST example ===== | ===== POST example ===== | ||
- | An example of a program executing an HTTPS request to send data as a file at URL https://demo.com/ | + | An example of a program executing an HTTPS request to send data as a file at URL https://example.com/ |
<code lua> | <code lua> | ||
Line 15: | Line 15: | ||
c = cURL.easy_init() | c = cURL.easy_init() | ||
- | c: | + | c: |
c: | c: | ||
Line 54: | Line 54: | ||
</ | </ | ||
+ | ===== Implementing other requests like PUT ===== | ||
+ | |||
+ | To implement other requests, you can use special field in the cURL for the custom methods. | ||
+ | |||
+ | Here is the example of PUT request to WebHMI itself from its Lua. | ||
+ | |||
+ | <code lua> | ||
+ | |||
+ | function main (userId) | ||
+ | local new_value = "new string" | ||
+ | write_reg_with_API(1, | ||
+ | end | ||
+ | |||
+ | function write_reg_with_API(reg_id, | ||
+ | | ||
+ | c = cURL.easy_init() | ||
+ | | ||
+ | c: | ||
+ | c: | ||
+ | | ||
+ | c: | ||
+ | c: | ||
+ | | ||
+ | c: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | }) | ||
+ | | ||
+ | c: | ||
+ | c:close() | ||
+ | end | ||
+ | |||
+ | </ | ||
===== Example - connecting to a remote module via its web server ===== | ===== Example - connecting to a remote module via its web server ===== | ||
Line 61: | Line 95: | ||
For a example we have the UC20-FBC-xxx (any bus Modubs, Ethernet/ | For a example we have the UC20-FBC-xxx (any bus Modubs, Ethernet/ | ||
- | {{ :: | + | {{ network: |
On this page you press **F12** to get necesssary information for the POST request: | On this page you press **F12** to get necesssary information for the POST request: | ||
- | {{ :: | + | {{ network: |
Then, use this information for POST request in Lua script on the WebHMI: | Then, use this information for POST request in Lua script on the WebHMI: | ||
- | {{ :: | + | {{ network: |
The function returns json object which you can then analize and check necessary fileds to read: | The function returns json object which you can then analize and check necessary fileds to read: | ||
- | {{ :: | + | {{ network: |
+ | |||
+ | ===== Notes on cURL usage ===== | ||
+ | |||
+ | <WRAP center round important 80%> | ||
+ | In the fw of 4.0 version, the following issue was reported: | ||
+ | When there are multiple cURL requests from the WebHMI to the unavailable resource, a system crash may happen. The timeout settings won't affect the sysem behaviour. Use this feature with care when you need cyclical calls of multiple cURLs in your scripts: | ||
+ | * use one script which detect availablity of the resource and locks following execution for a while | ||
+ | * use external watchdog circuit to reset WebHMI if you use it to control mission - critical system. | ||
+ | |||
+ | If the curl stability is the issue in your project, you can implement HTTP requests using custom protocol. See the [[http_get_custom |example]] | ||
+ | </ | ||
+ | |||
+ | ==== HTTP / HTTPS requests ==== | ||
+ | <WRAP center round info 80%> | ||
+ | Please note that HTTPS requests are only possible in **WebHMI Pro** version and virtualization images. | ||
+ | </ | ||
+ | |||
+ | ==== Troubleshooting CURL requests from WebHMI ==== | ||
+ | |||
+ | When troubleshooting your requests, you can turn on verbose information in your script. Please refer to the example below: | ||
+ | |||
+ | <code lua> | ||
+ | function main (userId) | ||
+ | local res = "" | ||
+ | local c = cURL.easy_init() | ||
+ | c : setopt{ url = ' | ||
+ | timeout = 30, | ||
+ | httpheader = {' | ||
+ | ' | ||
+ | -- 'Host: < | ||
+ | } | ||
+ | } | ||
+ | |||
+ | -- sw on verbose info | ||
+ | c : setopt{[cURL.OPT_VERBOSE] = 1} | ||
+ | c : setopt{[cURL.OPT_DEBUGFUNCTION] = function(...) | ||
+ | for i, v in pairs(arg) do DEBUG(i .. ' ' .. v) end | ||
+ | return 0 | ||
+ | end } | ||
+ | |||
+ | c : perform{writefunction = function(str) | ||
+ | res = res .. str | ||
+ | end} | ||
+ | c : close() | ||
+ | |||
+ | INFO(res) | ||
+ | if (res == '' | ||
+ | ERROR(' | ||
+ | else | ||
+ | INFO(' | ||
+ | end | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | |||
integration_with_other_systems.1567523301.txt.gz · Last modified: 2019/09/03 15:08 by emozolyak