BLE Client for Windows 10

BrianP
Posts: 53
Joined: Mon Apr 13, 2020 1:48 pm

BLE Client for Windows 10

Postby BrianP » Mon Aug 16, 2021 2:51 pm

I have managed to write a BLE client for Windows 10 console example. It allows you to exchange data with a device running the ESP32 ble_spp_server example. I believe with modification (changing the UUIDs and devices names) it would likely be useable for other BLE devices as well. Since it is a console application it is easily portable to Windows GUI.

This might be useful for debugging BLE projects or as a core for working with BLE on Windows. A more detailed commentary and a link to the repository is here https://documenteddesigns.com/2021/08/1 ... indows-10/

The demo is written for Microsoft Visual Studio 19 because it needs the CppWinRT library and it is pretty simple to set up MVS for that.

As a summary I am working with the ESP32-C3 and while Espressif provides all sort of sample code the ESP32-C3 is not yet well supported. I can’t get the BLC examples to compile for ESP32-C3 and the BLE samples which do compile are ble_spp_server and ble_spp_client, which are meant to talk to each other. My current project requires 2 ESP32-C3s, GPS, and LORA, with one of the ESP32-C3s acting as a gateway to an Android device. For battery reasons it made a lot more sense to connect to Android using BLE instead of WiFi.

I know I am not a particularly competent c++ programmer, and in particular I know next to nothing about Windows API programming. Therefore I am sure this is not an example of how things should be done, but it works and should be useful as a starter, especially since there are so few working examples around.

Known Problems and Limitations:

1) I haven’t figured out how to re-attach a BLE device if connection is lost. You need to re-start the code. Since this is intended for debugging purposes it should not be a problem;

2) If you stop and then restart the client quickly, it appears the server (ESP32-C3) still thinks there is a connection and the client won’t connect. Usually it figures it out after a while but if it doesn’t, restart the ESP32 and the client.

I would be delighted if anybody could help me solve these problems, especially the first one, because I think it is related to the second.

The software currently supports only a single BLE device, one read and one write UUID (see below). It should be easy to expand this to multiple BLE devices and/or multiple read or write UUIDs, however that was not my requirement.

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Client for Windows 10

Postby chegewara » Thu Aug 19, 2021 4:51 pm

1) after disconnect you have to start advertising on esp32 C3 and to start scan in windows app
2) ble connection has timeout parameter, which may be long enough to let you close and re-open app before disconnect happen due to timeout; this is also issue with app, because you should disconnect from esp32 before you kill app

BrianP
Posts: 53
Joined: Mon Apr 13, 2020 1:48 pm

Re: BLE Client for Windows 10

Postby BrianP » Thu Aug 19, 2021 4:54 pm

Thanks for the reply!

I'm assembling my hardware at the moment and as soon as I do I'll try and adjust the parameters.

Who is online

Users browsing this forum: No registered users and 103 guests