User Tools

Site Tools


lua:curl_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua:curl_example [2023/10/26 14:11] – [Writing some file onto WebHMI filesystem] emozolyaklua: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 = 'http://127.0.0.1/api/event-data/' .. event, c:setopt{ url = 'http://127.0.0.1/api/event-data/' .. event,
Line 12: Line 14:
          }          }
          
-    local res = ""+
     c:perform{writefunction = function(str)     c:perform{writefunction = function(str)
             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)  ~= 0) then return end +    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 =  
-                                        if (not done) then  +                function() if (not done) then done = true return fileContent end end } 
-                                            done = true  +    c : perform(); c : close() 
-                                            return fileContent +
-                                        end  +
-                               end } c : perform(); c : close() +
 end end
  
lua/curl_example.1698329489.txt.gz · Last modified: 2023/10/26 14:11 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki