Created
June 3, 2018 19:00
-
-
Save marcelstoer/7ae3e19c7be2847530fa63433637de60 to your computer and use it in GitHub Desktop.
NodeMCU Lua initializer with DNS & internet connectivity testing
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
WIFI_SSID = "--your-value-here--" | |
WIFI_PASSWORD = "--your-value-here--" | |
wifi_got_ip_event = function(T) | |
local site = "wikipedia.org" | |
-- Note: Having an IP address does not mean there is internet access! | |
-- Internet connectivity can be determined with net.dns.resolve(). | |
print("WiFi connection is established! IP address is: " .. T.IP) | |
print("DNS server 1: " .. net.dns.getdnsserver(0)) | |
print("DNS server 2: " .. net.dns.getdnsserver(1)) | |
net.dns.resolve(site, function(sk, ip) | |
if (ip == nil) then | |
print("DNS fail!") | |
else | |
print("Connected to the internet") | |
print(site .. " IP: " .. ip) | |
end | |
end) | |
end | |
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP, wifi_got_ip_event) | |
print("Connecting to WiFi access point...") | |
wifi.setmode(wifi.STATION) | |
wifi.sta.config({ ssid = WIFI_SSID, pwd = WIFI_PASSWORD }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment