-2

This is my first time trying out to code on C# or VisualStudio. Sorry if I am too much of a newbie.

I have a raspberry pi zero setup as a BLE GATT server, which I followed exactly with this guide.

My ultimate goal is just trying to send a text from the pi zero to my laptop.

Being a little familiar with python, I have tried to use Bleak to communicate with the GATT server but for some reason, I'm never able to connect to the GATT server. So I gave up trying to tinker with Bleak.

( Please note that I have used nRF Toolbox to verify that the pi zero BLE GATT server is set up correctly )

Fast foward, one day I saw this BLE GATT Client Sample from Microsoft. So I downloaded VisualStudio and followed the guide to deploy the sample.

Everything worked fine, I can connect to the GATT server and write data to the specific RX characteristics.

But the real problem resides on the TX characteristics, when I try to send data from the GATT server console to the laptop. The BLE Client Sample will show the value as "Unknown Format"

It seems that the data will be encoded ( value.append(dbus.Byte(c.encode())) ) with this before updating the TX charactersitics.

s

I tried to Google about this, but any further research will only make my head burn harder.

I'm sorry, can anyone tell me how to fix this "Unknown Format" data decode problem?

Thanks so much in advance.

  • Seems like the value is read in the `FormatValueByPresentation` method inside [this class](https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/BluetoothLE/cs/Scenario2_Client.xaml.cs). You could use the Debugger to step through it to find out what exactly is wrong. It also says that it only supports UInt32 and UTF-8 decoding. – adjan Aug 28 '20 at 21:53
  • 1
    @ukBaz Sweet! Thank you very much, I followed the guide you have given me and I think that `UTF8.GetString` thingy fixed it! Thank you very much!!! I don't know why people downvote me tho, this is my first time coding C#. Can you submit an answer so I can mark yours? – Just some sailboat Aug 29 '20 at 07:49

1 Answers1

1

On the server (RPi) you have:

UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' as 'notify'

UART_RX_CHARACTERISTIC_UUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' is 'write'

This means on the client (PC) you need 0003 to be 'write' and 0002 to be 'notify'.

You say the problem is when the server does a write to 0002 you are get unknown format?

BLE will always send the data as a byte array, I suspect you need to do something like this previous answer on the client for the data you receive

ukBaz
  • 6,985
  • 2
  • 8
  • 31