[quote=“Bulldoglowell, post:3, topic:180402”]OK, I created a URL that will return my unread email quantity using googlescript and this gentleman’s solution:
This gives me a URL to call, which when I go to that URL, it returns the following string:
0 There are 0 unread messages in my Gmail Inbox. (when empty) &
15 There are 15 unread messages in my Gmail Inbox. (when non empty)
I am trying to use wget to grab that string, test the first character and look for the zero, but I know luup.inet.wget returns two variables, I am just struggling with how to get the string portion. It looks like it is returning the return status successful number {0}, meaning that the following code will only return an OFF to my Virtual Switch.
local htmstatus, mailcount = luup.inet.wget("https://script.google.com/macros/s/AKfycbyu8TRKPQzJwlYYTcRCpO6b2zShRJ686G846pxG28v2vsvOQoDX/exec")
count = string.sub(mailcount,1,1)
if count == "0"
then
luup.variable_set("urn:upnp-org:serviceId:VSwitch1","Status", 0 ,10)
else
luup.variable_set("urn:upnp-org:serviceId:VSwitch1","Status", 1 ,10)
end
I need a little help with luup.inet.wget.[/quote]
If wget returns numerical zero in the first variable, the request was successful. You should be able to extract the count from the string in the second variable. If it doesn’t work, you will need to check the exact format of the string. It could be in json format or with some xml tags. May I humbly suggest that LuaTest would help you out? If you added a few print statements you would soon see what you were getting back.
local htmstatus, mailcount = luup.inet.wget("https://script.google.com/macros/s/AKfycbyu8TRKPQzJwlYYTcRCpO6b2zShRJ686G846pxG28v2vsvOQoDX/exec")
print("htmstatus: " .. htmstatus)
print("mailcount:" .. mailcount)
count = string.sub(mailcount,1,1)
print("count: " .. count)
if count == "0"
then
luup.variable_set("urn:upnp-org:serviceId:VSwitch1","Status", 0 ,10)
else
luup.variable_set("urn:upnp-org:serviceId:VSwitch1","Status", 1 ,10)
end
If htmstatus returns non-zero, then there is either something wrong with your url or it could have timed-out. wget has a default timeout of five seconds. You can change this by appending ,10 or whatever to the wget call arguments.