I am finally sending BLE data but I cannot convert it!

Greetings, All

I have a functioning Arduino IDE sketch using an ESP32C3 and a BME280. When I start the sketch, it is waiting for a start signal or handshake. I am using nRF Connect to initiate the process. When I press “Connect” in nRF Connect, the sketch comes to life, printing the temperature, humidity, and atmospheric pressure to the serial interface. It quickly connects to my nRF Connect but I am unable to decode the data. I have tried “Hex,” “Signed Integer,”, “Unsigned Integer,” etc to no avail. The numbers I get on my nRF Connect readout do not correlate to the data.

I am including my .ino sketch and screenshots from nRF Connect. I circled the data outputs in red. If someone could tell me why I am not seeing the data I expect (temp, humidity, pressure) in nRF Connect, I would really appreciate it. I have been spinning my wheels on this for a week but I have to defer to the community on this one. Thank you.

#include <ArduinoBLE.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BLE_NAME "Psychrometer"
#define SERVICE_UUID "19B10000-E8F2-537E-4F6C-D104768A1214"
#define TEMPERATURE_UUID "19B10001-E8F2-537E-4F6C-D104768A1214"
#define HUMIDITY_UUID "19B10002-E8F2-537E-4F6C-D104768A1214"
#define PRESSURE_UUID "19B10003-E8F2-537E-4F6C-D104768A1214"

// Create BME280 sensor object
Adafruit_BME280 bme;

BLEService bmeService(SERVICE_UUID);
BLEFloatCharacteristic temperatureCharacteristic(TEMPERATURE_UUID, BLERead | BLENotify);
BLEFloatCharacteristic humidityCharacteristic(HUMIDITY_UUID, BLERead | BLENotify);
BLEFloatCharacteristic pressureCharacteristic(PRESSURE_UUID, BLERead | BLENotify);

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!BLE.begin()) {
    Serial.println("Failed to start BLE!");
    while (1);
  }

  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  BLE.setLocalName(BLE_NAME);
  BLE.setAdvertisedService(bmeService);

  bmeService.addCharacteristic(temperatureCharacteristic);
  bmeService.addCharacteristic(humidityCharacteristic);
  bmeService.addCharacteristic(pressureCharacteristic);

  BLE.addService(bmeService);

  temperatureCharacteristic.writeValue(0);
  humidityCharacteristic.writeValue(0);
  pressureCharacteristic.writeValue(0);

  BLE.advertise();

  Serial.println("BLE peripheral is now active");
}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Connected to central: ");
    Serial.println(central.address());

    while (central.connected()) {
      // Read actual sensor values
      float temperature = bme.readTemperature();
      float humidity = bme.readHumidity();
      float pressure = bme.readPressure() / 100.0; // Convert Pa to hPa

      Serial.print("Temperature: ");
      Serial.print(temperature);
      Serial.println(" °C");

      Serial.print("Humidity: ");
      Serial.print(humidity);
      Serial.println(" %");

      Serial.print("Pressure: ");
      Serial.print(pressure);
      Serial.println(" hPa");

      temperatureCharacteristic.writeValue(temperature);
      humidityCharacteristic.writeValue(humidity);
      pressureCharacteristic.writeValue(pressure);

      delay(1000);
    }

    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }
}


It’s not particularly code related, it’s a data display issue with the app. Sorry, I can’t quite remember where the settings are, it is possible to set what format it is displayed in on the APP.

1 Like

Actually, that was the first thing I tried. It is the data parser selection with multiple choices. Of all of the conversion choices, I could select from Hex, signed integer, and unsigned integer. All the other choices were grayed-out and could not be selected.

im hoping to experiment with this … but have not had time yet

No worries, it is past my bedtime;). I appreciate your interest. I know that when I use the 6-bit shortcut 0x181A and call forth from the sub-array of 6-bit content, I can read the temperature, pressure, and humidity and the associated strings, although I did have to select “unsigned integer” in the parser. My issue is that I want to send far more specific data than that sub-group has titles for.

Hi there,
my .02 , All the examples I have ever seen , Convert it prior to sending, AFAIK.
Floats to XX
that way the receiver just reads it as ascii or Hex string.
HTH
GL :slight_smile: PJ
:v:

Would you be so kind as to provide a brief example of what converting in the sketch would look like? I tried this:

temperature = (temperature, HEX);

but nothing good came from it. Ultimately, I want this data to be readable by a .ala file (MIT App Inventor) so I am not really concerned about nRF Connect being able to read the data unless being able to do so in nRF Connect is a necessary precondition to broadcasting meaningful data to the .ala.