├── .gitignore ├── LICENSE ├── README.md ├── init.lua └── wifi_setup.lua /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Lua sources 2 | luac.out 3 | 4 | # luarocks build files 5 | *.src.rock 6 | *.zip 7 | *.tar.gz 8 | 9 | # Object files 10 | *.o 11 | *.os 12 | *.ko 13 | *.obj 14 | *.elf 15 | 16 | # Precompiled Headers 17 | *.gch 18 | *.pch 19 | 20 | # Libraries 21 | *.lib 22 | *.a 23 | *.la 24 | *.lo 25 | *.def 26 | *.exp 27 | 28 | # Shared objects (inc. Windows DLLs) 29 | *.dll 30 | *.so 31 | *.so.* 32 | *.dylib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | *.i*86 39 | *.x86_64 40 | *.hex 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Pedro Minatel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266 nodeMCU Web Setup 2 | 3 | 4 | This example is to configure the ESP8266 using nodeMCU firmware by the web page in AP mode. It allows you to configure and update the WiFi credentials, like SSID and password, using your browser on the smartphone or PC. 5 | 6 | ### Usage 7 | 8 | To use this firmware you will need the ESP8266 running the nodeMCU firmware. 9 | 10 | 11 | ### References 12 | 13 | **http://pedrominatel.com.br/esp8266/wifi-web-setup-para-esp8266-com-nodemcu/** 14 | -------------------------------------------------------------------------------- /init.lua: -------------------------------------------------------------------------------- 1 | --Pedro Minatel - 2015-12-13 2 | print("Starting...") 3 | 4 | if pcall(function () 5 | print("Open config") 6 | dofile("config.lc") 7 | end) then 8 | print("Connecting to WIFI...") 9 | --Configuring WiFi as STATION 10 | wifi.setmode(wifi.STATION) 11 | wifi.sta.config(ssid,password) 12 | wifi.sta.connect() 13 | timeout = 0; 14 | tmr.alarm(1, 1000, 1, function() 15 | if wifi.sta.getip() == nil then 16 | print("IP unavaiable, waiting... " .. timeout) 17 | timeout = timeout + 1 18 | if timeout >= 60 then 19 | file.remove('config.lc') 20 | node.restart() 21 | end 22 | else 23 | tmr.stop(1) 24 | print("Connected, IP is "..wifi.sta.getip()) 25 | --do your code here 26 | end 27 | end) 28 | else 29 | print("Enter configuration mode") 30 | dofile("wifi_setup.lua") 31 | end 32 | -------------------------------------------------------------------------------- /wifi_setup.lua: -------------------------------------------------------------------------------- 1 | print("Get available APs") 2 | available_aps = "" 3 | wifi.setmode(wifi.STATION) 4 | wifi.sta.getap(function(t) 5 | if t then 6 | for k,v in pairs(t) do 7 | ap = string.format("%-10s",k) 8 | ap = trim(ap) 9 | print(ap) 10 | available_aps = available_aps .. "