I have a function in my startup Lua that I use to make announcements (speech handled by an outside machine). Occasionally something’ll happen where multiple events trigger it at the same time and it sometimes causes Luup to restart.
Since I’m using a common function, it occurs to me that I should be able to set a global “busy” variable and delay any other concurrent HTTP call. Can someone help me with the coding for this? Would I use a luup.cal_delay?
Here’s my function. Some of the function makes sure that my wife and I are awake before text is spoken. It takes an optional argument that’ll override muting when we’re sleeping - for emergency announcements.
function speak(text,unmute)
unmute = unmute or 0
local s_awake = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 47)
local h_awake = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 48)
s_awake = tonumber(s_awake)
h_awake = tonumber(h_awake)
if ( ( (h_awake == 1) and (s_awake == 1) ) or unmute == 1) then
t = escape(text)
speakurl = "http://192.168.1.100/say/?t=" .. t
http = require("socket.http")
local body, code, headers, status = http.request(speakurl)
end
end