Light Cube/Projektcode: Unterschied zwischen den Versionen

Aus C3MAWiki
Zur Navigation springenZur Suche springen
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Zeile 4: Zeile 4:




'''ESP-Platine/Bauteil ESP NodeMCU Devboard'''
== ESP-Platine/Bauteil ESP NodeMCU Devboard ==
----
 
     wifi.setmode(wifi.STATION)
     wifi.setmode(wifi.STATION)
     wifi.sta.config("SSID", "PW")
     wifi.sta.config("SSID", "PW")
    ws2812.init();
 
    local ledCount = 34;
  ws2812.init();  
    local leds = string.char(10,00,0):rep(ledCount)
local ledCount = 34;
    local tick = false;
local leds = string.char(10,00,0):rep(ledCount)  
    function readjson(data)
local hadIP = false;
        ok, json = pcall(cjson.decode, data)
local tick = false;
        if ok then
function readjson(data)
            leds = ""
    ok, json = pcall(cjson.decode, data)
            for ledid = 1, ledCount, 1 do
    if ok then
                local ledData = json[ledid];
        leds = ""
                leds = leds .. string.char(ledData.g,ledData.r,ledData.b)
        for ledid = 1, ledCount, 1 do
            end
            local ledData = json[ledid];
        else
            leds = leds .. string.char(ledData.g,ledData.r,ledData.b)
        print("failed to decode!")
         end
         end
    else
    print("failed to decode!")
     end
     end
    local pseudoRemote = {}
end
    for ledid = 1, ledCount, 1 do
local pseudoRemote = {}
        pseudoRemote[ledid]={}
for ledid = 1, ledCount, 1 do
        pseudoRemote[ledid].r=100
    pseudoRemote[ledid]={}
        pseudoRemote[ledid].g=0
    pseudoRemote[ledid].r=100
        pseudoRemote[ledid].b=ledid
    pseudoRemote[ledid].g=0
    end
    pseudoRemote[ledid].b=ledid
    local remoteData = cjson.encode(pseudoRemote);
end
    print(remoteData)
local remoteData = cjson.encode(pseudoRemote);
    local srv=net.createServer(net.TCP)
print(remoteData)
    srv:listen(80,function(conn)
local srv=net.createServer(net.TCP)
        conn:on("receive",function(conn,payload)
srv:listen(80,function(conn)
            print("Got something...")
    conn:on("receive",function(conn,payload)
            print(payload);
        print("Got something...")
            readjson(payload)
        print(payload);
            conn:send("HTTP/1.1 200 OK\n")
        readjson(payload)
            conn:send("Content-Type: text/html\n\n")
        conn:send("HTTP/1.1 200 OK\n")
        end)
        conn:send("Content-Type: text/html\n\n")
     end)
     end)
     function update ()
end)
         if(not wifi.sta.getip())then
 
             tick = not tick;
local led1 = 0;
             if(tick)then
local led2 = 0;
                 ws2812.write(string.char(0,0,20):rep(ledCount))
local led3 = 0;
             else  
function countBlinks(eingabe)
                 ws2812.write(string.char(0,0,0):rep(ledCount))
     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
            return;
         end
         end
      ws2812.write(leds)
     end
     end
    tmr.alarm(0, 100, tmr.ALARM_AUTO, update)     
end


 
function update()
'''Hauptsteuereinheit'''
    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)

Version vom 1. Dezember 2016, 22:29 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)