BLE data transfer.... baffling

Hello all

I want to use an ESP32 and in particular its Bluetooth ability to transfer some basic data (as is a few variables) over to my phone.

I intend to write a simple app in MIT App inventor that I have used before.

But... the examples for ESP32 BLE in the IDE are pretty much useless.
There is zero explanation of how they work. Really vibrates my colon when you get examples that unless you are some brain swollen tech head, you basically can't work out.

The BLE code seems to be full of specific commands, but yet to find anywhere that explains what they do.
I did find a tutorial for sending data between to ESP32's, and that is what I am tinkering with, but basically he just says 'don't touch this bit' whenever there is a complicated bit.

Any pointers to a more intuitive tutorial?

If you go to the GitHub page of the BLE library, you'll find documentation for each of the functions called by the code. The BLE library is kind of big and complex, so it may take a while to find the function you're looking for. It gets easier after a while when you get accustomed to how code is usually structured.

For instance, if I open the "BLE_scan.ino" example and I go to line #25, I find a call to "BLE::getScan();" If I want to know what that does or how it's supposed to work, I go to the GitHub of the BLE library, specifically the file BLEDevice.cpp which contains the definitions of all the functions in the BLEDevice class. Using the search function, I can find on line 307 that this function invokes the constructor of the BLEScan class and returns a reference to the newly created object.

As I said, the BLE library is a fairly complicated one and you'll find yourself navigating from one class to another a lot of the time trying to figure out how things work. After a while, you start to get the hang of it. I'd recommend practicing this first on much simpler libraries to learn the basic principles of C++ code structure.

I understand your frustration, but remember that there are valid reasons why seasoned C++ programmers are fairly well-paid and generally well-educated. It's a profession and this specialism comes from extensive training and a certain dose of talent/intelligence. There's no quick substitute for those; like many of the rewarding things in life, it takes an investment in order to reap the benefits.

1 Like

Thanks... I'll look at that.

I appreciate these people who write these libraries for us minions to use.... I just wish they would remember that we are not anywhere near their level and a few explanatory comments would go a long way!

Looks like another one of those 'quick' projects that is now going to eat up a weeks worth of evenings!

I am trying this on an ESP32 Devkit 1. What is the reason for the IDE taking about 2 years to upload code to any ESP32? On average it's about 90 seconds which is an eternity if you are changing code and re-uploading every few minutes.

It doesn't do it on any other processors

The web hosts a number of extensive guides on this complex topic.

Take the time to do your homework, and plan on days or weeks of study to understand the material.

Because it tends to re-compile most/all of the code when uploading. I think this improved in the later board definitions. For me this was a reason to give PlatformIO a try, because it was more efficient in tracking changes and only recompiles what has changed (however, P_IO has other drawbacks). You'll find that some 'boards' compile slow like this; it depends in part on the complexity of the board definitions.

It's annoying, I know. It's been a while I did anything ESP32 within the Arduino environment; it may help to use IDE2.0 if you're not doing so already, and ensure the ESP32 board definitions are kept up to date. As I recall the situation used to be even worse in the past.

I tried PlatformIO and didn't get on with it. I might re-visit, but I found it too complicated for my tiny brain

I can relate, I also ended up moving away from Platform_IO. I found the way it deals with includes too complicated, requiring lots of manual intervention in excluding incompatible libraries. But it did compile nice and fast for ESP32.

Arduino is very user-friendly and a relatively easy way of getting into microcontroller programming, but there's a price we pay for this from time to time.

I have been making electronic 'stuff' for 30 years.... I know how long it takes!

I got the ESP32 up and running with the BLE. It didn't actually 'work' for some reason, but I could connect it to my phone. I am sure the fix was easy.

BUT... the short little demo code that I altered used up 89% of the Flash. So totally useless to me anyway, as there is no space left for my coding. Obviously the BLE library is pretty hefty.

So. Stuck here again. My current idea is a 32kb flash ATtiny + HC-06. I was trying to keep the footprint small, but that hasn't happened so far.

Teensy 3.2 would have been ideal, but they have gone away and the 4.1 is too big.

Pro-minis etc don't have enough analogue pins for my requirements (I need 10).

That is the other thing that is useless on the ESP32. Enable WiFi (which would have been better than BLE) and 9 analogue pins go away, because WiFi clashes with bank 2 analogue pins (apparently).

OK. Just found nimBLE library. The 'NimBLE_Service_Data_Advertiser Demo' example works and uses 43% of flash.
I'll have a go with that

Again, I can relate. On a related note, I was messing with a small STM32 microcontroller a few weeks ago, trying to create a device based on it using STM32Duino. Very simple - PWM a couple of LEDs, read some buttons, give some output to a small 0.96" OLED and get some input from a single I2C sensor.

Only lighting up a few PWM-ed LEDs and reading the I2C sensor already consumed all of the memory in the microcontroller...absolutely useless. I switched to SM32Cube, skipped the HAL stuff and wrote my own I2C stack etc. In the end, the entire application fits in about 60% of the flash memory, with all the necessary bells & whistles.

Like I said earlier, we pay a price for the user-friendliness and portability of Arduino.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.