Unable to see the Temperature Service in the Lightblue App

Hello friends,
Apologies if this issue has been already answered. I am trying to test a sketch to display the Temperature and Humidity values using the Lightblue App in IOS and it seems whatever I do the temperature characteristic is not showing. Humidity is coming up with exactly identical code. I am using the nrf52840 BLE Sense Module. Any help will be greatly appreciated !

type or paste code here
``` * Connections:
 * ============
 *  DHT11       NRF52840
 *  --------    ---------
 *  GND          GND
 *  VCC          3.3V
 *  DATA         Pin 7           
 *-------------------------
 NOTE : If the COM port does not show up press the tiny RESET button Twice
*/
#include <ArduinoBLE.h>
#include <DHT.h>
#define DHTPIN D7      // Analog Pin sensor is connected to
#define DHTTYPE DHT11  // DHT 11
DHT dht(DHTPIN, DHTTYPE);

int temperature;
int humidity;
int oldtemperature = 0;
int oldhumidity = 0;

// Bluetooth® Low Energy Service
BLEService temperatureService("2A6E");
BLEService humService("2A6F");

// Bluetooth® Low Energy Battery Level Characteristic
BLEUnsignedCharCharacteristic temperatureChar("2800", BLERead | BLENotify);  // standard 16-bit characteristic UUID
BLEUnsignedCharCharacteristic humidityChar("2804", BLERead | BLENotify);     // standard 16-bit characteristic UUID
// remote clients will be able to get notifications if this characteristic changes

long previousMillis = 0;  // last time the dht value was checked, in ms


void setup() {
  Serial.begin(9600);  // initialize serial communication
  while (!Serial)
    ;

  pinMode(LED_BUILTIN, OUTPUT);  // initialize the built-in LED pin to indicate when a central is connected

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1)
      ;
  }

  BLE.setLocalName("DhtMonitor");
  BLE.setAdvertisedService(temperatureService);           // add the service UUID
  temperatureService.addCharacteristic(temperatureChar);  // add the temperature characteristic
  BLE.addService(temperatureService);                     // Add the temperature service
  temperatureChar.writeValue(oldtemperature);             // set initial value for this characteristic

  BLE.setAdvertisedService(humService);        // add the service UUID
  humService.addCharacteristic(humidityChar);  // add the humidity characteristic
  BLE.addService(humService);                  // Add the humidity service
  humidityChar.writeValue(oldhumidity);        // set initial value for this characteristic

  // start advertising
  BLE.advertise();

  Serial.println("Bluetooth® device active, waiting for connections...");
}


void loop() {
  // wait for a Bluetooth® Low Energy central
  BLEDevice central = BLE.central();

  // if a central is connected to the peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's BT address:
    Serial.println(central.address());
    // turn on the LED to indicate the connection:
    digitalWrite(LED_BUILTIN, LOW);  //The builtin LED turns on when LOW and viceversa

    while (central.connected()) {
      long currentMillis = millis();
      if (currentMillis - previousMillis >= 1000) {
        previousMillis = currentMillis;
        updatedht();
      }
    }
    // when the central disconnects, turn off the LED:
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  } else BLE.advertise();
}

void updatedht() {
  //DHT.read11(dht_pin);
  temperature = dht.readTemperature(true);
  humidity = dht.readHumidity();

  if ((temperature != oldtemperature) || (humidity != oldhumidity))  // if the dht value has changed
  {
    Serial.print("Temperature: ");  // print it
    Serial.print(temperature);
    Serial.println("*F");
    Serial.print("Humidity: ");  // print it
    Serial.print(humidity);
    Serial.println("%");

    temperatureChar.writeValue(temperature);  // and update the temperature
    oldtemperature = temperature;             // save the level for next comparison

    humidityChar.writeValue(humidity);  // and update the humidity
    oldhumidity = humidity;             // save the level for next comparison
  }
}
/*
 * Xiao nRF52840 Sense + DHT11 + BLE
 * BLE Environmental Sensing: Temperature + Humidity
 */

#include <ArduinoBLE.h>
#include <DHT.h>

#define DHTPIN D7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// BLE Environmental Sensing Service UUID
BLEService envService("181A");  // Environmental Sensing

// BLE Characteristics (standard 16-bit UUIDs)
BLEUnsignedCharCharacteristic temperatureChar("2A6E", BLERead | BLENotify);  // Temperature
BLEUnsignedCharCharacteristic humidityChar("2A6F", BLERead | BLENotify);     // Humidity

int oldTemperature = -1;
int oldHumidity = -1;
unsigned long previousMillis = 0;

void setup() {
  Serial.begin(9600);
  while (!Serial);  // Wait for Serial if connected

  dht.begin();

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

  BLE.setLocalName("DhtMonitor");
  BLE.setAdvertisedService(envService);  // Advertise the Environmental Sensing service

  // Add characteristics to the service
  envService.addCharacteristic(temperatureChar);
  envService.addCharacteristic(humidityChar);

  // Add service to BLE stack
  BLE.addService(envService);

  // Set initial values
  temperatureChar.writeValue(0);
  humidityChar.writeValue(0);

  BLE.advertise();

  Serial.println("BLE DHT11 Sensor Ready. Waiting for connections...");
}

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

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

    while (central.connected()) {
      unsigned long currentMillis = millis();
      if (currentMillis - previousMillis >= 2000) {
        previousMillis = currentMillis;
        updateDHT();
      }
    }

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

void updateDHT() {
  int temperature = dht.readTemperature(true);  // true = Fahrenheit
  int humidity = dht.readHumidity();

  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  if (temperature != oldTemperature) {
    temperatureChar.writeValue((uint8_t)temperature);
    oldTemperature = temperature;
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" *F");
  }

  if (humidity != oldHumidity) {
    humidityChar.writeValue((uint8_t)humidity);
    oldHumidity = humidity;
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");
  }
}

try that, you have the Characteristics and services incorrectly setup.

BLEService temperatureService("2A6E");  // 2A6E is a *characteristic*, not a *service*
BLEService humService("2A6F");          // Same issue

Both of those lines are trying to define BLE Services using standard 16-bit Characteristic UUIDs, which is invalid.

The temperature and humidity UUIDs (2A6E, 2A6F) are characteristic UUIDs, not service UUIDs. They’re supposed to be used inside a service — not as services themselves.

HTH
GL :slight_smile: PJ :v:

I have some demo’s on here of this exact setup, hit the search “BLE Environmental” you’ll see it. :+1:

1 Like

@PJ_Glasso Thank you soo much for your help with the code and clarification ! It works !!

Hi there,

That’s great… Please do mark it as the solution so others can find it too.
it;s NOT rocket science but a process Glad it works :+1:

GL :slight_smile: PJ :v: