esp8266 nodemcu lua wget external file via http

Started on the old forum in February 2018 · view the original in the archive · old links redirect here

No replies · 58 views · started 8 years ago · 1 min read

GumSlone Administrator Principal · 1,690 posts #1

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:

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:

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

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close