DaveAppleton / ws2812-nodeMCU

ESP8266 WebServer controlling a single WS2812 using nodeMCU / Lua
5 stars 1 forks source link

code panics on nodemcu latest. #1

Open alberto148 opened 8 years ago

alberto148 commented 8 years ago

PANIC: unprotected error in call to Lua API (init.lua:55: attempt to call field 'writergb' (a nil value))

alberto148 commented 8 years ago

--here is the fix. -alberto148

wifi.setmode(wifi.STATION) wifi.sta.config("ssid","password") print(wifi.sta.getip()) gpio2 = 4 gpio.mode(gpio2, gpio.OUTPUT) ws2812.init() srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(client,request) if (string.find(request,"favicon") ~= nil) then return end print("request received") print(request) local buf = ""; local , , method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(method == nil)then , , method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end local _GET = {} if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end local redchecked,greenchecked,bluechecked = "","","" red,green,blue = 0,0,0 if(_GET.red == "red")then --gpio.write(led1, gpio.HIGH); red = 255 redchecked = " checked " end if(_GET.green == "green")then green = 255 greenchecked = " checked " end if(_GET.blue == "blue")then -- gpio.write(led2, gpio.LOW); blue = 255 bluechecked = " checked " end buf = buf.."

ESP8266 Web Server

"; buf = buf.."

RED <input type=checkbox name=red value=red " buf = buf..redchecked buf = buf..">

"; buf = buf.."

GREEN <input type=checkbox name=green value=green " buf = buf..greenchecked buf = buf..">

"; buf = buf.."

BLUE <input type=checkbox name=blue value=blue " buf = buf..bluechecked buf = buf..">

" buf = buf.."

" --red = 255 --green = 0 --blue = 0 ws2812.write(string.char(red,green, blue)) tmr.delay(1000000) client:send(buf); client:close(); collectgarbage(); end) end)