Skip to content

Instantly share code, notes, and snippets.

@smcl
Last active January 26, 2016 16:49
Show Gist options
  • Save smcl/2949b9c3ed67d9a19cc5 to your computer and use it in GitHub Desktop.
Save smcl/2949b9c3ed67d9a19cc5 to your computer and use it in GitHub Desktop.
-- init.lua
--
-- Simple lua script to get started. Will blink the esp8266's
-- onboard LED while not connected to a wifi access point, and
-- keep it lit up after a connection is established
seconds = 1000
ledBlinkTimer = 1
ledBlinkTimeout = seconds / 10
ledPin = 4
ledStatus = gpio.LOW
function blinkWifiStatus()
ip, nm, gw = wifi.sta.getip()
if not ip then
if ledStatus == gpio.HIGH then
ledStatus = gpio.LOW
else
ledStatus = gpio.HIGH
end
else
ledStatus = gpio.LOW
end
gpio.write(ledPin, ledStatus)
end
gpio.mode(ledPin, gpio.OUTPUT)
tmr.alarm(ledBlinkTimer, ledBlinkTimeout, tmr.ALARM_AUTO, blinkWifiStatus)
wifi.setmode(wifi.STATION)
-- uncommenting the following would connect to a wifi network "MyAccessPoint"
-- using the password "MyPassword"
-- wifi.sta.config("MyAccessPoint", "MyPassword")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment