Live data from Hacker News

Building a GATT Server on Pi Pico W

vanhunteradams.com

11–18 of 18 posts

Re: Building a GATT Server on Pi Pico W

#11
It’s not a full generic GATT server but I implemented a server for temperature sensors with MicroPython if anyone is curious what that looks like. I have it running on two picos to collect data across my house and then I push it to a MQTT server. Honestly would love feedback too because it’s pretty gross and error prone.

https://git.tcrez.dev/tcrez/micropython/src/branch/main/temp...

Re: Building a GATT Server on Pi Pico W

#12

When I last look at the description of the Pi Pico W from adafruit https://www.adafruit.com/product/5544 it says: "Bluetooth Low Energy - note this isn't supported in software yet, its just a hardware capability." Yet this blog discusses BTStack so it must work at some level ... Can anyone clarify: if you want to use BLE on this device, is BTStack the only option or is this outdated info?

It was enabled in mid 2023: https://www.raspberrypi.com/news/new-functionality-bluetooth...

Re: Building a GATT Server on Pi Pico W

#13
post #9

I'm trying to understand what GATT is. From what I've found in the links below, it looks Bluetooth 5.4 spec contains an Attribute Protocol (ATT) that allows for sharing of custom attributes between bluetooth devices. Attributes have a type identified by UUID, a server-specific 16-bit handle, a higher-level handle group, a value, and then permissions. Permissions specify read/write capability and requirements for encr…

GATT, at the lowest level, is a spec that allows you to access what is substantially a key-value store over bluetooth. It was part of the 4.0 spec. Keys are 16-bit "handles", values are arbitrary byte bags. Handles may change between connections and are not considered stable, which is why there is a higher level of abstraction used. Each K-V pair is called an attribute. On top of that simple kv-store, are built highe…

I had a play with BLE a few years ago but found the entry point too high to get started with - do you know of any high-level introductions to the terminology and concepts (possibly illustrated or animated, as that seems make the data flows easier to grasp)?

Re: Building a GATT Server on Pi Pico W

#14
post #9

Earlier quoted context omitted.

GATT, at the lowest level, is a spec that allows you to access what is substantially a key-value store over bluetooth. It was part of the 4.0 spec. Keys are 16-bit "handles", values are arbitrary byte bags. Handles may change between connections and are not considered stable, which is why there is a higher level of abstraction used. Each K-V pair is called an attribute. On top of that simple kv-store, are built highe…

I had a play with BLE a few years ago but found the entry point too high to get started with - do you know of any high-level introductions to the terminology and concepts (possibly illustrated or animated, as that seems make the data flows easier to grasp)?

the BT 4.0 (not later) spec chapter on GATT is relatively understandable.

Re: Building a GATT Server on Pi Pico W

#15

I'm trying to understand what GATT is. From what I've found in the links below, it looks Bluetooth 5.4 spec contains an Attribute Protocol (ATT) that allows for sharing of custom attributes between bluetooth devices. Attributes have a type identified by UUID, a server-specific 16-bit handle, a higher-level handle group, a value, and then permissions. Permissions specify read/write capability and requirements for encr…

Adafruit has an overview:

https://learn.adafruit.com/introduction-to-bluetooth-low-ene...

Re: Building a GATT Server on Pi Pico W

#16

I'm trying to understand what GATT is. From what I've found in the links below, it looks Bluetooth 5.4 spec contains an Attribute Protocol (ATT) that allows for sharing of custom attributes between bluetooth devices. Attributes have a type identified by UUID, a server-specific 16-bit handle, a higher-level handle group, a value, and then permissions. Permissions specify read/write capability and requirements for encr…

Just a BLE jargon that roughly equates to UDP/IP.

Re: Building a GATT Server on Pi Pico W

#17
GATT is great if you want to make yet another heart rate monitor. I was building a lock that worked over BTLE and I spent most of my time trying to get around the problems with GATT. It's been 8 years now but I believe that that there was a bunch of extra overhead that bloated the packets and the packets were too small. Resulted in too much back and forth etc. I really just wanted a socket. iOS eventually allowed you to interact directly with the Logical Link Control and Adaptation Protocol aka L2CAP. Seems like every time someone try to design a generic structure that does one job but is also extendable, it's a mess. Just give me the byte stream and move on. L2CAP doesn't seem to be accessible on the pico yet, https://github.com/micropython/micropython-lib/issues/803

Re: Building a GATT Server on Pi Pico W

#18

I'm trying to understand what GATT is. From what I've found in the links below, it looks Bluetooth 5.4 spec contains an Attribute Protocol (ATT) that allows for sharing of custom attributes between bluetooth devices. Attributes have a type identified by UUID, a server-specific 16-bit handle, a higher-level handle group, a value, and then permissions. Permissions specify read/write capability and requirements for encr…

I spent a good part of a year working specifically with the Bluetooth GATT spec designing my own client and servers which would try to function as close to the spec as possible. The spec is very bad, I'm sorry but I understand the amount of effort that must have gone into building it. There are blatant holes in the entire spec, documents are broken apart in some chaotic pattern where to implement a single ATT you nee…

> Worst part is, a lot of device manufacturers just yeet the GATT out the window and have custom UUIDs with custom everything which you'll never be able to implement properly with reverse engineering it.

Sorry, I’m part of the problem. ^_^; If you read the BLE Developers Handbook, it paints a beautiful picture of a mesh of low power sensor devices that periodically advertise information, and it helped put the design of GATT into context for me. Of course, we had no interest in using GATT in that manner - we just wanted the other features of BLE. One fundamental issue is that if you want E2E transport encryption to a specific mobile app, LE bonding is no longer sufficient. So you start rolling your own crypto only to realize that negotiated MTU means your max datagram size is variable and dynamic. From there, you’re well on your way to implementing a custom transport layer on top of GATT. If you don’t horribly abuse GATT and use it for its intended purpose (like some of the standardized profiles on top of GATT), it works fairly decently.

Post reply on HN