I tried but anyway the connection print the data received to my C# console and not the bangle. I tried even by deactivating the console with the code below, same results:
setInterval(() => (console.log(E.getTemperature())), 1000);
g.setFontAlign(0,0);
g.setFont("Vector",25);
var gatt;
E.setConsole(null);
NRF.on('connect', function(addr) {
g.clear();
g.setFont("Vector",10);
g.setColor(255,0,0);
g.drawString(addr,g.getWidth()/2, g.getHeight()/2);
g.setFont("Vector",25);
setTimeout(()=>g.drawString("Connected", g.getWidth()/2, g.getHeight()/2), 3000);
setTimeout(()=>g.clear(), 1000);
});
NRF.on('disconnect', function(reason) {
g.clear();
g.setColor(0,0,255);
g.drawString("Disconnected", g.getWidth()/2, g.getHeight()/2);
setTimeout(()=> g.clear(), 1000);
});
Bluetooth.on('data', function(d) {
g.clear();
Bluetooth.println(d);
g.setColor(0,0,0);
g.drawString('Data received', g.getWidth()/2, g.getHeight()/2);
g.drawString(s);
g.drawString(s, g.getWidth()/2, g.getHeight()/2);
});
this is instead the C# console class:
internal class Program
{
static DeviceInformation _device = null;
private static string NORDIC_UART_SERVICE = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
static DataFormat _dataFormat = DataFormat.UTF8;
static GattCommunicationStatus result;
static GattCharacteristic _characteristic;
static async Task Main(string[] args)
{
// Query for extra properties you want returned
string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" };
DeviceWatcher deviceWatcher =
DeviceInformation.CreateWatcher(
BluetoothLEDevice.GetDeviceSelectorFromPairingState(false),
requestedProperties,
DeviceInformationKind.AssociationEndpoint);
// Register event handlers before starting the watcher.
// Added, Updated and Removed are required to get all nearby devices
deviceWatcher.Added += DeviceWatcher_Added;
deviceWatcher.Updated += DeviceWatcher_Updated;
deviceWatcher.Removed += DeviceWatcher_Removed;
// EnumerationCompleted and Stopped are optional to implement.
deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
deviceWatcher.Stopped += DeviceWatcher_Stopped;
// Start the watcher.
deviceWatcher.Start();
while (true)
{
if (_device == null)
{
Thread.Sleep(200);
}
else
{
Console.WriteLine("Press any key to connect to the Bangle. Js");
Console.ReadKey();
BluetoothLEDevice bluetoothLEDevice = await BluetoothLEDevice.FromIdAsync(_device.Id);
Console.WriteLine("Pairing with the device");
GattDeviceServicesResult servicesResult = await bluetoothLEDevice.GetGattServicesAsync();
if (servicesResult.Status == GattCommunicationStatus.Success)
{
Console.WriteLine("Pairing succeed");
var services = servicesResult.Services;
foreach (var service in services)
{
Console.WriteLine($"Service: {service.Uuid}");
Console.WriteLine("-----------------------");
if (service.Uuid.ToString() == NORDIC_UART_SERVICE)
{
Console.WriteLine("Connected to NUS Service");
Console.WriteLine("----------------------------------");
GattCharacteristicsResult characteristicsResult = await service.GetCharacteristicsAsync();
if (characteristicsResult.Status == GattCommunicationStatus.Success)
{
var characteristics = characteristicsResult.Characteristics;
foreach (var characteristic in characteristics)
{
Console.WriteLine($"Characteristic {characteristic.Uuid}");
Console.WriteLine("--------------------------------");
GattCharacteristicProperties properties = characteristic.CharacteristicProperties;
if (properties.HasFlag(GattCharacteristicProperties.Notify))
{
Console.WriteLine("Notify property found");
GattCommunicationStatus status = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
if (status == GattCommunicationStatus.Success)
{
Console.WriteLine("Server has been informed of clients interest and has set the client in notify status");
characteristic.ValueChanged += Characteristic_ValueChanged;
_characteristic = characteristic;
}
}
else if (properties.HasFlag(GattCharacteristicProperties.Write))
{
Console.WriteLine($"\t \t Characteristic {characteristic.Uuid} has a write property ");
Console.WriteLine("-------------------------------- ");
var writer = new DataWriter();
writer.WriteString("Data received");
result = await characteristic.WriteValueAsync(writer.DetachBuffer());
if (result == GattCommunicationStatus.Success)
{
Console.WriteLine("Data sent");
}
}
else if (properties.HasFlag(GattCharacteristicProperties.WriteWithoutResponse))
{
Console.WriteLine($"\t \t Characteristic {characteristic.Uuid} has a write withoutresponse property ");
Console.WriteLine("-------------------------------- ");
}
}
}
}
}
}
Console.WriteLine("Press space to disconnect or q to exit");
if (Console.ReadKey().Key == ConsoleKey.Spacebar)
{
bluetoothLEDevice.Dispose();
return;
}
else if (Console.ReadKey().Key == ConsoleKey.Q)
{
Console.WriteLine("Closing");
Thread.Sleep(1000);
}
break;
}
}
}
private static void DeviceWatcher_Stopped(DeviceWatcher sender, object args)
{
//throw new NotImplementedException();
}
private static void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
{
//throw new NotImplementedException();
}
private static void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
{
//throw new NotImplementedException();
}
private static void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
{
//throw new NotImplementedException();
}
private static void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
{
if (args.Name == "Bangle.js 0ea8")
{
Console.WriteLine(args.Name);
_device = args;
}
}
private static void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
{
//An Indicate or Notify reported that the value has changed.
var value = Utilities.FormatValue(args.CharacteristicValue, _dataFormat);
if (value.Contains('J'))
{
string[] values = value.Split('J');
Console.WriteLine(values[1]);
}
else
{
Console.WriteLine(value);
}
}
Any other suggestion?
I tried but anyway the connection print the data received to my C# console and not the bangle. I tried even by deactivating the console with the code below, same results:
this is instead the C# console class:
Any other suggestion?