gpt4 book ai didi

android - 通过 USB 连接的 Android 设备控制 Raspberry Pi

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:09:22 32 4
gpt4 key购买 nike

我有一个运行自定义服务器的 Raspberry Pi 未连接到互联网(离线系统)。

我想通过 USB 线将 Android 设备连接到 rPi 并与之通信。

由于 Raspberry Pi 未连接到互联网,因此它没有 IP 地址(通过 DHCP 提供)。

如何使用通过 USB 连接的 Android 设备与 rPi 通信?

也许是本地 DHCP 服务器?

谢谢

最佳答案

关注this关联。您只需为其配置一次 RPi,就可以开始了。

What this does:

  1. Allows you to use your Android device as keyboard input and terminal display for your Raspberry Pi

  2. 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:

  1. 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
  2. Power down your Pi

  3. Connect your Android device to your Pi via it's USB data cable

  4. Power up your Pi... wait about a minute.

  5. On your Android device, go to Settings / Wireless & Networks / More / Tethering & Portable Hotspot... click "USB tethering"

  6. Start up VX ConnectBot and SSH "pi@192.168.42.42"

  7. 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.

  8. Root yourself up

    sudo su -
  9. Check to see which IP address that your Android device is using

    arp -a

    Mine is 192.168.42.129

  10. 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
  11. Test it!

    ping http://www.google.com

关于android - 通过 USB 连接的 Android 设备控制 Raspberry Pi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127865/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com