将 LE 蓝牙从 samsung watch active wearable app 连接到 raspberry pi,并向其发送 gattservice

Connect LE bluetooth from samsung watch active wearable app to raspberry pi, and send gattservice to it

我正在为 Samsung galaxy watch active 在 Tizen.net 框架上开发可穿戴应用程序,以便与 raspberry pi 进行通信。当触发按钮方法时,可穿戴设备连接到给定(硬编码)的蓝牙地址,并通过 GATT 请求(尚未实现 GATT 部分)向该地址发送一个整数。但是,我的可穿戴设备找不到我要查找的地址,因此无法连接到 raspberry pi 上的蓝牙,仅供参考,我在 python 2.7.[=12 上使用 raspberry pi 3+ =]

我尝试在 VS 上调试,但它抛出了一个分段错误。

static BluetoothGattClient client = null;
static bool StateChanged_flag = false;
public static string remote_addr = ("B8:27:EB:DC:D9:EC");
public static BluetoothLeDevice leDevice = null;



//Here is my buttonClick method that should trigger the connection. 
private async void ConnectBrewer_Clicked(object sender, EventArgs e)
    {
        try
        {
            if (!BluetoothAdapter.IsBluetoothEnabled)
            {
                Toast.DisplayText("Please turn on Bluetooth.");
            }
            else
            {
                ConnectBrewer.IsEnabled = false;
                BluetoothAdapter.ScanResultChanged += scanResultEventHandler;
                if (leDevice == null)
                {
                    BluetoothAdapter.StartLeScan();
                    await WaitScanFlag();
                    BluetoothAdapter.StopLeScan();
                    ConnectBrewer.IsEnabled = true;

                }

                else
                {
                    ConnectBrewer.Text = "Found";
                    ConnectBrewer.IsEnabled = false;
                    index_Page.Children[2].IsVisible = true;
                    index_Page.CurrentPage = index_Page.Children[2];
                    leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged;
                    client = leDevice.GattConnect(false);
                    ConnectBrewer.Text = "Connected!";
                }

            }
        }
        catch (Exception ex)
        {
            Toast.DisplayText("Error: " + ex.Message);
        }
    }

public async Task WaitScanFlag()

    {
        int count = 0;
        do
        {
            await Task.Delay(3000);
            if (count % 4 == 0)
            { 

            }
            count++;

        } while (count < 10 && !scanFlag);

    }
public static void scanResultEventHandler(object sender, AdapterLeScanResultChangedEventArgs e)
    {

        int txLevel;
        int rssi;
        BluetoothError result;
        string address;
        BluetoothLePacketType PacketType;

        if (!e.DeviceData.Equals(null) && e.DeviceData.RemoteAddress.Equals(remote_addr))
        {
//Here is where I am setting my leDevice object,based on the remote address, but the if statement conditions are never true. 
               leDevice = e.DeviceData;
            result = e.Result;
            scanFlag = true;
        }

    }
public static void LeDevice_GattConnectionStateChanged(object sender, GattConnectionStateChangedEventArgs e)
    {
        if (e.Result != (int)BluetoothError.None)
        {
            StateChanged_flag = false;
        }
        else if (!e.RemoteAddress.Equals(remote_addr))
        {
            StateChanged_flag = false;
        }
        else if (e.IsConnected.Equals(false))
        {
            StateChanged_flag = false;
        }
        else
        {
            StateChanged_flag = true;
        }
    }

我希望它能根据远程地址找到设备,但 ledevice 仍然为 null 并且永远不会更新,从而触发了分段错误。如何根据预先给定的地址进行连接?

我们可以针对此问题检查 2 项内容。

  1. 地址的字符串值

    • 可能是地址中的( )引起的。所以请删除 ( ) ,然后重新测试。 public static string remote_addr = "B8:27:EB:DC:D9:EC";
  2. 远程设备 (RPI3) 不在广告中。所以真的没有搜。

    • 首先,使用 android 的应用程序(nRF 连接),尝试扫描您的 RPI3。并检查它是否也在手机中被扫描。
    • 然后,进入银河手表shell。使用低层扫描工具扫描。
sdb root on
sdb shell
hcitool lescan
LE Scan ...
E4:DB:6D:62:4B:09 (unknown)
E4:DB:6D:62:4B:09 (unknown)
B8:BB:AF:C2:7B:1D (unknown)