As the title says... Chat on...

User avatar
By matospaul
#13505 Hello All

I'm having some trouble with the following code:

Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.setmac("\002\001\002\003\003\006")

wifi.sta.config("XXX","YYY")


stripPin = 4   -- Comment: GPIO2
local data
s=net.createServer(net.UDP)

s:on("receive",function(s,c)
   
    for i = 126, 276 do
            data = data .. string.char(c,i)
          end
    ws2812.writergb(stripPin, data) end)
s:listen(5568)


I'm trying to pass a string from the incoming UDP data (bytes 126 through 276) to the ws2812 function. The line data = data .. string.byte(c,i) throws an error. Here is the error:

PANIC: unprotected error in call to Lua API (init.lua:18: attempt to concatenate local 'data' (a nil value))

I'm sure I'm not passing this data correctly. Any help would be greatly appreciated.
User avatar
By cal
#13508
matospaul wrote:Hello All
Here is the error:

PANIC: unprotected error in call to Lua API (init.lua:18: attempt to concatenate local 'data' (a nil value))

I'm sure I'm not passing this data correctly. Any help would be greatly appreciated.


Moin,

initialize data with "" so that it isn't nil.
Code: Select alllocal data = ""


Carsten