Show BLE Input (ESP32C3) on a Label. Thats it

I am not realy interested in Apps, its just a small Park for a project, so learning Android Studio is not an Option, which lead me to NoCode Apps, but i can't get it done here either. I only found one tutorial on youtube, which lead me so far. (see below) I get everything connected and it looks fine, but how do i get my bytes into a float or what ever, to display it, as what it is: a Weight (Kg in my case).

Any help or direction? All tutorials i find seem to be outdated?

#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <BLE2901.h>
#include "HX711.h"

// Display
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define calibration_factor 21910.0

// HX711 Pins
#define LOADCELL_DOUT_PIN 3
#define LOADCELL_SCK_PIN 4

// BLE
BLEServer *pServer = NULL;
BLECharacteristic *pCharacteristic = NULL;
bool deviceConnected = false;
bool oldDeviceConnected = false;

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

// Display object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Weight-related variables
float highestValue = 0.0;
HX711 scale;

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

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

void setup() {
  Serial.begin(115200);

  // Initialize HX711
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(calibration_factor);
  scale.tare();

  // Initialize BLE
  BLEDevice::init("ESP32");
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

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

  pCharacteristic = pService->createCharacteristic(
    CHARACTERISTIC_UUID,
    BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY
  );

  pCharacteristic->addDescriptor(new BLE2902());
  pService->start();

  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(false);
  BLEDevice::startAdvertising();
  Serial.println("Waiting for a client to connect...");

  // Initialize Display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 not found!"));
    for (;;);
  }
  display.clearDisplay();
  display.setTextSize(2.5);
  display.setTextColor(SSD1306_WHITE);
}
void loop() {
  // Reading from the scale
  float currentValue = scale.get_units(1);
  if (currentValue > highestValue) {
    highestValue = currentValue;
  }

  // Display values
  display.clearDisplay();
 display.setCursor(70, 10);  // Textposition (x, y)
  display.print("Max:");

  // Aktuellen Wert anzeigen
  display.setCursor(70, 30);
  display.print(highestValue, 1);  // Zwei Nachkommastellen

  display.setCursor(0, 10);  // Textposition (x, y)
  display.print("Now:");

  // Aktuellen Wert anzeigen
  display.setCursor(0, 30);
  display.print(currentValue, 1);  // Zwei Nachkommastellen


  // Inhalt auf dem Display aktualisieren
  display.display();

  // Send the highest value via BLE
  if (deviceConnected) {
    pCharacteristic->setValue(highestValue);
    pCharacteristic->notify();
  }

  // Handle reconnection
  if (!deviceConnected && oldDeviceConnected) {
    delay(500);
    pServer->startAdvertising();
    oldDeviceConnected = deviceConnected;
  }

  // Handle new connection
  if (deviceConnected && !oldDeviceConnected) {
    oldDeviceConnected = deviceConnected;
  }

  delay(50);
}

https://i.ibb.co/MMwtGJP/mit.jpg

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

export_and_upload_aia

.

..

Help.aia (201.3 KB)

Currently going through the search results, but can't find anything usefull for me.
By this times, probably learning some basic coding would have been the easier way. :sweat_smile:

From your sketch, you are feeding a float directly to BLE without any text conversion.

But in your app, you Register for Strings
and try to treat the received data as text.


You have two options:

  • Find the sketch command to turn that float into text, and send the text, or
  • switch to Register for Floats and When BLE Floats Received on the app side.

Don't mix the two options.

i'll try "the switch to Register for Floats and When BLE Floats Received on the app side", it just might take me a few days :grin:

This works:

phew...there a lot to learn for me on the app side. Guess i'll dive into some tutorials during this winter. Thanks for you very valuable input, Stranger!