lua:curl_example
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lua:curl_example [2023/10/26 14:11] – [Writing some file onto WebHMI filesystem] emozolyak | lua:curl_example [2024/01/18 12:58] (current) – atolstov | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Getting some data from WebHMI itself using API ====== | ||
+ | |||
<code lua> | <code lua> | ||
- | | + | local res = "" |
local c = cURL.easy_init() | local c = cURL.easy_init() | ||
c:setopt{ url = ' | c:setopt{ url = ' | ||
Line 12: | Line 14: | ||
} | } | ||
| | ||
- | local res = "" | + | |
c: | c: | ||
res = res .. str | res = res .. str | ||
Line 28: | Line 30: | ||
====== Writing some file onto WebHMI filesystem ====== | ====== Writing some file onto WebHMI filesystem ====== | ||
+ | The following example create some file with content in the WebHMI filesystem using ftp access. The condition is when runRegId is changed to 0. The script immediately sets the register back to 1 preventing multiple calls and calls curl function to save the file. | ||
+ | |||
<code lua> | <code lua> | ||
function main (userId) | function main (userId) | ||
local runRegId = 840 | local runRegId = 840 | ||
-- check invoke condition | -- check invoke condition | ||
- | if (R(runRegId) | + | if (R(runRegId) ~= 0) then return end |
W(runRegId, 1) | W(runRegId, 1) | ||
| | ||
Line 42: | Line 46: | ||
upload = true, | upload = true, | ||
timeout = 2, | timeout = 2, | ||
- | readfunction = function() | + | readfunction = |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | end } ; c : perform(); c : close() | + | |
end | end | ||
lua/curl_example.1698329489.txt.gz · Last modified: 2023/10/26 14:11 by emozolyak