BLE script- parts work

This code has worked correctly once.
There is a service with a characteristic.
The service shows appears without the characteristic.

In the BLE scanner, 'Long name works now" shows up. That’s the BLE serverr.

You can see the service UUID.
Then you see the characteristic ID, but “Hello world” does not appear anywhere.

"Starting BLE work: and “Characteristic defined…” are in the serial monitor.:

It worked once.

    Based on Neil Kolban example for IDF:
    Ported to Arduino ESP32 by Evandro Copercini
    updates by chegewara
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

// See the following for generating UUIDs:

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

void setup()
  Serial.println("Starting BLE work!");

  BLEDevice::init("Long name works now");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
      BLECharacteristic::PROPERTY_READ |

  pCharacteristic->setValue("Hello World says Neil");
  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
  Serial.println("Characteristic defined! Now you can read it in your phone!");

void loop()
  // put your main code here, to run repeatedly:

This is reported in the ‘read values’ section:

It’s on the internet. Others have generated that ‘number’.

This is where “Hello world” should be.

Congratulations. Your code is working.

0x48656c6c6f20576f726c642073617973204e65696c is the hexadecimal representation of “Hello World says Neil”.

1 Like

This is a particularly good BLE/ESP32 tutorial:

1 Like

I knew it. I tried to Google a conversion. People have searched that UUID before, and it appears in various forums.

I’d rather have the western script. I’m using LightBlue. It seems to provide more than nRF.

I’m going to merge this BLE stuff with my BME680 today and make a central to display BME data on OLED. Hopefully not hex…

Since the scanner sketch on the page seems to show whatever you pushed via pCharacteristic->setValue() via the

Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());

line, it would seem that the data should actually be a character string? Looking at the app you are using, LightBlue, it seems it defaults to hex, but you can go into the settings for any of the data values (use the arrow on the right side of the atribute) and change it to UTF-8 String, Binary, etc.

I copied and pasted the sketch you gave above, used the following platformio.ini

platform = espressif32
board = wemos_d1_mini32
framework = arduino
lib_deps = ESP32 BLE Arduino

and tried it on a Wemos D1 Mini form-factor ESP32. After changing the data format to ‘UTF-8 String’ (from the default of Hex) I got the following in LightBlue …

So it looks like it works perfectly out of the box. :slight_smile: Yay… first attempt at anything BLE just worked thanks to the great work done by Neil & co…

1 Like


I really appreciate this.
I knew it was rewritten in HEX, but I couldn’t confirm it. Manuel confirmed it, but it still wasn’t a thing I could use.

Now I have a central problem. This working script is sending the advertisement as seen above, and the central seems to be getting it, but the serial output is gibberish with characters mixed in. The characters aren’t among the serial prints.

When I get back to it, I’ll try to display the incoming on OLED, see if it’s just a serial issue.

Beacon works. Central reader doesn’t.
After the voyeuristic central works, I’ll connect two devices. That’s the goal. I want two thing to work together.

So the real goal is to find a block of drop-in text to add Bluetooth.

I didn’t see that format thing. This is awesome. And it means I got to waste a lot of time!

Win win

I answered that in another thread, did you not see it?


Ah. RIght. I saw that. I put the Central on ice while I make my functioning peripheral advertising script send temperature data from the sensor.

I will add the speed instruction to .ini.