Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Android client SSH extension for MIT Application Inventor 2

andriod-ssh.jpg
The following attached file contains an SSH Client extension
which I made for my own use, but it may also be useful for users of the MIT Application Inventor 2 (AI2) community, or even to the AppyBuilder community (code intrinsically compatible for the last one, but not tested). This is just the current stage of development, but if you want to get updated revisions, you can get the last released source code at Github.

Component.png



It is being shared "as-is", which means that:

  • No implicit or expressed warranty provided - (leastwise worked for me),
  • No functional optimization performed, no refactoring made,
  • Not intended to be an "state-of-the-art" work, but rather a quick solution to a big problem,
  • Not tested in all devices, OS builds, etc... (tested on Android 4.2 and 8.1, both Samsung mobiles)
  • Attempted to follow good coding/style formatting practices, but not strictly committed to this.
This is an extension that sends simple SSH commands, and captures the returned "string" sentence. All commands execution have to be as quick as possible, once the AsynchUtil.runAsynchronously class is being used to instantiate the thread which embed the whole SSH execution (send/receive), and it is well known that this thread locks UI execution, turning the application unresponsive to the user.

Screen.png



In the attached demo application, the text field displays only the last line, and for this reason, if you want to see the whole sentence got from host, you can make simple changes in the code in order to merge incoming messages subsequently.

TestApp.png



It is worthy to mention that due to the oftentimes changes in the security policies of the protocols, it would not be improbable that the attached .aix file would not work in the future, therefore this extension should be re-compiled (with the Apache ANT builder), but now adding a more recent release of JSch at the LIB folder (current revision: jsch-0.1.54.jar).

Another point to remark is that, althought including the source code of the JSch library in the project, the correspondent compield JAR was necessary just to embed it into the application during build stage, without the need to give external dependencies to the user.

USAGE:
=====

1 ) Fill string variables "SetUser", "SetHost" and "SetPasswords" accordingly, without queotes​
2 ) Fill string variable "Command" with the Bash/Shell command to be issued, without queotes (e.g: ls )​
3 ) Call the function "SendData"​
4 ) Get result either:​
4.1 ) ...from within "NewIncomingMessage" event, argument "data" contains current text line, indded the last one.​
4.1 ) ...by reading "GetReceivedMessage" variable; be aware that it is assyncronously updated (intermediary values are superseded)​

Feel free to make experiments and give feedback.

LINKS AND TIPS

Development environment:
Source code dependencies:

Binary project dependencies:
  • JSCH : https://sourceforge.net/projects/jsch/files/jsch.jar/0.1.54/ (note, it is the above source code compiled)
    • At Environment Variables, add to CLASSPATH:
      <main folder>\appinventor\components\runtime\jcraft\jsch\jgss
    • At \appinventor\components\ locate the file Build.xml and seek for the comment header CopyComponentLibraries and add the following sentence:
      <copy toFile="${public.deps.dir}/jsch-0.1.54.jar" file="${lib.dir}/jsch/jsch-0.1.54.jar" />
    [*][*][*][*][*]
Required/Preferred tools:
How to create Extensions:

Comments

I was requested to provide a way to change the PORT as a regulear argument, such as made with the HOST parameter, but I have no longer the whole environment setup deployed in my computer, which as can be seen in the above list, it's a quite laborious task. BTW, the SSH port there is set hardcoded as 22, the default one.

jadx.png


However, I just realized that the extension .aix file can be decompressed, just by changing its extension to ZIP; and further, inside, we can open the 'classes.dex' file with the JADX tool. So, do someone know if it is possible to just make the change ( e.g, change port from 22 to e,g 8008 ) and re-compress the file again, with no need to compile the whole extension? I though this as a work-around option for those who want to quicly solve the specific issue of making use of a particular Port.
 

Part and Inventory Search

Blog entry information

Author
andre_luis
Read time
2 min read
Views
15,559
Comments
1
Last update

Downloads

  • Client_SSH_AI2_Ext.rar
    3.5 MB · Views: 14,165

More entries in Uncategorized

More entries from andre_luis

Share this entry

Back
Top