简体   繁体   English

在Linux环境中使用C ++的BLE服务器端实现

[英]BLE Server side implementations using C++ in a Linux environment

Are there any samples of a BLE Server implemented in C++ in a Linux environment ? 在Linux环境中,是否有任何用C ++实现BLE服务器示例? For context I have an NVIDIA Jetson TX2 board running Ubuntu and I'd like to have a BLE server in it that I can pair Android and iOS devices. 就上下文而言,我有一个运行UbuntuNVIDIA Jetson TX2板 ,我想在其中配备一个BLE服务器,可以将Android和iOS设备配对。 The device will be broadcasting characteristics that the mobile app can subscribe to, and they can also send/receive messages preferably in JSON format. 该设备将广播该移动应用程序可以订阅的特征,并且它们还可以发送/接收消息(最好是JSON格式)。 It currently has some Bluetooth codes but I think this only works in Classic mode: 它目前有一些蓝牙代码,但我认为这仅适用于经典模式:

...
int s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

loc_addr.rc_family = AF_BLUETOOTH;
loc_addr.rc_bdaddr = *BDADDR_ANY_INITIALIZER;
loc_addr.rc_channel = (uint8_t) 22;

int b = bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
...

I am still very new to C++, Linux and BLE development in general, so I'd like to get pointers to the right direction. 一般而言,我对C ++,Linux和BLE开发还是很陌生,所以我想向正确的方向发展。

My recommendation is that you take the following direction:- 我的建议是您遵循以下方向:

  1. Implement your application through the command line. 通过命令行实施您的应用程序。
  2. Implement your application through an automated shell script. 通过自动化的Shell脚本实现您的应用程序。
  3. (Optional) Implement your application using C/C++. (可选)使用C / C ++实现您的应用程序。

If having the application written in C/C++ is not a requirement, then I recommend skipping this step as you can achieve the same result with the shell script. 如果不需要用C / C ++编写应用程序,则建议跳过此步骤,因为您可以使用Shell脚本获得相同的结果。

As for implementing the application through the command line, I recommend using bluetoothctl tool as can be seen in the following answer:- 至于通过命令行实现应用程序,我建议使用bluetoothctl工具,如以下答案所示:

Once this starts working for you and you are able to connect from a remote device and browse the GATT table, convert the list of commands into a shell script and fire it to see the same results. 一旦这开始为您工作,您就可以从远程设备连接并浏览GATT表,将命令列表转换为Shell脚本并触发它以查看相同的结果。

Finally, if this works for you up to this point, then the next step is to convert that shell script into a C/C++ application. 最后,如果到目前为止,这对您仍然有效,则下一步是将该Shell脚本转换为C / C ++应用程序。 You can do so by browsing the source code for the bluetoothctl command that was used earlier. 您可以通过浏览先前使用的bluetoothctl命令的源代码来实现。 You can find the source for the BlueZ stack here , and the code for the bluetoothctl command can be found here . 您可以在此处找到BlueZ堆栈的源,并在此处找到bluetoothctl命令的代码。

I hope this helps. 我希望这有帮助。

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

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