Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GATT Server example request #8

Open
hbraasch opened this issue Aug 13, 2020 · 21 comments
Open

GATT Server example request #8

hbraasch opened this issue Aug 13, 2020 · 21 comments

Comments

@hbraasch
Copy link

Not an issue but a example request.

Would it be possible to give us an example on how to do a simple GATT server using this library? I've tried to match up some Python based D-Bus examples with what your library provides, but could not make any sense.

In the end I'd like to have some Xamarin app access data on a PI via BLE.

It shall be much appreciated.

@ramiss
Copy link

ramiss commented Aug 16, 2020

I'm looking for the same info please. I want the RPi to be discoverable as a serial port service.

@Parsakarami
Copy link

Hi, Chris.

First of all, Thank you for your library. It seems useful and great.
I want to know how can I create a GATT server and advertise it using D-Bus on Raspberry Pi?
I have seen multiple examples that have been written in Python but I couldn`t match those and use them in .Net core.

@hbraasch
Copy link
Author

I recently came across this sample code, it works very well. Its a simple generic GATT server implemented for Linux in C#/.Net, using D-Bus and Tmds.Dbus.

https://github.com/phylomeno/dotnet-ble-server

Do not use the provided Nuget, just add all the DotnetBleServer code to your project and see the examples provided for guidance

I compiled it for .Net Core 3.1 and it works fine

@scegg
Copy link

scegg commented Nov 5, 2020

I recently came across this sample code, it works very well. Its a simple generic GATT server implemented for Linux in C#/.Net, using D-Bus and Tmds.Dbus.

https://github.com/phylomeno/dotnet-ble-server

Do not use the provided Nuget, just add all the DotnetBleServer code to your project and see the examples provided for guidance

I compiled it for .Net Core 3.1 and it works fine

Thanks for your info. But it cannot work here.
Hello Bluetooth
advertisement object /org/bluez/example/advertisement0 created
Unhandled exception. System.AggregateException: One or more errors occurred. (org.freedesktop.DBus.Error.UnknownMethod: Method "RegisterAdvertisement" with signature "oa{sv}" on interface "org.bluez.LEAdvertisingManager1" doesn't exist

How you pass this exception?
Thanks.

@hbraasch
Copy link
Author

hbraasch commented Nov 5, 2020

Are you running it from the source code (as I mentioned above), not the Nuget library? The Nuget version (I think) is an older version than the source.

@scegg
Copy link

scegg commented Nov 6, 2020

Are you running it from the source code (as I mentioned above), not the Nuget library? The Nuget version (I think) is an older version than the source.

Thanks for your reply.

I use the code from the github directly. Only reference in the example is the main project, which is a project code reference. And the only nuget package used by the main project is tmds.dbus. I've created an issue there. Would you like to check it and upload your running code? Thanks again.

phylomeno/dotnet-ble-server#5

@hbraasch
Copy link
Author

hbraasch commented Nov 6, 2020

I have attached the code I'm using to create my GATT server. Hope it helps. Please ignore some the app specific code not removed.

GattServerCodeExample.txt
.

@scegg
Copy link

scegg commented Nov 6, 2020

I have attached the code I'm using to create my GATT server. Hope it helps. Please ignore some the app specific code not removed.

GattServerCodeExample.txt
.

In your code, required AddCharacteristic is missing from GattServiceBuilder. Should I use WithCharacteristic instead?

After running StartServer().Wait() from your code with the changing above, messages printed on screen:
"advertisement object /org/bluez/example/advertisement0 created"

That's all. Nothing detected from my LightBlue app. Didn't see "GattServer successfully started", nor error message.

@hbraasch
Copy link
Author

Not sure what you mean by "In your code, required AddCharacteristic is missing from GattServiceBuilder"?

My code in RegisterGattApplication(..) :
var gab = new GattApplicationBuilder();
var gsp = gab.AddService(gattServiceDescription);
gsp.AddCharacteristic(commandCharacteristicDescription, new[] { commandDescriptorDescription });

@scegg
Copy link

scegg commented Nov 12, 2020

Not sure what you mean by "In your code, required AddCharacteristic is missing from GattServiceBuilder"?

My code in RegisterGattApplication(..) :
var gab = new GattApplicationBuilder();
var gsp = gab.AddService(gattServiceDescription);
gsp.AddCharacteristic(commandCharacteristicDescription, new[] { commandDescriptorDescription });

AddCharacteristic is not shipped with the original code (GattServiceBuilder).

@hbraasch
Copy link
Author

Sorry, you're so right! I completely forgot. I did add a function to GattServiceBuilder (even marked it) which simply encapsulates ||WithCharacteristic||:

// Added by HRB
public void AddCharacteristic(GattCharacteristicDescription gattCharacteristicDescription,
GattDescriptorDescription[] gattDescriptorDescriptions)
{
WithCharacteristic(gattCharacteristicDescription, gattDescriptorDescriptions);
}
As far as I can see I did not do any other modifications to the code.

Insofar not seeing "GattServer successfully started"... Can you maybe debug into ||RegisterGattApplication|| to see which instruction hangs?

@scegg
Copy link

scegg commented Nov 13, 2020

RegisterGattApplication

It hangs at:
await GetAdvertisingManager().RegisterAdvertisementAsync(((IDBusObject) advertisement).ObjectPath,
new Dictionary<string, object>());
from AdvertisingManager.RegisterAdvertisement
from Advertisement.RegisterAdvertisement
from StartServer

@hbraasch
Copy link
Author

hbraasch commented Nov 14, 2020

Might sound like a stupid question but: Are you running it on PI 3 or 4, or other?

@scegg
Copy link

scegg commented Nov 14, 2020

Might sound like a stupid question but: Are you running it on PI 3 or 4, or other?

Last test is on my computer with Ubuntu server x64.

The test before is on my RPI4 with Ubuntu server arm64.

@hbraasch
Copy link
Author

I'm for now running it on Pi3, because I had problems with BLE on Pi4 (but its been a while and for the life of me I cannot remember why I temporarily gave up on the Pi4). Long shot but just give it a try on PI3?

@ArthurKun21
Copy link

Hi have you solved this problem?

@scegg
Copy link

scegg commented Apr 21, 2021

Hi have you solved this problem?

Who're you asking...?

But I don't think there is anyone solved this yet.

@ArthurKun21
Copy link

Might sound like a stupid question but: Are you running it on PI 3 or 4, or other?

Last test is on my computer with Ubuntu server x64.

The test before is on my RPI4 with Ubuntu server arm64.

this one in the ubuntu server. I was running it on my Vmware with ubuntu installed. I was using other library - python-bluezero but got the same error as yours

org.freedesktop.DBus.Error.UnknownMethod: Method "RegisterAdvertisement" with signature "oa{sv}" on interface "org.bluez.LEAdvertisingManager1" doesn't exist

@hbraasch
Copy link
Author

Ok!! Could be th OS'es. I've got it working it on Raspbian

@scegg
Copy link

scegg commented Apr 25, 2021

I'm for now running it on Pi3, because I had problems with BLE on Pi4 (but its been a while and for the life of me I cannot remember why I temporarily gave up on the Pi4). Long shot but just give it a try on PI3?

I found the reason why I cannot use BLE on my Pi4.
I'm using Ubuntu arm64 20.04, not Pi OS. A lib installation is required:
sudo apt install pi-bluetooth then
sudo nano /boot/firmware/usercfg.txt add include btcfg.txt to the end.
and sudo reboot.

Before testing code, make sure that bluetooth device can be listed by hciconfig -a.

@Caffiendish
Copy link

Caffiendish commented Dec 12, 2021

I had some issues getting BLE servers to work on my Raspberry Pi as well, so I forked CirrusResearch's notification branch (big thanks to them!), and made a couple of commented examples that should hopefully help other people:
https://github.com/Caffiendish/dotnet-ble-server/tree/Notifications

I've got a couple of issues to work out though, namely how "write (with response)" actually works, since my Windows machine as a client doesn't put "request" in the options. Or "command", for a "write-without-response".

If you have a client that does add options, you'll (as I understand it!) find them in the dictionary here:
https://github.com/Caffiendish/dotnet-ble-server/blob/Notifications/DotnetBleServer/Gatt/BlueZModel/GattCharacteristic.cs#L29

My Windows client just does what seems to be the basic stuff, "link", "device", "mtu".
I have devices that respond, but do so with notifications, so I'm kind of assuming that's how replies work.

Edit:
I forgot to mention, I'm using a Raspberry Pi Zero W, on the most current Raspberry OS, with whatever Mono version apt install got me 😄 and compiling my executable with DotNet 4.7.2 (Mono supports Net Core 2.0, so the library works).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants