toit icon indicating copy to clipboard operation
toit copied to clipboard

Add support for BLE server

Open justind000 opened this issue 3 years ago • 7 comments

Just writing to see if a BLE server implementation is being worked on. Specifically, what I'd like to see is turning the ESP32 into a server that other devices connect to, that creates characteristics and updates their values.

I have taken a look through ble.toit and it looks like some of the primitives are already there.

  • [x] Device
  • [x] Characteristic
  • [ ] Security
  • [ ] Server
  • [ ] Service

Toit is using the NimBLE implementation, if I'm looking at this correctly?

justind000 avatar Nov 26 '21 15:11 justind000

Yes, you're right. We are using NimBLE. We are not actively working on adding the last parts of the BLE implementation right now (as in the coming week), but we'd love to explore this with you.

For reference, the resources/ble_esp32.cc and event_sources/ble_esp32.cc files contain the implementation of the primitives used by ble.toit.

kasperl avatar Nov 27 '21 06:11 kasperl

I've taken the liberty of turning your question into a feature request :)

kasperl avatar Nov 27 '21 06:11 kasperl

I'm interested in the platform and am currently writing a few I2C drivers to get familiar with it.

A BLE server isn't on my short list either, but I have found it very useful to have for provisioning and interacting with the device through an app (web BLE maybe since you are already using web serial).

If I start playing around with it and make some progress, I will get in touch here.

justind000 avatar Nov 27 '21 06:11 justind000

Thanks, @justind000!

kasperl avatar Nov 27 '21 10:11 kasperl

I am currently giving the ble server/peripheral some attention. The idea is to let the user build a service descriptor with toit objects to be passed to the server constructor. The library would then enable advertising the services. It will contain some sensible defaults for attribute types and allow callbacks to executed in user code when an attribute is written to, enable reading an attribute and provide a default mechanism to handle notifications.

mikkeldamsgaard avatar Jan 28 '22 07:01 mikkeldamsgaard

Mikkel's work just landed. Please take a look, @justind000!

kasperl avatar Feb 28 '22 19:02 kasperl

With a good chunk of help from @mikkeldamsgaard, the BLE implementation is in a much better shape now. Do you know what we're still missing, @justind000?

kasperl avatar Aug 20 '22 06:08 kasperl

How is this looking by now, @mikkeldamsgaard?

kasperl avatar Nov 23 '22 07:11 kasperl

Still missing security. The rest is done.

mikkeldamsgaard avatar Nov 24 '22 10:11 mikkeldamsgaard

Security finally added in https://github.com/toitlang/toit/pull/1470. @kasperl please update when approved.

mikkeldamsgaard avatar Mar 07 '23 19:03 mikkeldamsgaard