Dear @geopaxpvtltd,
I was able to get the bluetooth working properly using d-bus api.
Thanks for that update. Also, glad to hear that you got it running.
In the meantime, I had some time to work on this issue. I was trying to reproduce the issue you are facing and interestingly I found that Bluetooth works just fine on your version of Hardware and TorizonCore. You can test it on the device (outside the container) by running the bluetoothctl
commands. You may follow some examples here or on this page.
This would confirm that the Bluetooth controller is working just fine on your Hardware and on your version of TorizonCore installed.
I could reproduce this error thrown from the hci_get_route
function in a C++ code running in a debian container. During my attempts to solve the error, I found this thread that is related. As you might have seen, the issue was solved by simply adding an extra argument --net=host
to the docker run command. This is to make the container run in the host’s network environment. In my case, this is how I started a simple Debian container with docker run command:
docker run -it --net=host torizon/debian:$CT_TAG_DEBIAN /bin/bash
After that, I was able to compile and run the C++ code successfully within the container (Of course I installed the libbluetooth-dev
library and other packages I need inside the container to get it running).
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
int main(int argc, char **argv)
{
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };
dev_id = hci_get_route(NULL);
if (dev_id < 0)
{
perror("Error: No Bluetooth adapter found.");
exit(1);
}
sock = hci_open_dev( dev_id );
if (dev_id < 0 || sock < 0) {
perror("opening socket");
exit(1);
}
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
if( num_rsp < 0 ) perror("hci_inquiry");
for (i = 0; i < num_rsp; i++) {
ba2str(&(ii+i)->bdaddr, addr);
memset(name, 0, sizeof(name));
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
name, 0) < 0)
strcpy(name, "[unknown]");
printf("%s %s\n", addr, name);
}
free( ii );
close( sock );
return 0;
}
You should be able to do the same using the configuration option
network_mode: "host"
in the docker-compose file. Please see the Compose file reference for more details.
I believe this would be the easiest solution for you compared to using dbus-api. If you get some time to test this, let me know how it goes
In this case, I will not be escalating the issue internally since it already works on this HW and SW setup. Let me know if you have more questions.