Created
January 11, 2019 07:21
-
-
Save Terrabits/ac914967864d57cc1b05a81cc21e7341 to your computer and use it in GitHub Desktop.
NodeMCU firmware init with WiFi
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
-- tested on HiLetgo NodeMCU v1.0 | |
-- requires modules: wifi, tmr | |
-- (and optionally gpio for blinky light) | |
local ssid = "ssid" | |
local password = "password" | |
local BLUE_LED = 4 | |
function connect_to_wifi(ssid, password) | |
wifi.setmode(wifi.STATION) | |
wifi.sta.config(ssid, password) | |
wifi.sta.connect() | |
end | |
function wait_for_ip(callback) | |
tmr.create():alarm(100, tmr.ALARM_AUTO, | |
function(t) | |
if wifi.sta.getip() ~= nil then | |
t:unregister() | |
callback() | |
end | |
end) | |
end | |
function continue_with_wifi() | |
gpio.write(BLUE_LED, gpio.LOW) | |
print('Connected to WiFi') | |
end | |
gpio.mode (BLUE_LED, gpio.OUTPUT) | |
gpio.write(BLUE_LED, gpio.HIGH) | |
connect_to_wifi(ssid, password) | |
wait_for_ip(continue_with_wifi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment