Welcome to Smart Home Forum by FIBARO
Search the Community
Showing results for tags 'repeat/until'.
When I plugin the plug in the power socket from my denon receiver, internally the unit is initializing different settings, like network, etc... when i plugin the unit, the receiver is set to standby, ok. I want to make a lua code whereby it makes a loop with repeat / until...until i get a code back from the unit if it's in standby mode, or on mode, from there it should continue, see below. but it's skips the repeat/until... When the unit is plugged in, no code is been returned... So i was thinking: instead of this: "if not(trim(result) == "PWON" or "PWSTANDBY") then" use "if (trim(result) == """) then" Are there other ways to detect an empty string ? With other words: When no code is been returned, stay in this loop until PWON or PWSTANDBY is been returned. fibaro:log("Connecting..."); tcpSocket = Net.FTcpSocket("10.0.1.155", 23); tcpSocket:setReadTimeout(1000); function trim(s) -- trim leading and trailing whitespaces -- return (s:gsub("^%s*(.-)%s*$", "%1")) end -- Denon is Initializing it's Network -- repeat fibaro:sleep(2000); tcpSocket:write(string.char(0x50, 0x57, 0x3f, 0x0d)); -- requesting for the PWON or PWSTANDBY status ? fibaro:sleep(500); result, err = tcpSocket:read(); tcpSocket:disconnect(); fibaro:debug("Denon Receiver..."..result); if (err == 0) then if not(trim(result) == "PWON" or "PWSTANDBY") then fibaro:sleep(1000) fibaro:debug("...is Initializing"); end end until (trim(result) == "PWON" or "PWSTANDBY") fibaro:debug("Ready to Receive Data: "..result); -- Rest of the code -- Please some help would be appreciated. Thankss a lot