Hello,
API call triggered in the timer but not going to the next actions.
When I set the timer to m.top.deactivate = true then only the next actions are working.
I need to call the api in timer for every 5 sec.
Based on the API response I have to stop the timer and navigating to another screen.
Xml file:
<?xml version="1.0" encoding="UTF-8"?>
<component name="PollUrlTask" extends="Task">
<interface>
<field id="url" type="string" />
<field id="intervalSecs" type="integer" value="5" />
<field id="deactivate" type="boolean" />
<!-- watch this -->
<field id="result" type="string" />
</interface>
<script type="text/brightscript" uri="PollUrlTask.brs" />
</component>
PollUrlTask.brs :
function fetch1(url as string) as string
req = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
req.SetMessagePort(port)
req.setRequest("POST")
req.SetUrl(url)
if (left(url, 5) = "https") then req.SetCertificatesFile("common:/certs/ca-bundle.crt")
result = req.AsyncGetToString()
if result then
while true
msg = wait(0, port)
json = ParseJson(msg)
print "json.result.devicestatus" json.statusCode
if json.statusCode = 200
m.global.userToken = json.result.token
print "userToken11111111" m.global.userToken
if m.global.userToken <> invalid
m.top.deactivate = true
end if
else if json.statusCode = 401
activation()
end if
if type(msg) = "roUrlEvent" then
code = msg.GetResponseCode()
if code = 200 then
return msg.GetString()
else
return ""
end if
else
result.AsyncCancel()
return ""
end if
end while
end if
return ""
end function