Java 连接Arduino Y和xFA;n与Processing-JSCH
我最近买了Arduino Yuún,我正试图使用模拟管脚的数据进行处理,并通过OSC广播到其他应用程序 我正在使用来自Proccesing论坛的代码(我没有收到答案),但我不知道如何在我的处理代码中使用此代码Java 连接Arduino Y和xFA;n与Processing-JSCH,java,ssh,arduino,processing,arduino-yun,Java,Ssh,Arduino,Processing,Arduino Yun,我最近买了Arduino Yuún,我正试图使用模拟管脚的数据进行处理,并通过OSC广播到其他应用程序 我正在使用来自Proccesing论坛的代码(我没有收到答案),但我不知道如何在我的处理代码中使用此代码 // jsch is an open source SSH client for Java. // get it from <a href="http://www.jcraft.com/jsch/" target="_blank" rel="nofollow">
// jsch is an open source SSH client for Java.
// get it from <a href="http://www.jcraft.com/jsch/" target="_blank" rel="nofollow">http://www.jcraft.com/jsch/</a>
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.*;
String user = "root";
String password = "<ARDUINO PASSWORD>";
String host = "arduino.local";
int port=22;
try
{
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no"); // less than maximally secure
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
Channel channel = session.openChannel("exec");
// this stream will be used to send data to the Yun
DataOutputStream dataOut = new DataOutputStream(channel.getOutputStream());
channel.setInputStream(null);
// this jsch member class provides remote execution of a shell command
((ChannelExec) channel).setCommand("telnet localhost 6571");
// see <a href="http://arduino.cc/en/Guide/ArduinoYun#toc17" target="_blank" rel="nofollow">http://arduino.cc/en/Guide/ArduinoYun#toc17</a> for why this command
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
// after configuring all channel parameters, we connect, causing the
// command to be executed. Results and further input will be handled
// by the streams
channel.connect();
byte[] tmp=new byte[1024];
// poll input stream forever
while (true) {
while (in.available ()>0) {
int i=in.read(tmp, 0, 1024);
if (i<0)break;
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
System.out.println("exit-status: "+channel.getExitStatus());
break;
}
try {
// if used with the Console example code, this will blink the LED
// in time with polling events
dataOut.writeBytes("L\n");
dataOut.flush();
Thread.sleep(1000);
dataOut.writeBytes("H\n");
dataOut.flush();
}
catch(Exception ee) {
System.err.print(ee);
}
}
System.out.println("disconnecting...\n");
channel.disconnect();
session.disconnect();
System.out.println("Finished.\n");
}
catch(Exception e) {
System.err.print(e);
}
//jsch是一个面向Java的开源SSH客户端。
//从
导入com.jcraft.jsch.ChannelSftp;
导入com.jcraft.jsch.jsch;
导入com.jcraft.jsch.Session;
导入java.io.*;
字符串user=“root”;
String password=“有关此命令的原因
((ChannelExec)channel.setErrStream(System.err);
InputStream in=channel.getInputStream();
//配置所有通道参数后,我们连接,导致
//要执行的命令。将处理结果和进一步的输入
//溪边
channel.connect();
字节[]tmp=新字节[1024];
//永远轮询输入流
while(true){
while(in.available()>0){
inti=in.read(tmp,0,1024);
如果(i)