通过 USB 连接的 Android 设备控制 Raspberry Pi
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22127865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Control Raspberry Pi via USB connected Android device
提问by Vitali V.
I have a Raspberry Pi with running custom server not connected to the internet (offline system).
我有一个运行自定义服务器的 Raspberry Pi,未连接到互联网(离线系统)。
I would like to connect Android device via USB cable to rPi and communicate with it.
我想通过 USB 电缆将 Android 设备连接到 rPi 并与之通信。
As Raspberry Pi is not connected to the internet, it doesn't have IP address (given via DHCP).
由于 Raspberry Pi 未连接到互联网,因此它没有 IP 地址(通过 DHCP 提供)。
How can I communicate with rPi using Android device connected via USB?
如何使用通过 USB 连接的 Android 设备与 rPi 通信?
Maybe local DHCP server?
也许本地DHCP服务器?
Thanks
谢谢
采纳答案by AL??I
Follow thislink. You just have to configure the RPi for it once and you are good to go.
按照这个链接。你只需要为它配置一次 RPi 就可以了。
What this does:
Allows you to use your Android device as keyboard input and terminal display for your Raspberry Pi
Allows you to tether your Raspberry PI to your Android device's WiFi (3G untested, but should work).
Background:
I love the idea of a truly portable Raspberry Pi box. I wanted to make one, but I don't have a compatible WiFi dongle, nor do I have a wireless keyboard and mouse. Even if I did all of these things, I'd like to save myself the extra USB port by having both my network and input go over the same port. I guess the next thing to do after this would be to set up some sort of VNC server and connect to the Pi's GUI via the Droid.
My Build:
- Raspberry Pi v2 (Linux raspberrypi 3.1.9+ #125 PREEMPT)
- Asus Transformer Prime (Android 4.1.1. Jelly Bean)
- Yoobao "Long March" -11200mA 1A / 2A battery (good for 10+ hours!)
- VX ConnectBot terminal emulator (Free in the Google Play store)
- Hackers Keyboard - because I like tab complete (Free in the Google Play store)
Assumptions:
- Your PI is configured to run SSHd on startup
- You are using the default Pi username / password
- Your Android device has internet connectivity via WiFi/3G and it is enabled
How to do it:
Add the following to /etc/network/interfaces
iface usb0 inet static address 192.168.42.42 netmask 255.255.255.0 network 192.168.42.0 broadcast 192.168.42.255
Power down your Pi
Connect your Android device to your Pi via it's USB data cable
Power up your Pi... wait about a minute.
On your Android device, go to Settings / Wireless & Networks / More / Tethering & Portable Hotspot... click "USB tethering"
Start up VX ConnectBot and SSH "[email protected]"
Keep hitting return until it asks you for your password. Enter it.
Congratulations - you should now have terminal access to your Pi with a software keyboard... kinda. Mine seems to disconnect the session every minute or so - very annoying.
Now to set up routing so that your Pi can see the world via your Android device.
Root yourself up
sudo su -
Check to see which IP address that your Android device is using
arp -a
Mine is 192.168.42.129
Add a default route pointing all traffic from your Pi out to your Android device. It's worth noting that this static route is temporary and will not survive rebooting your Pi. I've left it like this because I don't know if Android likes to change it's tether gateway address very often. If you've gotten this far, I'll assume you can figure out how to make a static route permanent if need be :)
route add default gw 192.168.42.129 usb0
Test it!
ping http://www.google.com
这是做什么的:
允许您将 Android 设备用作 Raspberry Pi 的键盘输入和终端显示
允许您将 Raspberry PI 连接到 Android 设备的 WiFi(3G 未经测试,但应该可以使用)。
背景:
我喜欢真正便携的 Raspberry Pi 盒子的想法。我想做一个,但我没有兼容的 WiFi 加密狗,也没有无线键盘和鼠标。即使我做了所有这些事情,我还是希望通过让我的网络和输入通过同一个端口来节省额外的 USB 端口。我想接下来要做的就是设置某种 VNC 服务器并通过 Droid 连接到 Pi 的 GUI。
我的构建:
- 树莓派 v2(Linux 树莓派 3.1.9+ #125 PREEMPT)
- 华硕 Transformer Prime(Android 4.1.1。果冻豆)
- Yoobao“长征”-11200mA 1A / 2A 电池(10+ 小时好用!)
- VX ConnectBot 终端模拟器(在 Google Play 商店免费)
- 黑客键盘 - 因为我喜欢标签完成(在 Google Play 商店免费)
假设:
- 您的 PI 配置为在启动时运行 SSHd
- 您正在使用默认的 Pi 用户名/密码
- 您的 Android 设备已通过 WiFi/3G 连接互联网并已启用
怎么做:
将以下内容添加到 /etc/network/interfaces
iface usb0 inet static address 192.168.42.42 netmask 255.255.255.0 network 192.168.42.0 broadcast 192.168.42.255
关闭你的 Pi
通过它的 USB 数据线将您的 Android 设备连接到您的 Pi
给你的 Pi 加电……等一下。
在您的 Android 设备上,转到设置/无线和网络/更多/网络共享和便携式热点...单击“USB 网络共享”
启动 VX ConnectBot 和 SSH "[email protected]"
继续按回车键,直到它要求您输入密码。输入它。
恭喜 - 您现在应该可以使用软件键盘通过终端访问您的 Pi……有点。我的似乎每分钟左右断开会话 - 非常烦人。
现在设置路由,以便您的 Pi 可以通过您的 Android 设备看到世界。
扎根自己
sudo su -
检查您的 Android 设备正在使用哪个 IP 地址
arp -a
我的是 192.168.42.129
添加一条默认路由,将所有流量从您的 Pi 指向您的 Android 设备。值得注意的是,此静态路由是临时的,在重新启动 Pi 后将无法生存。我就这样离开了,因为我不知道Android是否喜欢经常更改它的系绳网关地址。如果您已经走到这一步,我假设您可以弄清楚如何在需要时使静态路由永久化:)
route add default gw 192.168.42.129 usb0
测试一下!
ping http://www.google.com
回答by sébastien dagnicourt
Setting a static ip won't work (always the dhcp that sets one). On the phone, you can see how to retrieve the IP address here : How to get the system ip address after usb tethering of android phone?
设置静态 ip 不起作用(总是设置一个的 dhcp)。在手机上,您可以在这里看到如何检索IP地址:Android手机USB共享后如何获取系统IP地址?