This Christmas, I added a whole bunch of lights powered by 5V power sources. My goal was to switch them on at sunset, and switch them off on sunrise, by using a MOSFET for power control :)
While I was doing this, I wanted to send OTA updates of my Lua files to the ESP8266 via WiFi. For some unknown reason, I couldn’t use luatool.py’s TCP update method.
So, I ended up building my very own OTA update protocol (which turned out to be fun!). To begin, add ota.lua to your project, and invoke it using dofile("ota.lua") in your init.lua:
— Send OTA updates to remotely update lua scripts on your ESP8266.
—
— LICENCE: http://opensource.org/licenses/MIT
— Created by Jude Pereira <contact@judepereira.com>
— See https://judepereira.com/blog/sending-ota-updates-over-wifi-to-your-esp8266/
srv = net.createServer(net.TCP)
current_file_name =nil
srv:listen(8080, function(conn)
conn:on("receive", function(sck, payload)
ifstring.sub(payload, 1, 5) =="BEGIN"then
current_file_name =string.sub(payload, 7)
file.open(current_file_name, "w")
file.close()
sck:send("NodeMCU: Writing to ".. current_file_name ..'…\n')
elseifstring.sub(payload, 1, 4) =="DONE"then
sck:send("NodeMCU: Wrote file ".. current_file_name .."!\n")