Warning: include(.../cache/template/template63867.php): failed to open stream: No such file or directory in /home/codingta/public_html/includes/vb5/template.php on line 328 Warning: include(): Failed opening '.../cache/template/template63867.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/codingta/public_html/includes/vb5/template.php on line 328 esp8266 nodemcu lua wget external file via http - Coding-Talk

esp8266 nodemcu lua wget external file via http

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • esp8266 nodemcu lua wget external file via http

    Here is a simple wget function for esp8266 nodemcu lua, which gets a remote file and saves it locally. Your esp8266 has to have the http and file module included in its firmware.
    https://nodemcu.readthedocs.io/en/ma.../modules/http/
    https://nodemcu.readthedocs.io/en/master/en/modules/file/


    here is the function:
    Code:
    function wget(url,file_name)
    
        http.get(url, nil, function(code, data)
            if (code < 0) then
                print("HTTP request failed")
            else
                -- print(code, data)
                -- open file in 'w' mode
                if file.open(file_name, "w") then
                  -- write text to the file
                  file.write(data)
                  file.close()
    
    
                end
            end
          end)
    
    end
    usage:
    Code:
    wget("http://example.com/file.txt", "local_file_name.lua")
    the usage example shows how to get contents of external file.txt and save the contents to the local_file_name.lua
Working...
X