The Wifi Project
last updated: Feb. 7, 2015
The ESP8266 is a 32 bit microcontroller with built-in wifi. The board I'm using has the ESP8266 with an antenna and a flash memory chip. It costs only $5. I've loaded an interpreter and wrote a few scripts to connect to my router and to log into an IRC channel.
Where I got the board
electrodragon.comWiring
Loading the LUA interpreter
Flashing tool with the LUA interpreterThis tool comes with obsolete firmware. I replaced it with NodeMCU build 20150126
- start the flashing tool
- select correct comm port
- go to the CONFIG tab
- disable first 4 lines
- enable 5th line and select the updated firmware file and an offset of 0.
- back to OPERATION tab
- disconnect power if powered
- ground GPIO0
- power the board
- disconnect the pin from ground
- press the FLASH button and wait for it to complete
script uploader
This is the tool for editing and loading of the scripts (for Windows)My scripts
connect to the router (file name: init.lua)
wifi.setmode(wifi.STATION)
wifi.sta.config ( "SSID" , "password" )
The IRC script
// Most of this script is from https://gist.github.com/gdamjan/64fb6d6152ed1f9c8178
channel = "#test14"
function connect_callback(conn)
conn:send("NICK robot222\r\n")
conn:send("USER user_name 8 * :real name\r\n")
conn:send("JOIN "..channel.."\r\n")
end
function receive_callback(conn, payload)
print(payload)
if string.find(payload, "PING :") == 1 then
conn:send("PONG :" .. string.sub(payload, 7))
end
pos = string.find(payload, "PRIVMSG "..channel.." :")
if pos ~= nil then
inmsg = string.sub(payload, pos + string.len(channel)+10)
conn:send("PRIVMSG "..channel.." :did you say something like "..inmsg.."? \r\n")
end
end
function startbot()
conn:on("receive", receive_callback)
conn:on("connection", connect_callback)
conn:connect(6667, "chat.freenode.net")
end
-- The script starts here
conn = net.createConnection(net.TCP, false)
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()==nil then
print("Waiting for connection...")
else
tmr.stop(1) -- maybe only stop it on successfull connection
startbot()
end
end)
--Script clips
-- conn:send("PRIVMSG #test14 :hi...\r\n")
-- conn:send("QUIT \r\n")
-- print(wifi.sta.status()) -- 5 is what we want