diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index 0166490e13629f846fa0567311974a56898559ed..65238e5cf32cbc9b20dfc32a1c0aa8aa67267e79 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -346,21 +346,36 @@ namespace RobobinApp.ViewModels _connectedDevice = await TryConnectAsync(Guid.Parse(SelectedDevice.MacAddress)); Debug.WriteLine($"Successfully connected to {SelectedDevice.Name}."); - - // Try to get services var services = await _connectedDevice.GetServicesAsync(); - if (services != null && services.Count > 0) + // Iterate through the discovered services + foreach (var service in services) { - foreach (var service in services) + Debug.WriteLine($"Service: ID={service.Id}, Name={service.Name}"); + + // Check if this is the Generic Access service + if (service.Id == Guid.Parse("00001800-0000-1000-8000-00805f9b34fb")) { - Debug.WriteLine($"Service: ID={service.Id}, Name={service.Name}"); + Debug.WriteLine("Found Generic Access service!"); + + // Get the characteristic for the device name + var deviceNameCharacteristic = service.GetCharacteristicAsync(Guid.Parse("00002a00-0000-1000-8000-00805f9b34fb")); + + if (deviceNameCharacteristic != null) + { + // Read the device name characteristic + + Debug.WriteLine($"Device Name: {deviceNameCharacteristic}"); + await Application.Current.MainPage.DisplayAlert("Device Name", $"Device Name: Paul", "OK"); + } + else + { + Debug.WriteLine("Device name characteristic not found."); + } } } - else - { - Debug.WriteLine("No services found."); - } + + // Optional: Handle other services or characteristics if needed } catch (DeviceConnectionException ex) { @@ -381,8 +396,6 @@ namespace RobobinApp.ViewModels } } - - private async void OnDisconnect() { if (_connectedDevice != null) diff --git a/ButtonControls/RPiBluetooth.py b/ButtonControls/RPiBluetooth.py deleted file mode 100644 index cb10a936c616154215767398771699e2fc4592a8..0000000000000000000000000000000000000000 --- a/ButtonControls/RPiBluetooth.py +++ /dev/null @@ -1,37 +0,0 @@ -import dbus -import dbus.service -from dbus.mainloop.glib import DBusGMainLoop -from gi.repository import GLib - -# Define a UUID for your service -SERVICE_UUID = '00001801-0000-1000-8000-00805f9b34fb' - -class BLEService(dbus.service.Object): - def __init__(self, bus, index): - self.path = f"/org/bluez/example/service{index}" - self.props = { - 'UUID': dbus.String(SERVICE_UUID), - 'Primary': dbus.Boolean(True), - } - super().__init__(bus, self.path) - - @dbus.service.method('org.bluez.GattService1', in_signature='', out_signature='a{sv}') - def GetProperties(self): - return self.props - - @dbus.service.method('org.bluez.GattService1', in_signature='', out_signature='') - def Release(self): - print(f"{self.path}: Released") - -def main(): - DBusGMainLoop(set_as_default=True) - bus = dbus.SystemBus() - - service = MyBLEService(bus, 0) - - print("BLE Service running. Press Ctrl+C to stop.") - mainloop = GLib.MainLoop() - mainloop.run() - -if __name__ == '__main__': - main() diff --git a/ButtonControls/ bluetoothTest.py b/Connectivity/ bluetoothTest.py similarity index 100% rename from ButtonControls/ bluetoothTest.py rename to Connectivity/ bluetoothTest.py diff --git a/Connectivity/RPiBluetooth.py b/Connectivity/RPiBluetooth.py new file mode 100644 index 0000000000000000000000000000000000000000..b66dd05d7b7d91c2e1c9964c36e16283ccea79cb --- /dev/null +++ b/Connectivity/RPiBluetooth.py @@ -0,0 +1,63 @@ +import dbus +import dbus.service +from dbus.mainloop.glib import DBusGMainLoop +from gi.repository import GLib + +# Define UUIDs for your service and characteristic +SERVICE_UUID = '00001801-0000-1000-8000-00805f9b34fb' +PAIRING_UUID = '00002a25-0000-1000-8000-00805f9b34fb' + +class PairingCharacteristic(dbus.service.Object): + def __init__(self, service, index): + self.path = f"{service.path}/char{index}" + self.service = service + self.props = { + 'UUID': dbus.String(PAIRING_UUID), + 'Service': dbus.ObjectPath(service.path), + 'Flags': dbus.Array(['read', 'write'], signature='s') + } + super().__init__(service.bus, self.path) + + @dbus.service.method('org.bluez.GattCharacteristic1', in_signature='', out_signature='a{sv}') + def GetProperties(self): + return self.props + + @dbus.service.method('org.bluez.GattCharacteristic1', in_signature='ay', out_signature='ay') + def ReadValue(self, options): + return dbus.Array([dbus.Byte(0x00)], signature='y') + + @dbus.service.method('org.bluez.GattCharacteristic1', in_signature='aya{sv}', out_signature='') + def WriteValue(self, value, options): + print(f"Pairing request received: {value}") + # Handle pairing logic here + +class BLEService(dbus.service.Object): + def __init__(self, bus, index): + self.path = f"/org/bluez/example/service{index}" + self.props = { + 'UUID': dbus.String(SERVICE_UUID), + 'Primary': dbus.Boolean(True), + } + super().__init__(bus, self.path) + self.characteristics = [PairingCharacteristic(self, 0)] + + @dbus.service.method('org.bluez.GattService1', in_signature='', out_signature='a{sv}') + def GetProperties(self): + return self.props + + @dbus.service.method('org.bluez.GattService1', in_signature='', out_signature='') + def Release(self): + print(f"{self.path}: Released") + +def main(): + DBusGMainLoop(set_as_default=True) + bus = dbus.SystemBus() + + service = BLEService(bus, 0) + + print("BLE Service running. Press Ctrl+C to stop.") + mainloop = GLib.MainLoop() + mainloop.run() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/ButtonControls/Workstations.py b/Connectivity/Workstations.py similarity index 100% rename from ButtonControls/Workstations.py rename to Connectivity/Workstations.py