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?