After running once I get: attempt to index global 'os' (a number value)

I’ve written a new script for my sonos which will tell me the time, my morning motivation (TBD), and read me the last 24 hours of work emails (subject, time, sender). However I can run this script once (it does take like 9 seconds to run), then after that all of my os.date() functions stop working. If I restart Vera, everything comes back, until I run it again.

Is it a performance thing? Resources? Code?

[code]function sonosemails()

local emails = getemails()
local saypastemails = "I will now brief you on your unread emails from the last 24 hours. "

for k, v in pairs(emails) do
for k, v in pairs(emails[k]) do
–print(k, “:”, v)
if(k == 1) then
saypastemails = saypastemails … " Received " … v
elseif(k == 2) then
saypastemails = saypastemails … " From " … v
else
saypastemails = saypastemails … " with the subject " … v … "… "
end
end
end
return saypastemails
end

local AV_DEV = 53
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
local time = os.date(‘%I:%M’)
local TEMP_SID = “urn:upnp-org:serviceId:TemperatureSensor1”
local currenttemp = luup.variable_get(TEMP_SID, “CurrentTemperature”, 41)
local hightemp = luup.variable_get(TEMP_SID, “CurrentTemperature”, 43)
local weatherc = luup.variable_get(“urn:upnp-micasaverde-com:serviceId:Weather1”,“Condition”, 40)
local morningmot = “Do better.”
local ems = sonosemails()

luup.call_action(LS_SID, “Say”,
{Text = string.format(“Good Morning! The current time is %s. The weather today is %s with the current temp at %s, and a high of %s. Today your morning motivation is %s. %s”, time, weatherc, currenttemp, hightemp, morningmot, ems)}
, AV_DEV)[/code]

Just as a follow up.
I sshed into my Vera.
When everything is working (before running the lua) my Vera has 10MB of ram free, 22MB cached, and normal CPU load of 15%.

When I run my lua, it I do see CPU spike to close to 50%, and ram free stays around the same.

I am not sure but it doesn’t seem to be a resource type of error. Maybe it is my code. I will have to keep breaking it down to figure it out section by section.

I mean it is a dog. It takes 9 seconds to run… ouch.

The global Lua variable os should be a table type. If the error message you are getting says it’s a number then something has overwritten it. Check all of your Lua code in all of your scenes and make sure you haven’t accidentally blatted over it.

Well I feel stupid…

dc1, os = string.find(outputheaders,"OutlookSession=")

Thanks for the feedback futzle!