Reputation: 103
Are there any samples of a BLE Server implemented in C++ in a Linux environment? 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. The device will be broadcasting characteristics that the mobile app can subscribe to, and they can also send/receive messages preferably in JSON format. 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.
Upvotes: 0
Views: 2238
Reputation: 13305
My recommendation is that you take the following direction:-
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.
As for implementing the application through the command line, I recommend using bluetoothctl tool as can be seen in the following answer:-
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.
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. You can do so by browsing the source code for the bluetoothctl command that was used earlier. You can find the source for the BlueZ stack here, and the code for the bluetoothctl command can be found here.
I hope this helps.
Upvotes: 2