/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
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:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
void setup()
{
Serial.begin(9600);
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(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristic->setValue("Hello World says Neil");
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Characteristic defined! Now you can read it in your phone!");
}
void loop()
{
// put your main code here, to run repeatedly:
delay(2000);
}
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.
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 …
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!