diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dd7b030 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +###################################################################### +# User configuration +###################################################################### +# Path to nodemcu-uploader (https://github.com/kmpm/nodemcu-uploader) +NODEMCU-UPLOADER=nodemcu-uploader.py +# Serial port +PORT=/dev/ttyUSB0 +SPEED=460800 + +###################################################################### +# End of user config +###################################################################### +HTTP_FILES := $(wildcard http/*) +LUA_FILES := init.lua httpserver.lua httpserver-request.lua httpserver-static.lua httpserver-error.lua + +# Print usage +usage: + @echo "make upload_http to upload files to be served" + @echo "make upload_server to upload the server code and init.lua" + @echo "make upload to upload all" + +# Upload HTTP files only +upload_http: $(HTTP_FILES) + @$(NODEMCU-UPLOADER) -b $(SPEED) -p $(PORT) upload $(foreach f, $^, $(f)) + +# Upload httpserver lua files (init and server module) +upload_server: $(LUA_FILES) + @$(NODEMCU-UPLOADER) -b $(SPEED) -p $(PORT) upload $(foreach f, $^, $(f)) + +# Upload all +upload: $(LUA_FILES) $(HTTP_FILES) + @$(NODEMCU-UPLOADER) -b $(SPEED) -p $(PORT) upload $(foreach f, $^, $(f)) + +#test +test: $(LUA_FILES) $(HTTP_FILES) + echo -b $(SPEED) -p $(PORT) upload $(foreach f, $^, -f $(f) -d $(f)) diff --git a/http/updateaplist.lua b/http/updateaplist.lua new file mode 100644 index 0000000..9ed369c --- /dev/null +++ b/http/updateaplist.lua @@ -0,0 +1,14 @@ +local function storelist(t) +-- connection:send(cjson.encode(t)) +-- print(cjson.encode(t)) + file.remove("http/aplist.json") + file.open("http/aplist.json","w+") + file.writeline(cjson.encode(t)) + file.close() +end + +return function(connection,args) + wifi.sta.getap(storelist) + connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n") + connection:send('{"error":0, "message":"OK"}') +end