Author Topic: TCP Plugin and Tivos  (Read 9763 times)

0 Members and 2 Guests are viewing this topic.

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
TCP Plugin and Tivos
« on: March 20, 2014, 05:21:47 PM »
Not sure if I should tag this on the end of this topic or start a new one.

I'm trying to put together a set of commands to control networked Tivos (Virgin Media Tivo here in the UK, Tivo Premiere etc in US)

I'm using the TCP plugin and I've got it working almost all of the time but, and this is the strange bit, only when running the code from the editor. When I try to use Voice it always fails.

Command:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1609" name="tivo power toggle" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="On my Virgin Media TV it requires the power button to be pressed twice to turn off. &#xD;&#xA;Whilst not required to press twice to turn on it does no harm and allows me to have a single event to toggle off/on">
  <action>
    <cmdType>Tcp.Client.Connect</cmdType>
    <cmdString>tivotcp&amp;&amp;192.168.18.22&amp;&amp;31339&amp;&amp;\x0d</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Tcp.Client.Write</cmdType>
    <cmdString>tivotcp&amp;&amp;IRCODE STANDBY\x0d&amp;&amp;1000</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Tcp.Client.Write</cmdType>
    <cmdString>tivotcp&amp;&amp;IRCODE STANDBY\x0d&amp;&amp;1000</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TCP.Client.Disconnect</cmdType>
    <cmdString>tivotcp</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>tivo power</phrase>
  <event>tivo_toggle</event>
</command>
Annotated log
Code: [Select]
Garry - This was a voice command
20/03/2014 20:12:04 658 doCommand:tivo power toggle
20/03/2014 20:12:04 658 action repeat set to: 1
20/03/2014 20:12:04 658 Action:  Tcp.Client.Connect - tivotcp&&192.168.18.22&&31339&&\x0d
20/03/2014 20:12:04 658 [action] Tcp.Client.Connect:tivotcp&&192.168.18.22&&31339&&\x0d

20/03/2014 20:12:04 658 [plugin] Tcp: New thread created for client: tivotcp
20/03/2014 20:12:08 215 [vcevent] TCP.StartListen.tivotcp

20/03/2014 20:12:08 215 action repeat set to: 1
20/03/2014 20:12:08 215 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:08 215 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:08 215 [plugin] Tcp: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
20/03/2014 20:12:08 215 [vcevent] TCP.ClientError.tivotcp

20/03/2014 20:12:08 215 action repeat set to: 1
20/03/2014 20:12:08 215 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:08 215 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:08 215 Event Error: Thread was being aborted.
20/03/2014 20:12:08 215 [vcevent] TCP.EndListenLoop.tivotcp

20/03/2014 20:12:08 215 [vcevent] TCP.StartListen.tivotcp

20/03/2014 20:12:08 215 [vcevent] TCP.Reconnecting.tivotcp

20/03/2014 20:12:08 215 [plugin] Tcp: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
20/03/2014 20:12:10 288 [vcevent] TCP.ClientError.tivotcp

20/03/2014 20:12:10 288 action repeat set to: 1
20/03/2014 20:12:10 288 Action:  TCP.Client.Disconnect - tivotcp
20/03/2014 20:12:10 288 [action] TCP.Client.Disconnect:tivotcp

20/03/2014 20:12:10 288 [vcevent] TCP.EndListenLoop.tivotcp
Garry -- now try same thing from editor
20/03/2014 20:12:20 518 [vcevent] VC.OpenEditor

20/03/2014 20:12:20 518 options: loading options
20/03/2014 20:12:20 518 options: verifying speech engine culture language
20/03/2014 20:12:33 293 doCommand:tivo power toggle
20/03/2014 20:12:33 293 action repeat set to: 1
20/03/2014 20:12:33 293 Action:  Tcp.Client.Connect - tivotcp&&192.168.18.22&&31339&&\x0d
20/03/2014 20:12:33 293 [action] Tcp.Client.Connect:tivotcp&&192.168.18.22&&31339&&\x0d

20/03/2014 20:12:33 293 [plugin] Tcp: New thread created for client: tivotcp
20/03/2014 20:12:33 293 [vcevent] TCP.StartListen.tivotcp

20/03/2014 20:12:33 293 action repeat set to: 1
20/03/2014 20:12:33 293 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:33 293 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:33 293 action repeat set to: 1
20/03/2014 20:12:33 293 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:33 293 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:35 325 action repeat set to: 1
20/03/2014 20:12:35 325 Action:  TCP.Client.Disconnect - tivotcp
20/03/2014 20:12:35 325 [action] TCP.Client.Disconnect:tivotcp

20/03/2014 20:12:35 325 [vcevent] TCP.EndListenLoop.tivotcp

20/03/2014 20:12:41 652 doCommand:tivo power toggle
20/03/2014 20:12:41 652 action repeat set to: 1
20/03/2014 20:12:41 652 Action:  Tcp.Client.Connect - tivotcp&&192.168.18.22&&31339&&\x0d
20/03/2014 20:12:41 652 [action] Tcp.Client.Connect:tivotcp&&192.168.18.22&&31339&&\x0d

20/03/2014 20:12:41 652 [plugin] Tcp: New thread created for client: tivotcp
20/03/2014 20:12:41 652 [vcevent] TCP.StartListen.tivotcp

20/03/2014 20:12:41 652 action repeat set to: 1
20/03/2014 20:12:41 652 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:41 652 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:41 652 action repeat set to: 1
20/03/2014 20:12:41 652 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:41 652 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:43 686 action repeat set to: 1
20/03/2014 20:12:43 686 Action:  TCP.Client.Disconnect - tivotcp
20/03/2014 20:12:43 686 [action] TCP.Client.Disconnect:tivotcp

20/03/2014 20:12:43 686 [vcevent] TCP.EndListenLoop.tivotcp
Garry - editor closed now trying with voice command again
20/03/2014 20:12:50 409 doCommand:tivo power toggle
20/03/2014 20:12:50 409 action repeat set to: 1
20/03/2014 20:12:50 409 Action:  Tcp.Client.Connect - tivotcp&&192.168.18.22&&31339&&\x0d
20/03/2014 20:12:50 409 [action] Tcp.Client.Connect:tivotcp&&192.168.18.22&&31339&&\x0d

20/03/2014 20:12:50 409 [plugin] Tcp: New thread created for client: tivotcp
20/03/2014 20:12:50 409 [vcevent] TCP.StartListen.tivotcp

20/03/2014 20:12:50 409 action repeat set to: 1
20/03/2014 20:12:50 409 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:50 409 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:50 409 [plugin] Tcp: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
20/03/2014 20:12:52 138 [vcevent] TCP.ClientError.tivotcp

20/03/2014 20:12:52 138 action repeat set to: 1
20/03/2014 20:12:52 138 Action:  Tcp.Client.Write - tivotcp&&IRCODE STANDBY\x0d&&1000
20/03/2014 20:12:52 138 [action] Tcp.Client.Write:tivotcp&&IRCODE STANDBY\x0d&&1000

20/03/2014 20:12:52 138 Event Error: Thread was being aborted.
20/03/2014 20:12:52 138 [vcevent] TCP.EndListenLoop.tivotcp

20/03/2014 20:12:52 138 [vcevent] TCP.StartListen.tivotcp

20/03/2014 20:12:52 138 [vcevent] TCP.Reconnecting.tivotcp

20/03/2014 20:12:52 138 [plugin] Tcp: TCP.ClientError: System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at vcPlugin.tcpClient.listenToServerLoop()
20/03/2014 20:12:52 138 [vcevent] TCP.ClientError.tivotcp

20/03/2014 20:12:52 138 action repeat set to: 1
20/03/2014 20:12:52 138 Action:  TCP.Client.Disconnect - tivotcp
20/03/2014 20:12:52 138 [action] TCP.Client.Disconnect:tivotcp

20/03/2014 20:12:52 138 [vcevent] TCP.EndListenLoop.tivotcp

20/03/2014 20:12:57 698 shutting down form, saving window state
20/03/2014 20:12:57 698 Minimizing to notification area
20/03/2014 20:13:00 628 focused: Idle
20/03/2014 20:13:00 628 [vcevent] unFocused.VoxCommando

20/03/2014 20:13:00 628 [vcevent] focused.Idle

20/03/2014 20:13:03 613 focused: explorer
20/03/2014 20:13:03 613 [vcevent] unFocused.Idle

20/03/2014 20:13:03 613 [vcevent] focused.explorer

« Last Edit: March 21, 2014, 05:49:09 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
TCP Plugin and Tivo
« Reply #1 on: March 20, 2014, 05:57:00 PM »
Did you try using \x0D\x0A

I can't think why it would make a difference to run it from the editor or in a voice command.  Unless it is actually something like it works only the first time, and not the second time.

You could also try using TCP.Single.Write

Usually we use client if we want to hold the connection open for a longer period of time, rather than opening and closing right away, although technically it should still work...

Also, I'm wondering why you use a delay of a full second.  That seems long to me.  It might be better not to put a delay in the TCP action but to add a VC.Pause between the two actions.

It's hard to troubleshoot this type of thing without have a device.  I usually try lots of different things to eliminate possibilities and find patterns.

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
TCP Plugin and Tivo
« Reply #2 on: March 20, 2014, 08:36:07 PM »
Hi

I don't think its a case of only works once - I called it twice from the editor in the log file and although I didn't show it I went back to the editor after the last failed voice attempt and ran the command again and it worked.

The 1 second delay was trial and error attempt at fixing the issue and you are right doesn't make total sense - it works in the editor even with a 50 ms delay.

I did try SingleWrite first but then it always failed on the second call.

 I'll give \x0D\x0A a go but the documentation says only \x0D

All very odd indeed and very difficult to track down.  All I can say is it has not worked voice controlled and 99% of the time it works in the editor (and no that doesn't make sense to me either) I might try a python script next (did I see mention somewhere that I could code something in c#)

Thanks again for your help.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
TCP Plugin and Tivo
« Reply #3 on: March 20, 2014, 09:13:46 PM »
It's ironpython running in a .net environment so yeah, you can make calls to c# libraries if you are careful but you should also be able to do stuff in pure python, which might be easier.

If I remember correctly this example is settings up a TCP server, not a client, but it may still prove helpful to you.  I would prefer if you were able to get it to work in "pure VC" but if not I'm sure you can find a way to make it work in python.

http://voxcommando.com/forum/index.php?topic=1236.msg10615#msg10615

JasonFox

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 4
    • View Profile
TCP Plugin and Tivo
« Reply #4 on: March 21, 2014, 02:32:38 AM »
See my post here:

http://voxcommando.com/forum/index.php?topic=1459.0

Don't know if it will be helpful to your situation since I don't use the standby command specifically but hopefully it will.  :)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
TCP Plugin and Tivo
« Reply #5 on: March 21, 2014, 09:05:12 AM »
Thanks Jason. So basically the TiVo prefers if you connect and stay connected, which is really how the TCP.client actions were intended to be used. If you get a chance could you please test the standby commands?

BTW using writeln should be equivalent to using write and manually terminating your message with \x0D

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
TCP Plugin and Tivo
« Reply #6 on: March 21, 2014, 04:53:37 PM »
Thanks. I'm going to give this a go - I did originally have it setup to open the channel and stay open. I wonder if it is the terminator in the open which is the issue (can't really see why)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
TCP Plugin and Tivo
« Reply #7 on: March 21, 2014, 05:45:53 PM »
The terminator in the "Tcp.Client.Connect" action (I assume that's what you mean by "open") is used to detect termination of messages coming back from the server (in this case the Tivo).  You could try with or without but I don't think it should make a big difference to sending.  You never know!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin and Tivos
« Reply #8 on: March 21, 2014, 05:55:39 PM »
I'm using the TCP plugin and I've got it working almost all of the time but, and this is the strange bit, only when running the code from the editor. When I try to use Voice it always fails.


Please clarify one thing for me.  Do all your voice activated TCP>>Tivo commands (like "volup", "channelDown" etc.) fail, or is it only a problem with the Double Standby command?

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
Re: TCP Plugin and Tivos
« Reply #9 on: March 21, 2014, 06:05:37 PM »
Hi James - None seem to work

A bit more evidence. I've just tried Jason's scripts. As soon as I say OK Tivo I get continuous TIVO events being fired and the only way to stop them is to shut down VC completely (even a full restart doesn't get rid of them) If I run it in the command editor I don't see this.

I assume Jason isn't seeing this. I've tried with both V1 and V2 builds of VC.

I'm going to try a new install next.

Cheers
Garry


jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin and Tivos
« Reply #10 on: March 21, 2014, 06:23:25 PM »
I don't know what is different about Jason's setup but it sound like you need the terminator in your connect action.

If you are not both using the same version of the TCP plugin I guess it would help me to know which versions each of you have.

I would be happy to share your computer screen (VNC or Teamviewer) at some point to try to make sense of this, but it would have to be earlier in the day.

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
Re: TCP Plugin and Tivos
« Reply #11 on: March 21, 2014, 07:03:06 PM »
Thanks James really appreciate the offer. I feel I'm taking a lot of your time for something which may be specific to my network set up.

Some further evidence. I tried a clean build, having rebooted both Tivo and the PC - same problem. I did the same but added \0xD as the terminator  and I no longer get the multiple events but it now fails on the write with an established connection was aborted by the software on your machine. This is regardless of whether it is on the editor or not.

Out of interest does the fact it is generating continuous events without the terminator mean its constantly receiving data (do you generate an event per character in this case) - that would seem odd.

My plugin is 0.1.8.0

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
Re: TCP Plugin and Tivos
« Reply #12 on: March 21, 2014, 07:47:49 PM »
OK decided to try the python approach as a test.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="tivo py" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1628" name="tivo power toggle" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="On my Virgin Media TV it requires the power button to be pressed twice to turn off. &#xD;&#xA;Whilst not required to press twice to trun on it does no harm and allows me to have a single event to toggle off/on">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>sendtotivo('IRCODE STANDBY')</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>tivo power</phrase>
    <event>tivo_toggle</event>
  </command>
  <command id="296" name="tivo" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>sendtotivo('{1}')</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>tivo</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\tivoremote.xml</payloadFromXML>
  </command>
  <command id="799" name="Set Tivo Response Variable" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Results.SetVar</cmdType>
      <cmdString>TivoResponse&amp;&amp;{1}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>TIVO</event>
  </command>
  <command id="387" name="onload" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.TriggerEvent</cmdType>
      <cmdString>loaded</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <cmdString>Plugins\PY\tivo.py</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>onload</event>
  </command>
</commandGroup>

Where Plugins\PY\tivo.py is
Code: [Select]
#!  /usr/bin/python
#   Title: tivo.py
#   Author: Garry Whittaker
#   Date: 21MAR2014
#   Info: To send remote control commands to the tivo over LAN
#   TODO:

import socket
import base64


#



def sendtotivo(msg):
    dst = '192.168.18.22' # IP to tivo
   
    new = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    new.connect((dst, 31339))
   
    pkt = msg+chr(0x0D)
    new.send(pkt)
    new.close()


This works 100% reliably for all commands !

JasonFox

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 4
    • View Profile
Re: TCP Plugin and Tivos
« Reply #13 on: March 22, 2014, 01:56:35 AM »
Thanks for sharing your python version I definitely want to give it a try.

I only experienced the problem you described above (constant events from tivo to VC) once and it coincided with a failure to disconnect, not sure how/why either happened.

I won't have time in front of VC and Tivo until tomorrow night but I'll share how you're python script works on my set up as soon as I get the chance.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: TCP Plugin and Tivos
« Reply #14 on: March 22, 2014, 12:46:25 PM »
OK decided to try the python approach as a test.

Nice. Looks amazingly simple.

I'm curious about the base64 module you're importing for your code. Can you explain where it's being used? I have been racking my brain trying to figure this out.

Thanks!
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)