【发布时间】:2020-07-07 18:38:30
【问题描述】:
在我的 pi 崩溃后,我一直在尝试建立与 Hc-06 BT 模块的蓝牙连接。我过去成功地做到了,但由于 pi 崩溃而丢失了原始程序。我相信我已经遵循了每个教程的每一步,但不知何故它不起作用。
到目前为止我做了什么: 我做到了:
- 用我的手机和一个BT串口应用程序连接到HC-06,验证它工作正常,是的!
- 让 pi 与 HC-06 成功配对
- 让 pi 信任 hc-06。
- 每次启动应用程序时,我都会运行一个 shell 脚本,如下所示
sudo killall Xvfb
sudo killall java
sudo rfcomm bind rfcomm0 20:14:04:15:23:75 // 是的,这里的地址是正确的
sudo xvfb-run /home/pi/Documents/application.linux-armv6hf/piTrain
我正在使用的应用程序是一个处理草图。我开发了一个功能来连接蓝牙模块。 BT 背后的设备是 arduino nano。整体是一个手控器(
现在我的记忆告诉我,执行这行代码会在过去建立连接:
handController = new Serial( this , "/dev/rfcomm0" , 9600 );
它不再这样做了,所以显然我忘记了要做的事情。
握手功能:
void handShaking() {
int b;
if( handController.available() > 0 ) {
if( handControllerConnected == false ) {
handControllerConnected = true;
println("connection with handcontroller established!");
}
b = handController.read();
dccCentral.write( b );
println("controller: " + (char) b );
handControllerTimeout = millis() + 5000 ;
}
if(dccCentral.available() > 0 ) {
b = dccCentral.read();
handController.write( b );
println("central: " + (char) b );
}
if( millis() > handControllerTimeout ) {
if( handControllerConnected == true ) {
handControllerConnected = false;
println("connection with hand controller lost!");
handControllerTimeout = millis() + 5000 ;
}
else {
try {
handController.stop();
}
catch ( NullPointerException e) {
println(" error terminating connection ");
}
try {
handController = new Serial( this , "/dev/rfcomm0" , 9600 );
handController.write('$');
handController.write('$');
handController.write('9');
println("attempting to connect with hand controller...");
}
catch(Exception e){
println("error cannot set up hand controller connection");
}
handControllerTimeout = millis() + 10000 ;
}
}
}
在我调用 handController.stop() 后,每 10 秒调用一次以下行 新序列号(这个,“/dev/rfcomm0”,9600); 程序的输出:
pi@raspberrypi:~ $ ./boot.sh
Can't create device: Device or resource busy
0 /dev/rfcomm0
1 /dev/serial1
2 /dev/ttyAMA0
3 /dev/ttyUSB0
setting up connecton with DCC central
12
respons = hello
respons confirmed, connection with DCC central established
setting up connecton with RS485 bus
connecton set up!
rs485 bus cleared
central:
central: B
central: a
central: s
central:
central:
central:
connection with hand controller lost!
attempting to connect with hand controller...
attempting to connect with hand controller...
只要 Wifi 不崩溃,这种情况就会持续下去。
不同的是我的工作方法。事故发生后,我希望 Rpi 尽可能“愚蠢”。我在我的 Windows PC 上用 VS 代码编写我的处理草图。我使用 processing-java 命令行工具来导出草图。使用 scp,我将整个文件夹传输到 rpi,然后运行启动脚本。
也许这确实意味着一些有用的东西:
pi@raspberrypi:~ $ sudo rfcomm connect hci0 20:14:04:15:23:75
Can't connect RFCOMM socket: Connection reset by peer
pi@raspberrypi:~ $ sudo rfcomm connect rfcomm0 20:14:04:15:23:75
Can't connect RFCOMM socket: Connection refused
上次蓝牙连接是在公园里散步时,它只是...起作用了。
谁能告诉我我忘记了什么或做错了什么?
编辑: 额外信息。在蓝牙程序中,我得到了这个输出。连接后我快速运行信息,自动断开仍然发生
[bluetooth]# connect 20:14:04:15:23:75
Attempting to connect to 20:14:04:15:23:75
[CHG] Device 20:14:04:15:23:75 Connected: yes
[CHG] Device 20:14:04:15:23:75 ServicesResolved: yes
Failed to connect: org.bluez.Error.NotAvailable
[Hand Controller]# info 20:14:04:15:23:75
Device 20:14:04:15:23:75 (public)
Name: Hand Controller
Alias: Hand Controller
Class: 0x00001f00
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: yes
UUID: Serial Port (00001101-0000-1000-8000-00805f9b34fb)
[CHG] Device 20:14:04:15:23:75 ServicesResolved: no
[CHG] Device 20:14:04:15:23:75 Connected: no
[bluetooth]# info 20:14:04:15:23:75
Device 20:14:04:15:23:75 (public)
Name: Hand Controller
Alias: Hand Controller
Class: 0x00001f00
Paired: yes
Trusted: yes
Blocked: no
Connected: no
LegacyPairing: yes
UUID: Serial Port (00001101-0000-1000-8000-00805f9b34fb)
[bluetooth]#
【问题讨论】:
-
我了解到蓝牙模块不断自动断开连接。我正在使用蓝牙ctl。我试过取消配对和不信任等,它没有效果。当我连接时,如果几秒钟后自动断开连接。当我绑定时,它一直在连接/断开连接。为什么是这样?我在我的 pi 3b btw 上使用最新的 raspbian 版本
标签: bluetooth processing