I have the Pepper robot running NAOqi 2.9, which is the version using QiSDK to create Android applications for its tablet.
I currently have to get Pepper's head's IP in my Android app, which can be easily made as a manual input, but I'm wondering if there's a way to do this programatically, since the tablet knows the head's IP, always displaying it in the notification bar, alongside the tablet's IP.
On step 5 on Connecting to a real robot they say you can do this manually.
How to find the IP address?
On the tablet of the robot, display the notifications (swipe down from the top of the screen) and look for the following logo:
But that's just the Getting Started page. I've also looked into the Javadocs of the qisdk api but didn't find anything related to the head's IP.
I was wondering if someone knows a way I could do this, not necessarily using QiSDK, since it doesn't seem to support this.
This isn't the most straightforward solution, but you can access the head computer from the tablet through SSH, since the head is connected to the tablet by USB and has a static IP address of 192.168.100.80
. Then you can get the IP address of the head using ifconfig
.
To do this in Java, I used JSch, but any java SSH implementation should be fine.
Download jsch-0.1.55.jar from here. Create a new folder libs
in your app directory and save the jar in there. Then add the following to your build.gradle under dependencies:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
Thanks to this answer, you can do some processing on the ifconfig
output to get the IP address of Pepper's head on the wifi network.
Note: I'm not able to test this on a physical Pepper at the moment, so please check this first by SSHing into Pepper and running the command. Mainly check that wlan0
is the right name for the network device.
ifconfig wlan0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.InputStream;
// Create SSH session
jsch = new JSch();
session = jsch.getSession("nao", "192.168.100.80", 22);
session.setPassword("nao");
// Avoid asking for key confirmation
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
String command = "ifconfig wlan0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1";
session.connect();
ChannelExec channelssh = (ChannelExec)session.openChannel("exec");
channelssh.setCommand(command);
InputStream stdout = channelssh.getInputStream();
// Execute command
channelssh.connect();
// Get output
StringBuilder output = new StringBuilder();
int bytesRead = input.read();
while (bytesRead != -1) {
output.append((char) bytesRead);
bytesRead = input.read();
}
// close SSH channel
channelssh.disconnect();
// Here's the IP address of the head, formatted as a string
String headIP = output.toString();