0

I am writing a .NET application that needs to send Bluetooth packages to a MagicBlue LED. In other words, I would like to create a .NET application similar to it's Android one: https://itunes.apple.com/us/app/led-magic-blue/id992330218?mt=8

Here is a demo: https://www.youtube.com/watch?v=5Q3aQjuiLY0

My Bluetooth Adapter has found the bulb and connected to it, so it is discoverable, also I have it's MAC Address, that is needed for my purpose.

I am using the InTheHand (32Feet Bluetooth) .NET Library to communicate. The bulb needs to receive an array of bytes, in order to execute a command (change the color, power on/off, etc).

// I use this Write function to send an array of bytes.
private bool Write(byte[] buffer)
{
    using (var bluetoothClient = new BluetoothClient())
    {
        try
        {
            var ep = new BluetoothEndPoint(_macAddress, Guid.NewGuid());
            bluetoothClient.Connect(ep);
            var bluetoothStream = bluetoothClient.GetStream();
            if (bluetoothStream != null)
            {
                bluetoothStream.Write(buffer, 0, buffer.Length);
                bluetoothStream.Flush();
                bluetoothStream.Close();
                return true;
            }
        }
        catch (Exception ex) { } 
    }
}

When I reach to bluetoothClient.Connect(ep);, it throws an exception saying that "the connected party did not properly responded after a period of time...".

How can I solve this problem the array of bytes to the bulb?

PianoSong
  • 340
  • 4
  • 18
  • is `_macAddress` of type `BluetoothAddress`? how do you construct it? what does passing a random Guid as the service Id do? – Cee McSharpface Jan 10 '18 at 20:06
  • Yes, `_macAddress` is of type BluetoothAddress. `_macAddress = new BluetoothAddress(macAddrBytes);`. Passing a random Guid, does nothing. The same is when I use the `ClassGuid` found in `DeviceManager/Bluetooth/MyDevice/Details/Property`. The Property `Driver Description` has value `Bluetooth LE (Low Energy) Device`. And I found few minutes ago that `32Feet` does not support LE devices. Can this represent a problem? – PianoSong Jan 10 '18 at 20:22

1 Answers1

0

change to:

var ep = new BluetoothEndPoint(_macAddress, BluetoothService.HandsFree);

its will be working fine!

ekrem tapan
  • 147
  • 4
  • 15