如何实现通信
首先,我们要意识到一点,Android与树莓派都是独立的linux系统,二者通信其实是两台独立设备之间的通信,可以有三种方式:
1)有线通信
2)无线通信
3)蓝牙通信
1、基于USB有线通信方式下的Android设备控制树莓派
设置树莓派
Add the following lines into your network configuration:
vi /etc/network/interfaces
allow-hotplug usb0
iface usb0 inet dhcp
When you would have already connected all devices, and you do not want to reboot, just restart the network:
/etc/init.d/networking restart
连接安卓设备
Connect your Android Tablet to a Raspberry Pi USB port via a micro-USB cable. Power your Raspberry Pi with a standard USB power supply. You can use any DC USB power supply.
设置安卓允许USB分享
Enable USB tethering on your Android tablet.
Settings → Connections → Tethering and Wi-Fi hotspot → USB tethering
Now the Raspberry automatically gets an IP address via its USB0 port. The Android tablet behaves like a NAT router. This should work both when your tablet is connected to Wi-Fi or to a mobile 3G/4G network.
2、基于***无线通信***方式下的Android设备控制树莓派
在树莓派上安装相应的服务器框架,实现GET/POST请求响应
3、基于***蓝牙通信***方式下的Android设备控制树莓派
基于GATT通信协议,实现蓝牙连接;
在树莓派中写好响应命令,在安卓设备备中发送请求调用相应的请求
具体参考书籍2
参考:
1、https://elinux.org/How_to_use_an_Android_tablet_as_a_Raspberry_Pi_console_terminal_and_internet_router
2、书籍 Raspberry Pi Android Peoject