So I've been playing around with telnet commanding and status with my TivoHD, and I keep getting network drops that I can't seem to recover from. When the activity first loads, things work fine for a while, which may be anywhere from a couple minutes to more than half an hour. But invariably, at some point, things stop working.
I am fairly sure the issue is with the Pronto, not the Tivo, because 1) other tools including putty and a control util written by someone at tivocommunity work fine and do not disconnect. 2) I can usually re-establish comms by going to the home page and back to the tivo activity, at which point things again work for a while.
The TivoHD telnet feature is described here (not sure there's any official documentation yet...):
[Link: tivocommunity.com]It is nowhere near as comprehensive as, say, the Denon protocol (working fine via telnet for me, incidentally), but it does allow basic commanding and retrieving channel and recording status.
I've tried a variety of page timers, scheduleAfter, etc. to monitor/keepalive, but no luck. I've tried with the Tivo and pronto on the same subnet, which is not how I normally have things configured, but no luck with that either. If anyone has any suggestions, I'd love to hear them.
Thanks,
Eric
Here is the code as it stands now. This is eval'ed at the activity level and kicked off by calling connectionSetupTivo.
// Tivo Comms
// Global vars
var socketTivo = null;
var socketStatusTivo = "down";
// Response processing =====================================================
function processInputTivo(sString)
{
var tmpString;
var aResults = sString.split(String.fromCharCode(13));
var i;
for (i=0; i
{
tmpString = aResults[i];
System.print(tmpString);
if(tmpString.substr(0,9)=="CH_STATUS" && CF.widget("TIVOCHANNEL")) {
CF.widget("TIVOCHANNEL").label = "Ch: " + parseInt(tmpString.substr(10,4),10); }
if(tmpString.substr(0,9)=="CH_STATUS" && CF.widget("TIVOCHANNELREC")) {
CF.widget("TIVOCHANNELREC").visible = (tmpString.substr(15,3) == "REC"); }
}
}
// Connection handling ===================================================
function onConnectTivo()
{
System.print("Tivo: Connected");
socketStatusTivo = "up";
if (CF.widget("SOCKET_CLOSE","PS_SYSTEM","PS_SYSTEM"))
{ CF.widget("SOCKET_CLOSE","PS_SYSTEM","PS_SYSTEM").label = ""; }
if (CF.widget("SOCKET_ERROR","PS_SYSTEM","PS_SYSTEM"))
{ CF.widget("SOCKET_ERROR","PS_SYSTEM","PS_SYSTEM").label = ""; }
}
function onDataTivo()
{
var myString;
System.print("Tivo: Received Data");
socketStatusTivo = "receiving";
myString = socketTivo.read();
processInputTivo(myString);
}
function onCloseTivo()
{
System.print("Tivo: Connection Closed");
socketStatusTivo = "down";
socketTivo=null;
if (CF.widget("SOCKET_CLOSE","PS_SYSTEM","PS_SYSTEM"))
{ CF.widget("SOCKET_CLOSE","PS_SYSTEM","PS_SYSTEM").label = "T"; }
}
function onIOErrorTivo(e)
{
System.print("Tivo: Connection Failed");
System.print("Tivo: " + e);
socketStatusTivo = "error";
socketTivo=null;
if (CF.widget("SOCKET_ERROR","PS_SYSTEM","PS_SYSTEM"))
{ CF.widget("SOCKET_ERROR","PS_SYSTEM","PS_SYSTEM").label = "T"; }
}
function connectionSetupTivo()
{
System.print("Tivo: Setting Up");
socketStatusTivo = "pending";
if (socketTivo && socketTivo.connected) { socketTivo.close(); }
socketTivo = null;
socketTivo = new TCPSocket(false);
socketTivo.connect("192.168.5.199",31339,3000);
socketTivo.onConnect=onConnectTivo;
socketTivo.onData=onDataTivo;
socketTivo.onClose=onCloseTivo;
socketTivo.onIOError=onIOErrorTivo;
}
// Send commands ========================================================
function sendCommandsTivo(cmdList)
{
var cmd;
var i;
if (socketTivo && socketTivo.connected)
{
for (i=0; i{
cmd = cmdList[i];
System.print("Tivo: Sending: " + cmd);
socketTivo.write(cmd + "\r");
System.delay(25);
}
}
else
{
if (socketStatusTivo !== "pending")
{
connectionSetupTivo();
}
scheduleAfter(250,sendCommandsTivo,cmdList);
}
}