Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Working with Device Registration Example Code

I am a new Roku developer and am just getting started with BrightScript.

I have the Device Registration example code running on my Roku HD3 and this is talking to a local server running PHP. The process works, but I have noticed that the while loop with the delay doesn't really get executed. I've logged all of the GET/POST calls to the server and it seems that the Roku is making hundreds of requests to the "getRegResult" endpoint - this is within the "checkRegistrationStatus" function.

Can anyone point me in the right direction to getting this example code working properly (eg using the retryInterval/retryDuration variables)

Thanks,
Alex
0 Kudos
2 REPLIES 2
belltown
Roku Guru

Re: Working with Device Registration Example Code

"AlexHolsgrove" wrote:
I am a new Roku developer and am just getting started with BrightScript.

I have the Device Registration example code running on my Roku HD3 and this is talking to a local server running PHP. The process works, but I have noticed that the while loop with the delay doesn't really get executed. I've logged all of the GET/POST calls to the server and it seems that the Roku is making hundreds of requests to the "getRegResult" endpoint - this is within the "checkRegistrationStatus" function.

Can anyone point me in the right direction to getting this example code working properly (eg using the retryInterval/retryDuration variables)

Thanks,
Alex

I just ran the example code "as is" (getting the registration code from rokudev.roku.com.) It seems to work just fine (sort of).

I'm not sure why there's a loop in checkRegistrationStatus. It's supposed to make a single request to the server and return a value indicating whether the user has registered yet. If you want to simulate the user not having registered, and the main loop polling (the one in doRegistration), then add this line of code in checkRegistrationStatus after token = e.GetBody()

token = ""	' Simulate failing to get registration code


If I were you, I'd re-write checkRegistrationStatus. The Roku code looks very strange. For instance, there's code to extract customerId and creationTime elements from the response, but it will never get executed if they come after the regToken element, neither will the print statement and return statement at the end of the function. And the code will end up in an infinite loop if the server returns a result containing no regToken element.

If your code is looping in checkRegistration it might be because there's something messed up with the response your PHP server is returning [most likely your server is returning a <result> but no <regToken> element]. Try putting some code in checkRegistrationStatus to print the server response. E.g. after rsp = http.Http.GetToString()

print "Registration Status Response: " + rsp


Run the Roku example code "as is" then run the code against your PHP server and compare the responses to see if your server is returning the same format response as the Roku server.
0 Kudos

Re: Working with Device Registration Example Code

I think I found the problem. If there is no regToken in the XML response then the code loops frantically. Try changing

if e.GetName() = "regToken" then


to something like

if e.GetName() = "intentionallyInvalid" then


And it will poll the server repeatedly.

http://sdkdocs.roku.com/plugins/viewsource/viewpagesrc.action?pageId=3114169
The SDK Docs say that the "pending" response was supposed to look like this:

<?xml version="1.0"?>
<result>
<status>incomplete</status>
</result>


So I guess the best method would be to check the status first, and then check all of the fields are present and not empty - and then either store the data, or return "3" to retry in 30 seconds.

The example code for this is rather poor, and for something as important as device registration! Perhaps Roku can re-write this example with better error checking!

Thanks again for your help.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.