Your Digital Media Has Never Looked So Good

 
renojim
** Valued Community Member **
Topic Author
Posts: 3490
Joined: Mon Feb 15, 2010 1:35 pm

Debugging pkgs with DbgPrint

Thu Nov 26, 2015 2:29 am

I came up with this when I wanted to see what was going on with the roChannelStore process using real transactions, not just simulated ones from sideloaded apps and this post spurred me on to post my technique for "printing" from installed pkgs. It won't get you error messages like you'd get from the debug console, but if you pepper your code with enough DbgPrints you ought to be able to figure out what's going on.

First, you'll need netcat. That link is for the windows version, but there's also versions for *nix. Netcat runs from the command line. To listen for the DbgPrints from your channel, you use the command:
nc -L -p 6666 -w 1

The port it listens on can be anything you want; I use 6666. The -L (note: capital L) tells it to listen and not close the connection after each message ("listen harder"). The -w 1 tells it to timeout after one second. I don't think it's necessary since I use async requests in DbgPrint, but I don't think it can hurt either.

Now for DbgPrint:
Sub DbgPrint(text as String)
    print "DbgPrint: ";text
    ' On laptop run:  nc -L -p 6666 -w 1
    if not m.JT then return

    server = "http://192.168.0.100:6666"
    port = CreateObject("roMessagePort")

    xfer = CreateObject("roUrlTransfer")
    xfer.SetPort(port)
    xfer.setUrl(server)
    xfer.AsyncPostFromString(text+chr(10)+chr(10))
    sleep(100)
    xfer.AsyncCancel()
    sleep(100)
End Sub

I use the global m.JT in most of my channels to tell when my code is running on one of my boxes (it's set depending on the device ID from roDeviceInfo->GetDeviceUniqueId). I use it here so that I can leave this in my final code (I don't usually strip out extraneous prints) and it won't have any effect if it's not running on one of my boxes.

To use it within your code, you have to make sure you convert everything to one string first. It's helpful to combine multiple prints into one call using chr(10) to split things on different lines because netcat spits out a lot of header stuff that makes multiple prints take up a lot of screen space:
DbgPrint("x = " + x.toStr() + chr(10) + "y = " + y.toStr())
Putting multiple things in one call also speeds things up. This will slow down your code a little.

You'll want to set server to the IP address of the computer you'll be using for netcat. It would be better if it wasn't hard-coded, but I don't think I'll ever change the IP address of my development computer.

I've used other methods of POSTing back to my server and saving logs to files, but I much prefer the realtime nature of this. There's certainly plenty of room for improvement, for example you can only print strings, but this has been helpful to me and I hope it's helpful to others.

-JT
 
User avatar
knuckle
** Valued Community Member **
Posts: 4689
Joined: Fri Jul 08, 2011 6:16 pm
Location: Florida,USA

Re: Debugging pkgs with DbgPrint

Thu Nov 26, 2015 7:09 am

pretty neat Jim ,thanks
ROKU 3 4114AT076252
ROKU 2 LT 16A182002191
ROKU 2 LT #2 16A19K025194
ROKU HD 18D2CP067635
Roku TV 2N002P050587 2WE012050587
ROKU HDMI STICK 5S35CF000124
Roku Express + YU000X236772
all running wireless on a Technicolor C2000T
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Debugging pkgs with DbgPrint

Thu Dec 03, 2015 1:08 pm

neat idea!

on a *nix the syntax needed seems to be
$ nc -kl 1234

That also spits HTTP flotsam on screen, doesn't it? Wouldn't it be cleaner to use roDataGramSocket/roStreamSocket on Roku side or enable the web server on computer's side and then read its log?
 
renojim
** Valued Community Member **
Topic Author
Posts: 3490
Joined: Mon Feb 15, 2010 1:35 pm

Re: Debugging pkgs with DbgPrint

Thu Dec 03, 2015 8:47 pm

I thought about sockets, but it's been a while since I did anything with them so while it's possible that they would be better, I didn't feel like taking the time to relearn how to use them.

I haven't tried nc on *nix; I just know it exists. If it eliminates the flotsam and jetsam, then I'll definitely have to give it a try.

I've used logging to files before, but I much prefer the immediate feedback that netcat gives.

-JT
 
adamkaz
Posts: 116
Joined: Sun Jan 11, 2009 2:23 pm

Re: Debugging pkgs with DbgPrint

Fri Dec 04, 2015 5:54 am

Liking this so I can come back later - needed an easy way to debug live channels for Roku billing. Looks like this will help!
 
MatroxRT
Posts: 27
Joined: Thu Mar 12, 2015 2:03 pm

Re: Debugging pkgs with DbgPrint

Fri Dec 04, 2015 10:50 am

Nice tip @RenoJim! Debugging In-App Purchasing can be a sore point in development for sure!

Who is online

Users browsing this forum: No registered users and 13 guests