Seeking example of "just works" for NimBLE

I'm using a Nano ESP32 with NimBLE. ESP32 is the server and an Android app is the client. I'd like to implement "just works" pairing to encrypt the transmission of a characteristic write. I've been unable to find a code example. I've tried a dozen different code permutations with no success.

Bonding is working.
MITM is set to false.
Secure Connections. I've tried enabled and disabled.

onAuthenticationComplete event is being called.

startSecurity. I've tried with and without it. When placed in onConnect, it returns true.

createCharacteristic. When it contains WRITE_ENC or READ_ENC, the Android client receives a ERROR_GATT_WRITE_NOT_ALLOWED.

Does anybody know of a working code example for this?

Hi @anon66902326 !

This is all I could find asking Chatgpt to search for examples:

📲 For a full end-to-end ESP32 NimBLE server + Android BLE client demo

There isn’t a single official repository combining:

ESP32 NimBLE server with encrypted (Just Works) characteristics and

A ready-to-compile Android Studio app

That said, combinations that are community-verified include:

🚀 ESP32 NimBLE (server) + Generic Android Client

Use:

ESP-IDF bleprph or NimBLE-Arduino server sketch (above).

Then test with a generic BLE app on your Android phone like nRF Connect or BLE Scanner.

Pair at Android level before accessing encrypted characteristics.

That sequence (ESP32 with Just Works security → pair on Android → encrypted write/read) is the easiest way to validate pairing works end-to-end.

📌 Summary of useful reference projects
Purpose	Link
ESP-IDF NimBLE peripheral example (with security config)	https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/nimble/bleprph

NimBLE-Arduino client example (shows security setup calls)	https://github.com/h2zero/NimBLE-Arduino/blob/master/examples/NimBLE_Client/NimBLE_Client.ino

Discussion showing Just Works security config	https://github.com/h2zero/NimBLE-Arduino/issues/588

If you’d like, I can show you exact modifications to the esp-idf bleprph example so that it explicitly implements a Just Works encrypted characteristic (e.g., a write that requires encryption) and how to trigger that from an Android BLE client.

Not sure if this really helps, but I hope it's a start ...

You can also try to ask Chatgpt to prepare a solution. My experience with this is quite different, sometimes it immediately creates working solutions, but in most cases it works like a young student: very keen to give quick answers, highly self confident but patient when confronted with its mistakes ;-) And it does not always succeed but sometimes it leads you to the right track.

Good luck!
ec2021

[Edit] As the ChatGPT output looks a little bit strange in code tags here the mos relevant links

SP-IDF NimBLE peripheral example (with security config)

NimBLE-Arduino client example (shows security setup calls)
https://github.com/h2zero/NimBLE-Arduino/blob/master/examples/NimBLE_Client/NimBLE_Client.ino

Discussion showing Just Works security config

Have you checked the Board examples and the Library examples? Since you didn't post source code in code tags as you are supposed to, I can't check the library examples for you. Good luck.

@anon66902326 :
Could you confirm that you are using this library?
https://github.com/h2zero/NimBLE-Arduino/tree/master

If not please post which lib you are using ... that may help forum members to identify how to support you!