setValue alternative

Dear supporters,

I am working with BLE on ESP32 and I am triing to find some alternative for setValue.

setValue function is for analog data and I am working with digital data.

Can someone please advise me what kind of funcion can I use.

Thank you so much.

DB_ezer

Please post the full program that you are having a problem with.

The setValue function means nothing unless it is seen in context

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

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

HardwareSerial hwSerial_1(1);

bool deviceConnected = false;

BLECharacteristic *UARTCharacteristic;

class MyServerCallbacks: public BLEServerCallbacks
{
void onConnect(BLEServer* pServer)
{
deviceConnected = true;
};

void onDisconnect(BLEServer* pServer)
{
deviceConnected = false;

}
};

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

BLEDevice::init("BLE");

BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());

BLEService *pService = pServer->createService(SERVICE_UUID);

UARTCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_NOTIFY
);

UARTCharacteristic->addDescriptor(new BLE2902());

pService->start();

pServer->getAdvertising()->start();

Serial.println("Characteristic defined! Now you can read it in your phone!");

hwSerial_1.begin(9600, SERIAL_8N1, RX1, TX1);

}

void loop() {
while (hwSerial_1.available()) {

float c = hwSerial_1.read();
Serial.println(c);
if (deviceConnected) {

UARTCharacteristic->setValue(c);
UARTCharacteristic->notify();

}
}
}

How did I know that you would not Auto format your code and post it here in code tags as described in Read this before posting a programming question

For the benefit of others here is the code posted in the suggested manner

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

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

HardwareSerial hwSerial_1(1);

bool deviceConnected = false;

BLECharacteristic *UARTCharacteristic;

class MyServerCallbacks: public BLEServerCallbacks
{
    void onConnect(BLEServer* pServer)
    {
      deviceConnected = true;
    };

    void onDisconnect(BLEServer* pServer)
    {
      deviceConnected = false;
    }
};

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting BLE work!");
  BLEDevice::init("BLE");
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());
  BLEService *pService = pServer->createService(SERVICE_UUID);
  UARTCharacteristic = pService->createCharacteristic(
                         CHARACTERISTIC_UUID,
                         BLECharacteristic::PROPERTY_NOTIFY
                       );
  UARTCharacteristic->addDescriptor(new BLE2902());
  pService->start();
  pServer->getAdvertising()->start();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
  hwSerial_1.begin(9600, SERIAL_8N1, RX1, TX1);
}

void loop()
{
  while (hwSerial_1.available())
  {
    float c = hwSerial_1.read();
    Serial.println(c);
    if (deviceConnected)
    {
      UARTCharacteristic->setValue(c);
      UARTCharacteristic->notify();
    }
  }
}

Are you sure that

 float c = hwSerial_1.read();

reads a float and not just a single byte ?

I am sorry for wrong post.

You are right about reading bytes. I´ll try to fix it.

Thank you so much.

DB_ezer