I lost track of this thread and happened across it again today. I have been working with the ESP8266-01 for a while. I first wrote a managed AT driver for a Netduino, but was unsatisfied with the stability. I then moved on to the NodeMCU firmware which embeds a Lua (eLua) interpreter on the ESP. This firmware is remarkably stable and supports the larger ESP-12. The API supports PWM, 1-wire, I2C, SPI, ADC, MQTT and more. The disadvantage, of course is that you have to learn to do a little programming in Lua, but it is fairly easy. The firmware is here under pre_build and you flash it just like the AT firmware,
and the API instruction set,
For development, I use Lua Loader and a PC console TCP client for testing.
Flavor of Lua TCP server code example: (talk to ESP with PC console TCP client)
IP address obtained by init.lua. Automatically run on restart
– start server
– ============
– ============
srv=net.createServer(net.TCP)
srv:listen(5666,function(conn) --port
conn:on("receive",function(conn,payload)
print(payload)
– Start chain of if … then, elseif, else to process TCP commands (Lua has no Select Case)
– ===================================================================
if (string.find(payload, “X”) ~= nil) then
– First command processor switch to client mode to connect to NIST DayTime server
print('daytime.lua started')
local conn1 = nil
conn1=net.createConnection(net.TCP, 0)
--connect
conn1:connect(13,'utcnist2.colorado.edu')
-- show the server returned payload
conn1:on("receive", function(conn1, payload)
retval = '20'..string.sub(payload,8,14)..
string.sub(payload,15,24)
print('retval: ' .. retval)
conn:send(retval)
end) -- function(conn1, payload)
-- show disconnect
conn1:on("disconnection", function(conn1, payload) print('\nDisconnected') conn1=nil end)
– Second command processor (blink LED on gpio2)
elseif(string.find(payload, "Y") ~= nil) then
isOn = false
gpio0 = 3
gpio2 = 4
gpio.mode(gpio2, gpio.OUTPUT)
gpio.write(gpio2, gpio.LOW)
tmr.stop(1) -- There are now 0..7 timers
dly = 1000 -- miliseconds
tmr.alarm(1, dly, 1, function() --tmr(1), repeat
isOn = not isOn
if isOn then
gpio.write(gpio2,gpio.LOW)
else
gpio.write(gpio2,gpio.HIGH)
end
end) -- function
conn:send('gpio2 LED is blinking')
– third command processor (stop blink LED on gpio2)
elseif(string.find(payload, "Z") ~= nil) then
tmr.stop(1)
gpio.write(gpio2,gpio.LOW)
conn:send('gpio2 LED has stopped blinking')
– Default command processor (unknown command)
else
tosend = 'you sent: ' .. payload
conn:send(tosend)
end --if command processor chain
end) – conn:on(“receive” …
– Close server connection and continue to Listen for request
conn:on(“sent”,function(conn) conn:close() conn = nil end)
end) – srv:listen(5666,function(conn)
– End of TCP Server chunk
– ========================
– ========================