简体   繁体   English

Bluez编程

[英]Bluez Programming

I'm programming in BlueZ on my Raspberry Pi with an USB Bluetooth dongle. 我正在使用USB蓝牙适配器在我的Raspberry Pi上使用BlueZ进行编程。 I need to be able to programmatically connect to an Arduino BT, the problem is that the Bluetooth module of the Arduino is still using legacy pairing so whenever I try to open a socket to the device I get a Permission Denied . 我需要能够以编程方式连接到Arduino BT,问题是Arduino的蓝牙模块仍在使用传统配对,因此每当我尝试打开设备的套接字时,我都会获得Permission Denied How do I send along a PIN to complete the pairing request through BlueZ? 如何通过BlueZ发送PIN码来完成配对请求?

You might want to check out the main.c file in the client folder of the most recent Bluez source code. 您可能想要查看最新Bluez源代码的客户端文件夹中的main.c文件。 It's the source code for the bluetoothctl tool. 这是bluetoothctl工具的源代码。 Run it too. 也跑吧。 The source code shows exactly how they use GDBus, including proxies, agents, calling methods like described in the API ( /doc folder ) and all that. 源代码确切地显示了它们如何使用GDBus,包括代理,代理,API( / doc文件夹 )中描述的调用方法等等。 It's in C and uses the high level API. 它在C中并使用高级API。

I suggest you step through the code because it took me 2 weeks endlessly trying to understand Bluez in C and the fact that there's no documentation, but when I read that main.c file I was ready in a day. 我建议你逐步完成代码,因为我花了两个星期无休止地试图理解C语言中的Bluez以及没有文档的事实,但是当我读到main.c文件时,我已经准备好了一天。 Read up on proper Dbus API documentation and more importantly the concepts. 阅读适当的Dbus API文档,更重要的是概念。 Some documents that helped me: 一些帮助我的文件:

The gdbus tool: https://developer.gnome.org/gio/stable/gdbus.html gdbus工具: https//developer.gnome.org/gio/stable/gdbus.html

These contain all the calls to gdbus and objects in the main.c file and explain them very well. 它们包含对main.c文件中gdbus和对象的所有调用,并对它们进行了很好的解释。 https://developer.gnome.org/gio/stable/gdbus-convenience.html https://developer.gnome.org/gio/stable/gdbus-convenience.html

D-Feet, an invaluable tool to inspecting and learning about Dbus on your system. D-Feet,一种在您的系统上检查和了解Dbus的宝贵工具。 Try checking out the /bluez bus. 尝试检查/ bluez总线。 https://wiki.gnome.org/action/show/Apps/DFeet?action=show&redirect=DFeet https://wiki.gnome.org/action/show/Apps/DFeet?action=show&redirect=DFeet

or 要么

sudo apt-get install d-feet

Not much of a tutorial, but worth a read to understand some concepts, as the bluetoothctl tool fits into what they're trying to say here. 没有太多的教程,但值得阅读以理解一些概念,因为bluetoothctl工具符合他们在这里想说的内容。 http://dbus.freedesktop.org/doc/dbus-tutorial.html http://dbus.freedesktop.org/doc/dbus-tutorial.html

The bluetoothctl creates an interactive shell though, so it might not be wise to waste time trying to fit in your code, but just pick what you need from it. bluetoothctl创建了一个交互式shell,因此浪费时间尝试适合您的代码可能并不明智,只需从中选择您需要的内容即可。

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

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