简体   繁体   English

App Inventor 2 和树莓派之间通过 usb 进行通信?

[英]Communication between App inventor 2 and Raspberry pi via usb?

I plan to create an android app that can take pictures and send them to a Raspberri pi 2.我计划创建一个 android 应用程序,它可以拍照并将它们发送到 Raspberri pi 2。

Even if I can use a Raspberri pi 3 or connect a bluetooth usb or wifi, I prefer to have a communication via usb only.即使我可以使用 Raspberri pi 3 或连接蓝牙 usb 或 wifi,我更喜欢仅通过 usb 进行通信。

What is the best option for a simple html, css and js based application like App inventor?对于简单的 html、css 和基于 js 的应用程序(如 App 发明者),最佳选择是什么?

I tried some app supposed to communicate by OTG cable but not working, may be my phone (chinese one) is not compatible.我尝试了一些应该通过 OTG 电缆进行通信但无法正常工作的应用程序,可能是我的手机(中文手机)不兼容。

I was thinking connecting rj45 to android, but look complicated.我正在考虑将 rj45 连接到 android,但看起来很复杂。

I know most people will use wifi but for special projects we may need to communicate via usb.我知道大多数人会使用 wifi,但对于特殊项目,我们可能需要通过 usb 进行通信。 I've finally found, for those who are looking, here are the steps:我终于找到了,对于那些正在寻找的人,以下是步骤:

  1. ssh on the raspberry pi or use screen and then:树莓派上的 ssh 或使用屏幕然后:
    Make the ip static :制作 ip static

    sudo nano /etc/network/interfaces
    add:添加:

     allow-hotplug usb0 iface usb0 inet static address 192.168.42.75 netmask 255.255.255.0 network 192.168.42.0 broadcast 192.168.42.255 gateway 192.168.42.1

    And/Or: ............// for me work with both和/或:........// 对我来说两者都工作
    sudo nano /etc/dhcpcd.conf
    add:添加:

     interface usb0 static ip_address=192.168.42.75/24 static routers=192.168.42.1 static domain_name_servers=192.168.42.1

    Replace the IP address (change 75) with a free IP address between the range 2-254.将 IP 地址(更改 75)替换为介于 2-254 之间的空闲 IP 地址。

  2. Reboot and connect the Pi to the Android phone.重新启动并将 Pi 连接到 Android 手机。

  3. On the phone activate USB Tethering :在电话上激活USB Tethering
    Settings> Network & Internet > Tethering & Mobile Hotspot设置>网络和互联网>网络共享和移动热点

  4. Use SSH_CLIENT extension in App Inventor to send your commands:在 App Inventor 中使用 SSH_CLIENT 扩展来发送您的命令:
    https://github.com/aluis-rcastro/AI2_ANDROID_SSH_CLIENT_EXTENSION https://github.com/aluis-rcastro/AI2_ANDROID_SSH_CLIENT_EXTENSION

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM