Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kiranthepro.epizy.com.raspberrypirobotcontroller;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import com.jcraft.jsch.JSch;
- import com.jcraft.jsch.Channel;
- import com.jcraft.jsch.ChannelExec;
- import com.jcraft.jsch.JSchException;
- import com.jcraft.jsch.Session;
- public class RobotController extends AppCompatActivity {
- private WebView streamWebView;
- String host;
- String user;
- String password;
- public static Session session;
- public static ChannelExec channel;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_robot_controller);
- host=getIntent().getExtras().getString("com.kiranthepro.epizy.com.raspberrypirobotcontroller.HOSTNAME");
- user=getIntent().getExtras().getString("com.kiranthepro.epizy.com.raspberrypirobotcontroller.USERNAME");
- password=getIntent().getExtras().getString("com.kiranthepro.epizy.com.raspberrypirobotcontroller.PASSWORD");
- initStreamConnection();
- new makeSSHConnection().execute();
- }
- private class makeSSHConnection extends AsyncTask<Void, Void, Void> {
- @Override
- protected Void doInBackground(Void... voids) {
- try {
- initSSHConnection();
- System.out.println("IT WORKED!");
- } catch (Exception e) {
- System.out.println(e);
- }
- return null;
- }
- }
- public void initStreamConnection() {
- streamWebView = (WebView)findViewById(R.id.PiLiveStream);
- streamWebView.setWebViewClient(new WebViewClient());
- streamWebView.loadUrl(host);
- streamWebView.getSettings().setBuiltInZoomControls(true);
- streamWebView.getSettings().setDisplayZoomControls(false);
- }
- public void initSSHConnection() throws JSchException {
- JSch jsch = new JSch();
- Session session = jsch.getSession(user, host, 22);
- session.setPassword(password);
- session.setTimeout(10000);
- java.util.Properties config = new java.util.Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- session.connect();
- channel = (ChannelExec)session.openChannel("exec");
- channel.setCommand("python3 PythonFiles/robot_controller_scripts/moveRobotSetupPins.py");
- System.out.println("Successfully set up pins!");
- System.out.println(host + "\n" + user + "\n" + password);
- }
- public void sendFwdCmd() {
- channel.sendCommand("python3 PythonFiles/robot_controller_scripts/moveRobotScriptSSH.py F");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement