在配对的Android和Raspberry PI之间通过蓝牙进行数据传输 [英] Data transfer via bluetooth between paired Android and Raspberry PI

查看:95
本文介绍了在配对的Android和Raspberry PI之间通过蓝牙进行数据传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我需要通过蓝牙在android和raspberry pi之间传输数据.但是,我对此并不陌生,并且我对两个设备配对时会发生的情况没有很深入的了解.基于相关的两个设备已经配对的假设,为该任务编程的起点将在哪里?我一直在阅读BluetoothSocket,但是我仍然不确定从哪里开始.有人可以帮我吗?

I am working on a project where I need to transfer data between android and raspberry pi via Bluetooth. However, I am new to this and I don't have deep understanding on what happens when two devices are paired. Based on assumption that the two devices of interest are already paired, where would the starting point be for programming for such task? I've been reading on BluetoothSocket, but I am still unsure of where to start. Can anyone help me please?

非常感谢您!

推荐答案

不久前,我一直在从事同一任务.关键是,为了开始发送和接收数据,您必须首先建立连接.有两个连接(创建套接字)的侧设备和另一个接收连接(蓝牙服务器套接字)的设备,连接完成后即发出连接.建立连接后,您应该停止接收传入的连接或尝试建立任何连接. 从实现的角度来看,您应该实现几个线程来管理所有这些阶段-连接线程,接受线程,通信线程. Google提供了一个很好的例子: https://github.com/googlesamples/android-BluetoothChat .它使用该技术.唯一的缺点是它使用Handler(Android功能,允许读取进行通信)来通知用户蓝牙事件.我通过引入另一个线程,接收状态更新和从回调接口调用方法进行了一些修改,可以随时使用项目中的代码: https://github.com/AlexShutov/LEDLights .

I've been working on the same task little while ago. The point is, that in order to start sending and receiving data you have to establish connection first. There is two side- device which connects (creates socket) and the other receiving connection (bluetooth server socket), giving out connection once connection is complete. After connection is established, you should stop receiving incoming connection or attempting establishing any connections. From implementation perspective, you should implement few threads for managing all those stages - connection thread, accept thread, communucation thread. There is a great example from Google: https://github.com/googlesamples/android-BluetoothChat . It uses that technic. The only drawback is that it uses Handler (Android feature, allowing thereads to communicate) for informing user about Bluetooth events. I modified it a bit by introducing another thread, receiving status updates and calling methods from callback interface, feel free to use code from project: https://github.com/AlexShutov/LEDLights.

这篇关于在配对的Android和Raspberry PI之间通过蓝牙进行数据传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆