Berkay (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
Berkay (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
||
Zeile 10: | Zeile 10: | ||
ws2812.init(); | ws2812.init(); | ||
local ledCount = 34; | local ledCount = 34; | ||
local leds = string.char(10,00,0):rep(ledCount) | local leds = string.char(10,00,0):rep(ledCount) | ||
local hadIP = false; | local hadIP = false; | ||
local tick = false; | local tick = false; | ||
function readjson(data) | function readjson(data) | ||
ok, json = pcall(cjson.decode, data) | ok, json = pcall(cjson.decode, data) | ||
if ok then | if ok then | ||
Zeile 25: | Zeile 25: | ||
print("failed to decode!") | print("failed to decode!") | ||
end | end | ||
end | end | ||
local pseudoRemote = {} | local pseudoRemote = {} | ||
for ledid = 1, ledCount, 1 do | for ledid = 1, ledCount, 1 do | ||
pseudoRemote[ledid]={} | pseudoRemote[ledid]={} | ||
pseudoRemote[ledid].r=100 | pseudoRemote[ledid].r=100 | ||
pseudoRemote[ledid].g=0 | pseudoRemote[ledid].g=0 | ||
pseudoRemote[ledid].b=ledid | pseudoRemote[ledid].b=ledid | ||
end | end | ||
local remoteData = cjson.encode(pseudoRemote); | local remoteData = cjson.encode(pseudoRemote); | ||
print(remoteData) | print(remoteData) | ||
local srv=net.createServer(net.TCP) | local srv=net.createServer(net.TCP) | ||
srv:listen(80,function(conn) | srv:listen(80,function(conn) | ||
conn:on("receive",function(conn,payload) | conn:on("receive",function(conn,payload) | ||
print("Got something...") | print("Got something...") | ||
Zeile 44: | Zeile 44: | ||
conn:send("Content-Type: text/html\n\n") | conn:send("Content-Type: text/html\n\n") | ||
end) | end) | ||
end) | end) | ||
local led1 = 0; | local led1 = 0; | ||
local led2 = 0; | local led2 = 0; | ||
local led3 = 0; | local led3 = 0; | ||
function countBlinks(eingabe) | function countBlinks(eingabe) | ||
while(eingabe > 0) do | while(eingabe > 0) do | ||
if(eingabe >= 100) then | if(eingabe >= 100) then | ||
Zeile 61: | Zeile 61: | ||
led3 = led3 +1 | led3 = led3 +1 | ||
eingabe = eingabe -1 | eingabe = eingabe -1 | ||
end | |||
end | |||
end | |||
end | end | ||
function update() | function update() | ||
ws2812.write(leds) | ws2812.write(leds) | ||
end | end | ||
local anSekunde = false; | local anSekunde = false; | ||
function blinkIP() | function blinkIP() | ||
anSekunde = not anSekunde | anSekunde = not anSekunde | ||
if(anSekunde) then | if(anSekunde) then | ||
Zeile 91: | Zeile 91: | ||
else | else | ||
ws2812.write(string.char(00,0,0):rep(ledCount)) | ws2812.write(string.char(00,0,0):rep(ledCount)) | ||
end | |||
end | end | ||
function wlaninit () | function wlaninit () | ||
if(not wifi.sta.getip())then | if(not wifi.sta.getip())then | ||
tick = not tick; | tick = not tick; | ||
Zeile 110: | Zeile 110: | ||
countBlinks(eingabe); | countBlinks(eingabe); | ||
tmr.alarm(0, 1000, tmr.ALARM_AUTO, blinkIP) | tmr.alarm(0, 1000, tmr.ALARM_AUTO, blinkIP) | ||
end | |||
end | |||
end | end | ||
tmr.alarm(0, 100, tmr.ALARM_AUTO, wlaninit) | tmr.alarm(0, 100, tmr.ALARM_AUTO, wlaninit) |
Version vom 1. Dezember 2016, 21:30 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
wifi.setmode(wifi.STATION) wifi.sta.config("SSID", "PW")
ws2812.init(); local ledCount = 34; local leds = string.char(10,00,0):rep(ledCount) local hadIP = false; 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)
local led1 = 0; local led2 = 0; local led3 = 0; function countBlinks(eingabe) while(eingabe > 0) do if(eingabe >= 100) then led1 = led1 +1 eingabe = eingabe -100 else if(eingabe >= 10) then led2 = led2 +1 eingabe = eingabe -10 else led3 = led3 +1 eingabe = eingabe -1 end end end end
function update() ws2812.write(leds) end local anSekunde = false; function blinkIP() anSekunde = not anSekunde if(anSekunde) then if led1 > 0 then ws2812.write(string.char(0,20,0)) led1 = led1 -1 return end if (led2 > 0) then ws2812.write(string.char(0,0,0) .. string.char(0,20,0)) led2 = led2 -1 return end if (led3 > 0) then ws2812.write(string.char(0,0,0):rep(2) .. string.char(0,20,0)) led3 = led3 -1 return end tmr.alarm(0, 100, tmr.ALARM_AUTO, update) else ws2812.write(string.char(00,0,0):rep(ledCount)) end end function wlaninit () 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; else if not hadIP then hadIP = true local IP = wifi.sta.getip() local o1,o2,o3,o4 = IP:match("(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)" ) local eingabe = tonumber(o4) countBlinks(eingabe); tmr.alarm(0, 1000, tmr.ALARM_AUTO, blinkIP) end end end tmr.alarm(0, 100, tmr.ALARM_AUTO, wlaninit)