Skip to content
Snippets Groups Projects
Commit b5b7008e authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Renamed folder to somehting slightly more clear, RPiBluetooth was able to be...

Renamed folder to somehting slightly more clear, RPiBluetooth was able to be used to get the services via the app/
parent 6bf0d868
No related branches found
No related tags found
1 merge request!1App now has a basic structure and BLE support
......@@ -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)
......
File moved
......@@ -3,8 +3,33 @@ import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
# Define a UUID for your service
# 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):
......@@ -14,6 +39,7 @@ class BLEService(dbus.service.Object):
'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):
......@@ -27,11 +53,11 @@ def main():
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
service = MyBLEService(bus, 0)
service = BLEService(bus, 0)
print("BLE Service running. Press Ctrl+C to stop.")
mainloop = GLib.MainLoop()
mainloop.run()
if __name__ == '__main__':
main()
main()
\ No newline at end of file
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment