Re: Telnet/socket connecton

944 views
Skip to first unread message

TomL

unread,
May 21, 2013, 9:40:19 AM5/21/13
to tas...@googlegroups.com
(I would kill to have "expect" working on Android shell.  That would be awesome.)

Since you have the java source code for Communicator.java and Homeautomation.java, you can modify them yourself and compile your personal version of the app.  In your version, you can hard code the name of the remote server, user and password.  Now you won't have to login everytime you run your custom app.

Tom



On Sunday, May 19, 2013 2:23:46 AM UTC-4, Daniel Söderlund wrote:
Hello 

I have this bashscript 

remote_server="server port"
my_user_id="user"
my_password="password1"

turn() {
   my_command="ts turn $1 $2"
   expect << EOF
      # Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier
      # in the script.
      # Open a telnet session to a remote server, and wait for a username prompt.
      spawn telnet $remote_server
      expect ">> "
      # Send the username, and then wait for a password prompt.
      send "user $my_user_id\r"
      expect ">> "
      # Send the password, and then wait for a shell prompt.
      send "pass $my_password\r"
      expect ">> "
      # Send the prebuilt command, and then wait for another shell prompt.
      send "$my_command\r"
      # Exit the telnet session, and wait for a special end-of-file character.
      send "quit\r"
      expect
EOF

}

turn tv on 

exit 

I like to do the same with tasker ( non rooted device ) and make a shortcut to the desktop 

There is a app for this but it's not perfect as you have login every time and there is no widget or why to create a shortcut 

Daniel Söderlund

unread,
May 21, 2013, 9:45:39 AM5/21/13
to tas...@googlegroups.com
Expect is used due to it was a easy way to do it in linux. I don't
need it on my phone it was just the general idea

Well my java skills isn't the greatest almost Null. :(
So I thought maybe do it with scripts in tasker.




2013/5/21 TomL <toml...@gmail.com>:
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Tasker" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/tasker/GviqjQhAwps/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to
> tasker+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

TomL

unread,
May 21, 2013, 9:55:48 AM5/21/13
to tas...@googlegroups.com
The tough part is that Tasker doesn't offer any easy way to script the send/wait/send things you need to do over the telnet connection to your remote host.


I think you need to look at his source code, modifyit so that it can send TCP packets instead of UDP packets, and then you'll be 90% of the way to doing what you need.

Tom

TomL

unread,
May 21, 2013, 10:08:23 AM5/21/13
to tas...@googlegroups.com
It's a pity your phone isn't rooted.  If it was rooted, you can use Tasker to run shell commands that can simulate key inputs.  So, you can have Tasker do something like:

launch terminal app
runshell: 
sendevent /dev/input/event4 u
sendevent /dev/input/event4 s
sendevent /dev/input/event4 e
sendevent /dev/input/event4 r
sendevent /dev/input/event4 [return]
sendevent /dev/input/event4 p
sendevent /dev/input/event4 a
sendevent /dev/input/event4 s
sendevent /dev/input/event4 s
sendevent /dev/input/event4 w
sendevent /dev/input/event4 o
sendevent /dev/input/event4 r
sendevent /dev/input/event4 d
sendevent /dev/input/event4 [return]
etc etc.

Tom

David Stone

unread,
Apr 9, 2014, 1:02:16 AM4/9/14
to tas...@googlegroups.com
A bit late, but I've just published a plugin that should be able to handle this for you:


You can try a 7-day trial copy at:



 

Daniel Söderlund

unread,
Apr 9, 2014, 3:14:49 AM4/9/14
to tas...@googlegroups.com
Hello, looks good. 
I rooted my phone few weeks ago but it's better to have a GUI :) 
I'll download the trial and see how it works. If t works well I'll buy it( maybe buy it anyway just for the support), if you need a beta tester just shout.  


BR
Daniel 


Kind Regards/Mvh
Daniel Söderlund
+46 (0) 703 576 509


--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.

To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Daniel Söderlund

unread,
Apr 9, 2014, 7:27:43 AM4/9/14
to tas...@googlegroups.com
Hi again, 


I'm trying to replicate my script in the plugin, not sure what I should do.
When I create the first expect  it doesn't show up in the list, maybe a bug don't know. 

BR
Daniel


Kind Regards/Mvh
Daniel Söderlund
+46 (0) 703 576 509


David Stone

unread,
Apr 9, 2014, 11:28:05 AM4/9/14
to tas...@googlegroups.com
On Wednesday, April 9, 2014 4:27:43 AM UTC-7, Daniel Söderlund wrote:
Hi again, 


I'm trying to replicate my script in the plugin, not sure what I should do.
When I create the first expect  it doesn't show up in the list, maybe a bug don't know. 

BR
Daniel 

Sorry, I am seeing the same thing here.  Something in updating all of my build tools and doing a production build must have broken it.  And although all my automated tests passed, they are clearly not sufficient.  I will post an update as soon as I work it out.

Thanks,

David

David Stone

unread,
Apr 9, 2014, 11:09:59 PM4/9/14
to tas...@googlegroups.com
Sorry, and embarrassed about that.   It turned out to be a bug that only shows up once after the initial installation, and was invisible to my plethora of unit tests.  Need to work out how to best do this type of system testing, but uiautomator is such a long way around.  Anyways, I fixed the bug, updated the Google Play store binary and also updated the trial version.

David


Jörg Kobelt

unread,
Jun 10, 2014, 2:23:48 AM6/10/14
to tas...@googlegroups.com
Hi David,
I bought your App and now I tried to do some Telnet ...
I only want to send a string to a telnet host, the host didn´t need a Login (it is only local)
 
In the Target I put the IP of the local telnet server.
Port: 4224
timeout: 5
 
Send KOBELKA.event.mobil=test
 
Nothing reaches the host, what did I wrong ?

David Stone

unread,
Jun 10, 2014, 9:05:39 AM6/10/14
to tas...@googlegroups.com
On Monday, June 9, 2014 11:23:48 PM UTC-7, Jörg Kobelt wrote:
Hi David,
I bought your App and now I tried to do some Telnet ...
I only want to send a string to a telnet host, the host didn´t need a Login (it is only local)
 
In the Target I put the IP of the local telnet server.
Port: 4224
timeout: 5
 
Send KOBELKA.event.mobil=test
 
Nothing reaches the host, what did I wrong ?

Hello Jörg,

The first thing to do is to enable Send/Expect logging.  This is done by launching Send/Expect as a standalone application, opening the options menu, selecting Preferences, and then enabling the Logging box.

Next run your Send/Expect configuration, triggering it either from Tasker, or perhaps easier when debugging, directly from standalone Send/Expect.

After it has run, in standalone Send/Expect open the options menu and select Log.   This will show you what Send/Expect did.

If the log shows the Send/Expect was successful, the problem may be that the connection is being closed before the Telnet server has had a chance to process the command. If this is the case you can add a pause in your Send/Expect configuration after the send.

David

P.S.  Because this is a Send/Expect question let's continue this conversation in the Send/Expect forum.

Reply all
Reply to author
Forward
0 new messages