-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f32ae85
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |