2

I am developing a wearable app on Tizen.net framework for Samsung galaxy watch active, to communicate with a raspberry pi. when a button method is triggered, the wearable connects to the bluetooth address given (hardcoded) and sends an integer to that address via GATT request (haven't implemented GATT part yet). However, my wearable will not find the address I am looking for, and thus wont connect to the le Bluetooth on raspberry pi FYI I am using raspberry pi 3+ on python 2.7.

I tried debugged on VS but it throws a segmentation fault due.

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;
        }
    }

I expect it to find the device based on the remote address, but ledevice remains null and is never updated, triggering a segmentation fault. How do I connect based on a pregiven address?

Mike
  • 37
  • 6

1 Answers1

3

We can check 2 things for this issue.

  1. The string value for address

    • It is possible to be caused by ( ) in address. So please remove ( ) , and test again. public static string remote_addr = "B8:27:EB:DC:D9:EC";
  2. The remote device (RPI3) is not in advertisement. So did not search really.

    • First, using android's app(nRF connect), try to scan your RPI3. and check if it is scanned or not in the mobile also.
    • Then, enter galaxy watch's shell. Scan it using scanning tool in low layer.
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)
jkdev
  • 11,360
  • 15
  • 54
  • 77
DoHyun Pyun
  • 146
  • 2
  • Thank you for your reply, However, I did remove the (), however my app is a tizen.net wearable app, it is not android, but is very similar. At any rate, removing () did not fix the issue. I do have the raspberry pi on sudo hcitool lescan. The raspberry pi is detecting the watch, but the watch app is not connecting still to the bluetooth address of RPI – Mike Jul 16 '19 at 14:09
  • Need to confirm the senario. 1. The GATT client role. (Scanning target) - Galaxy Watch Active > I am developing a wearable app on Tizen.net framework for Samsung galaxy watch active 2. The GATT server role (The remote target) - RPI3 (B8:27:EB:DC:D9:EC) Then,, you should check if the remote target RPI3 is adverising or not. To check it,, you can use your android phone's "nRF connect" app, or Galaxy Watch's console command. "hcitool lescan". Using this, you should confirm that RPI3 is advertising correctly. If RPI3 is not in advertising,,Galaxy Watch can't lescan it. – DoHyun Pyun Jul 17 '19 at 00:56
  • Thank you for your contribution. I had to make my RPI LE Bluetooth in discovery mode using command "sudo hciconfig0 hci0 leadv 0" and now my tizen.net wearable app connects to the RPI 3. After the connection, I need to send an integer from the app to the RPI and I'm struggling with the GATT structure. The integer that I will send refers to a GPIO pin on RPI that I want to switch HIGH when the value changes. What should be my GATT server the RPI or the wearable? any idea as to how to set it up? Thanks again and apologies, dealing with limited documentation (tizen.net) is frustrating. – Mike Jul 17 '19 at 15:53
  • Hello, you can refer this URL to use GATT server in RPI - https://scribles.net/running-ble-gatt-server-example-on-raspbian-stretch/ And.. In galaxy watch. You can refer under sample code to use GATT client - https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattClient.cs;h=41205cdb6e8ed77dddf25696c193e7c77a258051;hb=refs/heads/tizen – DoHyun Pyun Jul 18 '19 at 00:37