Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
renevdzee committed Jan 22, 2016
0 parents commit f32ae85
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# nodemcu_tftpd

A simple nodemcu lua tftp server to upload your nodemcu lua files over the Wifi connection

## Installation

Upload the with f.e. lualoader
then compile using

```lua
node.compile("tftpd.lua")
```
and optionally remove the lua file to save some flash space

```lua
file.remove("tftpd.lua")
```

## Start

To run the tftp server:

```lua
dofile("tftpd.lc")
```

To auto-start the tftp server add the line above to your init.lua
28 changes: 28 additions & 0 deletions tftpd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
_tblk=0
s=net.createServer(net.UDP)
s:on("receive",function(c,r)
local op=string.byte(r,2)
if(op==2)then
local fn=string.match(r,"..(%Z+)")
uart.write(0,"TFTP '"..fn.."': ")
_tblk=1
file.open(fn,"w")
c:send("\0\4\0\0")
elseif(op==3)then
local b=string.byte(r,3)*256+string.byte(r,4)
local sz=string.len(r)-4
uart.write(0,"#")
if(b==_tblk)then
c:send("\0\4"..string.sub(r,3,4))
_tblk=b+1
file.write(string.sub(r,5))
end
if(sz~=512)then
print(" done!")
file.close()
end
collectgarbage();
end
end)
s:listen(69)
print("TFTP server started")

0 comments on commit f32ae85

Please sign in to comment.