BLE Service not working

I have written the following code with the view forArduino UNO R4 WiFi to publish the Service and Characteristics.

In a separate Android application using MIT Inventor, I have confirmed that the Phone and Android and connected. However, when I check in Android, I get the following message indicating that Arduino has not started the Service.

image

// Bluetooth® Low Energy Service
BLEService HeightAndStaggerGaugeService ("62337a59-ce87-4561-b8a7-c85665d0a111");  // This is the UUID for BLE Service

// BLE Characteristics
// Syntax: BLE<DATATYPE>Characteristic <NAME>(<UUID>, <PROPERTIES>, <DATA LENGTH>)
BLEFloatCharacteristic MovementOfGaugeAlongTrackFloat ("ed0315e0-e5e5-469c-ba53-f15461520222", BLERead | BLEWrite | BLENotify);        // This is the UUID for movement of H&S Gauge received from Android

BLEStringCharacteristic MovementOfGaugeAlongTrackString ("85527775-d124-4257-a4d7-a0af5b199333", BLERead | BLEWrite | BLENotify, 13);  // This is the UUID for movement of H&S Gauge received from Android

void setup() {
  // put your setup code here, to run once:

  Serial.begin(19200);

  if (!BLE.begin()) {
    Serial.println("BLE failed to Initiate");  // commented 01/12/2023
    delay(10);                                 // commented 01/12/2023
    while (1);
  }

  Serial.println("Passed the BLE Begin loop");

  // Adding characteristics to BLE Service Advertisment
  HeightAndStaggerGaugeService.addCharacteristic (MovementOfGaugeAlongTrackFloat);
  HeightAndStaggerGaugeService.addCharacteristic (MovementOfGaugeAlongTrackString);

  // Adding the service to the BLE stack
  BLE.addService(HeightAndStaggerGaugeService);
  // Start advertising
  BLE.advertise();
  
  Serial.println("Bluetooth device is now active, waiting for connections..."); 
}

you are missing BLE.setAdvertisedService(HeightAndStaggerGaugeService);
Like :

  BLE.setAdvertisedService(HeightAndStaggerGaugeService);

 // Adding characteristics to BLE Service Advertisment
  HeightAndStaggerGaugeService.addCharacteristic (MovementOfGaugeAlongTrackFloat);
  HeightAndStaggerGaugeService.addCharacteristic (MovementOfGaugeAlongTrackString);

  // Adding the service to the BLE stack
  BLE.addService(HeightAndStaggerGaugeService);

  // Start advertising
  BLE.advertise();

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.