Berkay (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
Berkay (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
||
Zeile 9: | Zeile 9: | ||
wifi.setmode(wifi.STATION) | wifi.setmode(wifi.STATION) | ||
wifi.sta.config("SSID", "PW") | wifi.sta.config("SSID", "PW") | ||
wifi.setmode(wifi.STATION) | |||
ws2812.init(); | wifi.sta.config("C3MA", "chaosimquadrat") | ||
ws2812.init(); | |||
local ledCount = 34; | |||
local leds = string.char(10,00,0):rep(ledCount) | |||
local tick = false; | |||
function readjson(data) | |||
ok, json = pcall(cjson.decode, data) | |||
if ok then | |||
leds = "" | |||
for ledid = 1, ledCount, 1 do | |||
local ledData = json[ledid]; | |||
leds = leds .. string.char(ledData.g,ledData.r,ledData.b) | |||
end | |||
else | |||
print("failed to decode!") | |||
end | |||
end | |||
local pseudoRemote = {} | |||
for ledid = 1, ledCount, 1 do | |||
pseudoRemote[ledid]={} | |||
pseudoRemote[ledid].r=100 | |||
pseudoRemote[ledid].g=0 | |||
pseudoRemote[ledid].b=ledid | |||
end | |||
local remoteData = cjson.encode(pseudoRemote); | |||
print(remoteData) | |||
local srv=net.createServer(net.TCP) | |||
srv:listen(80,function(conn) | |||
conn:on("receive",function(conn,payload) | |||
print("Got something...") | |||
print(payload); | |||
readjson(payload) | |||
conn:send("HTTP/1.1 200 OK\n") | |||
conn:send("Content-Type: text/html\n\n") | |||
end) | |||
end) | |||
function update () | function update () | ||
if(not wifi.sta.getip())then | |||
tick = not tick; | |||
if(tick)then | |||
ws2812.write(string.char(0,0,20):rep(ledCount)) | |||
else | |||
ws2812.write(string.char(0,0,0):rep(ledCount)) | |||
end | |||
return; | |||
end | |||
ws2812.write(leds) | |||
end | end | ||
tmr.alarm(0, 100, tmr.ALARM_AUTO, update) | tmr.alarm(0, 100, tmr.ALARM_AUTO, update) | ||
Version vom 14. Oktober 2016, 21:14 Uhr
Dies ist ein Projekt, an dem momentan aktiv gearbeitet wird. Wenn du Fragen hast oder mitarbeiten möchtest, wende dich an Berkay.
Hier wird der bisherige Projektcode von dem Projekt Light Cube reingestellt. Die Projektseite: Light_Cube
ESP-Platine/Bauteil ESP NodeMCU Devboard
Verbindung mit dem WLAN herstellen:
wifi.setmode(wifi.STATION) wifi.sta.config("SSID", "PW") wifi.setmode(wifi.STATION) wifi.sta.config("C3MA", "chaosimquadrat") ws2812.init(); local ledCount = 34; local leds = string.char(10,00,0):rep(ledCount) local tick = false; function readjson(data) ok, json = pcall(cjson.decode, data) if ok then leds = "" for ledid = 1, ledCount, 1 do local ledData = json[ledid]; leds = leds .. string.char(ledData.g,ledData.r,ledData.b) end else print("failed to decode!") end end local pseudoRemote = {} for ledid = 1, ledCount, 1 do pseudoRemote[ledid]={} pseudoRemote[ledid].r=100 pseudoRemote[ledid].g=0 pseudoRemote[ledid].b=ledid end local remoteData = cjson.encode(pseudoRemote); print(remoteData) local srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive",function(conn,payload) print("Got something...") print(payload); readjson(payload) conn:send("HTTP/1.1 200 OK\n") conn:send("Content-Type: text/html\n\n") end) end) function update () if(not wifi.sta.getip())then tick = not tick; if(tick)then ws2812.write(string.char(0,0,20):rep(ledCount)) else ws2812.write(string.char(0,0,0):rep(ledCount)) end return; end ws2812.write(leds) end tmr.alarm(0, 100, tmr.ALARM_AUTO, update)
Hauptsteuereinheit
--