This page last changed on Jan 17, 2011 by deanox.

I'm trying to get OR (on an Android Archos101) to talk to Homeseer. I have a generic TCP/IP plugin for homeseer that responds to simple text commands fine from a telnet client - e.g. "execx10,a1,off" and also offers very good low level debugging output so I can see what is being received.

If I implement a Telnet command in OR - I can't structure the command properly. There is no text sent from the server when the socket is opened, so nothing to wait for. So setting the command to "execx10,a1,off" results in openremote timing out waiting for "execx10,a1,off". If I use " |execx10,a1,off" it times out waiting for " " and if I used "|execx10,a1,off" OR doesn't give the time out error, but I dont see the command being received, just the socket opens and closes as if it had timed out.

So for a telnet command is there a format for "dont wait for a string from the far end" ?

If I implement a TCP/IP command - its received fine, but the homeseer plugin is expecting (CR)(LF) and OR appears to only send (CR) so deosnt action the received command.

Is there a way of getting OR to send (CR)(LF) ? (Can I insert control characters into the command string?)

And is there a similar UDP socket protocol available ? I have an IP to IR box that uses a simple UDP command. Openremote would be perfect to drive it if a basic UDP (IP,Port,Command) protocol were available. Although I've used Vbasic in the past and some general scripting I haven't got my head around how I could add that myself to Openremote yet.

URL for UDP based IP to IR box : http://www.keene.co.uk/electronics/multi.php?mycode=KIRA

Thanks for any assitance. With the UDP protocol for IR and TCP/IP to Homeseer I could control everything very nicely

Hi Dean,

I've run into something similar with my TiVo Series 3 so I'll try to shed a little more light on this problem.  I am running OR from a version I have recently downloaded from Subversion and compiled using the Eclipse IDE.  In the class TelnetCommand.java there is a method called send().  In that class exists the condition statement if(count%2==0){ waitForString(cmd, tc); ...  When execution reaches this line it stops waiting for a response from the client which will never come.  After one second waitForString() times out.

When I comment out the condition statement, telnet when used with the TiVo series 3, works fine.

-Doug

Posted by drick at Jan 17, 2011 21:57

Doug - thanks, I may have to spend a couple of evenings trying to getmy head round subversion and eclipse. - Do I just have to build the controller to start tweaking the telnet implementation ?

I have thrown a Visual Basic converison layer together (sorry VB is about all I can do really at the moment) that accepts a socket connection from the controller and initiates one out to Homeseer (in my case) and echos data between. If I convert CR to CRLF on the way through I can get simple commands to work. Haven't tried interaction with sensors yet - but the same principle should mean I can convert any response to the simple "on/off" or "0-100" that I think OR is looking for.

Bouyed with that success I then adapted it to accept a TCP connection from OR and initiate a UDP connection to my IR device aswell. Managed to also add a pronto hex conversion to the format required for my IR box on the way through. Strangely the Wife wasn't quite so impressed with a button press on my Android tablet changing the Sky digital (Satellite) channel as I was

So I now have proof of concept to get OR controlling HomeSeer and IR for me and confirmed I need...

Option for TCP Socket (or Telnet) to use CRLF instead of CR

Option for UDP protocol with parameters for IP, Port, Command (also with CRLF)...This would be enough if I manually convert all my IR codes. Clearly if I want to use a generic Pronto (or other) IR format I would need a dedicated protocol with that conversion built in.

Anyone recommend a good starter Java book !?

Posted by deanox at Jan 22, 2011 23:50

Hi

I see from your posts that you apear to be having the same problem I had some time ago when trying to send Telnet commands. I could send the first one OK and then the controler locked up (see my post

Sending Telnet or TCP IP commands)

I believed it was down to CR/LF command not being sent from OR as I tested it with Putty and all worked OK.

Would it be possable to have this as user configured in OR so that it would send either a CR or LF and also whether it should receive a response. This would be most helpfull.

Posted by pjmm at Jan 23, 2011 13:38

Pierce - I actually had the same issue with my temporary VB App. OR wants to create a new TCP connection for each button press with a Telnet command. Some clients (like my very rushed vb app) couldn't cope with the previous TCP session closing, so wouldnt cleanly open the new session for the next button press from the same host. Meaning I had exactly the same sympton for a while - 1st one worked, subsequent one wouldn't. because it was only a temporary app I simply forced the socket closed after each code is received and it was fine. So whilst the CR/LF might fix it ... it might not.

I may well go back and look at whats happening with wireshark to see which end isnt closing the socket cleanly.

Posted by deanox at Jan 23, 2011 19:08

Hi Dean

the aplication I am tyying to controll is called "mce controller" it has a client and server which can be used as a controffer as well as starting programs on a pc. The server excepts Telnet commands

I have tried the lates version of OR  and it now appears that it does not even send the first command.

Any help you can give would be much appriciated

Posted by pjmm at Jan 23, 2011 20:18

Hi Dean,

I was using Telnet up to now and it does not send any command now. I tried using TCPIP

and it works for the once. If I re start the OP server I can then send one more command

would it be waiting for a string back like the problem you had before.

Posted by pjmm at Jan 24, 2011 18:50

Pierce - I just had a quick test with MCEController and wireshark and it appears that the MCE controller end is entirely silent. It doesn't send an acknowldegement either on initial connect or after a successfull command.

So with OR set to "telnet", OR times out waiting for an initial response before sending the command.

and with OR set to "TCP/IP", OR connects and sends the command but then times out waiting for the far end to acknowledge which it never does and the connection isn't cleanly closed by either side.

So yes you're not tripping over the CRLF/CR issue...but the fact that OR expects a response on both Telnet and TCP/IP commands.

Posted by deanox at Jan 24, 2011 21:30

Hi Dean

many thanks for the reply does that mean that if you comment out the condition statement

will it work then.

Would there be a way to have this selectible ie to expect a responce or not to expect a

responce

Posted by pjmm at Jan 24, 2011 21:50

I think I'm now in a position to outline what I would need from a slightly more detailed "IP" command including some of the issues with the current Telnet & TCP/IP options.

Unfortunately I've never written a line of Java before so I'm not really in a good place to suggest in detail what changes are required to the current code. Even if I could convert what I know into java I dont really understand how I'd go about creating both a customised version of the controller - and a customised local copy of the designer which would need to be able to add the required parameters for a new or modified protocol. I suspect thats not an easy skills/knowledge gap to jump so I think we'd need a more experienced OR programmer to jump in at this point.

Posted by deanox at Jan 25, 2011 20:14

Hi Dean

many thanks for all the help at least you have established why we are able to only send one command using TCPIP and no command while using Telnet.

Juha is hoping to do a  patch for telnet  soon. Hopfully that might help.

Posted by pjmm at Jan 25, 2011 22:08

I lookup the statement you described and i found the follwowing

    public void send() {
      TelnetClient tc = null;
      try {
         tc = new TelnetClient();
         tc.connect(getIp(), Integer.parseInt(getPort()));
         StringTokenizer st = new StringTokenizer(getCommand(), "|");
         int count = 0;
         while (st.hasMoreElements()) {
            String cmd = (String) st.nextElement();
            if (count % 2 == 0) {
               waitForString(cmd, tc);
            } else {
               sendString(cmd, tc);
            }
            count++;
         }
      } catch (Exception e) {
         logger.error("could not perform telnetEvent", e);
      } finally {
         if (tc != null) {
            try {
               tc.disconnect();
            } catch (IOException e) {
               logger.error("could not disconnect from telnet", e);
            }
         }
      }
   }

Could you explain which part you removed? I tried removing the if

 if (count % 2 == 0) {
               waitForString(cmd, tc);
            } else {
               sendString(cmd, tc);
            }

But without any luck. I'm not wel known to java so i'm taking my 1st steps here.

Posted by kide at Jan 30, 2011 15:08

In the 'if' block you removed, you want to remove everything EXCEPT the line sendString(cmd, tc);

The problem seems to be that the code is waiting for the response 'CRLF' at the line waitForString(cmd, tc).  That response is never comming so the telnet session just times out.  If you remove the 'if' block leaving just the sendString(cmd, tc); the controller will send the command to your device.

Posted by drick at Jan 30, 2011 16:05

Hi,thanks for sharing the information regarding to generic tcp ip and telnet.Really a good information is provided by you.Actually i'm new in programming area so i feel some hasitation in sharing this information.Thanks a lot again for sharing the information here.

 [url=http://www.3magicbeans.com]Website Development Denver[/url]
 [url=http://www.3magicbeans.com]Denver Web Designs[/url]

Posted by 3magic at Jan 31, 2011 05:51

It works like a charm

[Controller]2011-01-31 07:36:14,701 INFO [HTTP-Thread-6] org.openremote.controller.protocol.telnet.TelnetCommand.sendString(203) | send: set Stalamp_KL on
Posted by kide at Jan 31, 2011 06:37

Ernst - could you share how you ran from modified source ?

I'd love to start experimenting with a few minor changes in places and maybe a UDP option for my IR. I've downloaded the source form SVN and can see the relevant protocol sections etc but have no idea how to turn that into a controller version I could run.

Posted by deanox at Jan 31, 2011 09:02

Well there are multiple ways but here's what i did since i was wresteling with the documentation for a while

Build teh developer release via this document [Building OpenRemote 2.0 Developer Releases|display/docs/Building+OpenRemote+2.0+Developer+Releases]

This will give you the latest version of the controller (Alpha 11)

Before you build it modify the file "TelnetCommand.java" with eclipse and change:

This:

            String cmd = (String) st.nextElement();
            if (count % 2 == 0) {
               waitForString(cmd, tc);
            } else {
               sendString(cmd, tc);
            }

into this:

            String cmd = (String) st.nextElement();
            if (count % 2 == 0) {
/**               waitForString(cmd, tc);
            } else {
*/
               sendString(cmd, tc);
            }

Now build the controller, download the panel and be amazed

Posted by kide at Jan 31, 2011 09:18

Hi Ernst,

can you confirm if Telnet should wait for the response 'CRLF' or should it not?.

If it should not should this fix not be a permanent fix?

Posted by pjmm at Jan 31, 2011 23:03

i cant confirm nor deny this. This would be something to mail to the designers for them to take a look at.

Posted by kide at Feb 01, 2011 06:27

@All: please look at the following topic for more information/solution

Telnet status read implemented

Posted by kide at Feb 10, 2011 13:14

Hi Ernst

I have looked at this post and have the following questions

Is this fix available now or in the future.

Pierce

Posted by pjmm at Feb 11, 2011 13:45

Hi Pierce,

The fix is available now!. You can sync the specific svn tree with

svn co http://openremote.svn.sourceforge.net/svnroot/openremote/branches/feature/Controller_2_0_0_Alpha11_telnet

Do you know how to build a Developers release?

Posted by kide at Feb 11, 2011 15:02

Hi that great news. I have not built a Development release but if you point me in the right direction

ill give it a bash

Posted by pjmm at Feb 11, 2011 15:21

Follow this link Building OpenRemote 2.0 Developer Releases

Sync the the Openremote Boss alpha 8 branch with:

   svn co http://openremote.svn.sourceforge.net/svnroot/openremote/tags/OpenRemote_Boss_2_0_0_Alpha8

Now you have the base Dev relaease including all the tools you need together with the Alpha11 release of the controller.

Enter the Directory "OpenRemote_Boss_2_0_0_Alpha8" and sync the modified telnet target with:

 svn co http://openremote.svn.sourceforge.net/svnroot/openremote/branches/feature/Controller_2_0_0_Alpha11_telnet

Now follow the rest of the document (with correct paths) and your good to go

Have fun

Posted by kide at Feb 11, 2011 15:35

Hi Ernst

I tried what you sugesrted usinghttp://openremote.svn.sourceforge.net/svnroot/openremote/branches/feature/Controller_2_0_0_Alpha11_telnet
but I still got the same results as I got before when trying to send a telnet command.

I then edited the file as per your post

String cmd = (String) st.nextElement();
if (count % 2 == 0)

Unknown macro: { /** waitForString(cmd, tc); }
else
Unknown macro: { */ sendString(cmd, tc)}

this worked allowing me to send telnet commands. After each command it disconnected and reconnected but I am still able to send multible commands. Can you tell me what were the updates which were made to the file and should it have worked for me

Posted by pjmm at Feb 12, 2011 18:57

Hi Pierce,

I hope you didnt edit the file "TelnetCommand.java" because this hack is not needed anymore.

All the neccecary changes are made to the code that it should work out of te box.

Could you explain in detail what you are trying to do?

Posted by kide at Feb 13, 2011 07:50

Hi Ernst

I am trying to use an aplication by the name of MCEController to controll a PC.

This aplication can receive commands by Telnet and comes as a client and server.

I can sucessfully controll it using Putty and was previously able to only send one command from

Open Remote before it locked up.

I downloaded and installed your new Telnet file but this did not work.

I then modified the old TelnetCommand.jave and this worked. I am able to send

several commands and controll the PC. It does appear to terminate the session each time but it re connects after each command.

You can If you have time download MCEController and see can you replicate the problem.

Many thanks for your help

Posted by pjmm at Feb 13, 2011 11:55

Pierce - Whats the format of your telnet command ?

It should be "null|key=1" for example with the new version of the Telnet command.

Posted by deanox at Feb 13, 2011 14:13

Ok i see where your going wrong here.

I assume you downloaded the SVN tree + the new telnet branch as i described. right? and DO NOT modify anything. Skip the hack i mentioned before!

In the "commands" section in composer you need to do the following

instead of using the normal command  you need to place a "null |" before it so it will skip the control prompt check.

e.g. in my case it was:

set Stalamp_KL off

my command now:

null | set Stalamp off

Now sync it, run it and be amazed

Posted by kide at Feb 13, 2011 14:39

Hi Ernst

so I fully understand when I would normally send "vol+" I should now send "|vol+" is that correct?

Can you tell me what happens when you insert the"|" before the command?

Posted by pjmm at Feb 13, 2011 21:34

Hi PIerce,

Nope.... instead of "vol +" you send literally "null | vol +"

the pipe "|" does exactly what it is it pipes a sequence. As i did you needed a control prompt sop what we did in this topic we eliminated the checking of that prompt. In the new code there is a new feature which is able to compensate for the checking of that control prompt.

if you put "null |" before you actual command it tells the code to "forget the control prompt check and directly execute the command" 

For a full explination about that the "|" can do more please read Telnet Status Read Implemented

Posted by kide at Feb 14, 2011 07:07

Hi Ernst

I tried that out but unfortunatly it dident work this is the entry from the controler log

maby you can see what is going wrong

[Controller]2011-02-17 19:13:19,358 INFO [HTTP-Thread-1] org.openremote.controller.protocol.telnet.TelnetCommand.waitForString(310) | WaitForString read before running into timeout:
[Controller]2011-02-17 19:13:19,374 ERROR [HTTP-Thread-1] org.openremote.controller.protocol.telnet.TelnetCommand.send(281) | could not perform telnetEvent
java.lang.Exception: waitForString response timed-out waiting for "null "
    at org.openremote.controller.protocol.telnet.TelnetCommand.waitForString(TelnetCommand.java:311)
    at org.openremote.controller.protocol.telnet.TelnetCommand.send(TelnetCommand.java:270)
    at org.openremote.controller.protocol.telnet.TelnetCommand.send(TelnetCommand.java:251)
    at org.openremote.controller.service.impl.ControlCommandServiceImpl.trigger(ControlCommandServiceImpl.java:56)
    at org.openremote.controller.rest.ControlCommandRESTServlet.doPost(ControlCommandRESTServlet.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:354)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

Posted by pjmm at Feb 17, 2011 19:36

Hi Ernst

I figured it out I entered "null | vol+" is should be "null|vol+" no space before and after "|"

It now appears to work OK

Posted by pjmm at Feb 17, 2011 20:39

I need to send a Telnet command string and it must be in total 16 bytes long OpenRemote adds

CRLF and then the string is 18 bytes long.

Is it possable to disable sending the CRLF

Posted by pjmm at Feb 22, 2011 18:23

Hi Pierce,

Sorry i totally missed you message here.

Yes sure you can do it. Do the following null|<your first command>|<your second command>

the "|" will send a CRLF as i understood correctly.

Please be so kind and take a look at Telnet Howto docs

This is a first draft and feel free to comment on it.

Posted by kide at Feb 28, 2011 17:46

Hi Ernst

I want to send

HCA0002010002058 without any CFLF (or CR) which makes it18 bytes long

It must be this string and only 16 Bytes long in total

How do I do this

Posted by pjmm at Feb 28, 2011 21:14

Ok lets cut it down into pieces because obviously i missed the bus here.

What are you trying to do?

If you telnet to your target:

- What is the responds you get on the screen (direct after login)

- What do you type as a command

- And what (should) happen

Posted by kide at Mar 01, 2011 08:06

I need to send "HCA0002010002058" this string only with no cr/lf at the end

It must only be a total of 16 bytes otherwise the program I am trying to talk to will

not responde.

Is it possable just to send HCA0002010002058 without cr/lf

Posted by pjmm at Mar 01, 2011 20:37

I need to send "HCA0002010002058" this string only with no cr/lf at the end

It must only be a total of 16 bytes otherwise the program I am trying to talk to will

not responde.

Is it possable just to send HCA0002010002058 without cr/lf

Posted by pjmm at Mar 01, 2011 20:37

Ok i'm still not sure if i get you.

In simple term: Do You want to send a command without hitting enter?

Posted by kide at Mar 02, 2011 07:27

Yes if the line is terminated with a cr or crlf it will not be exactly 16 bytes

and the program at the other end will not responde

Posted by pjmm at Mar 03, 2011 22:52

Sorry i dont know the awnser to your question. Can you make a new topic of it?

Posted by kide at Mar 05, 2011 09:19

Could I ask what syntax you were using for sending telnet commands to your TiVo? I have a Series 3 also, and I can successfully send telnet commands via my laptop. For example, I can send the command 'IRCODE GUIDE', and the episode guide will come up. Doing so again will remove the episode guide. However, I cannot figure out the syntax for the command box in the Online Designer. I've tried some of the following:
>'IRCODE GUIDE'
>'|IRCODE GUIDE|'
>'null|IRCODE GUIDE|null'

What command text did you use?

Thanks!

Posted by jammastercd at Aug 20, 2011 03:11
Document generated by Confluence on Jun 05, 2016 09:30