Recieving string data via BLE

Good team, i am sending string data from esp32 to mit app inventor using descriptors however the values don't show up in the app, my search tells me that in the phone app notification need to enable any help about how to enable notification or how to go about it

Did you register for strings?

Also, upload the esp32 code here.

Did you try testing the sketch against a ble terminal program like nrfConnect?

The more you post, the better your answers.

  1. i don't know what you mean by register for string any help on that,
  2. yes I tested with rnfeconnect "value" data shows up normal but current_cordinate data I have to enable the notification before it shows.
#include <BLEDevice.h>

#include <BLEServer.h>

#include <BLEUtils.h>

#include <BLE2902.h>

// create pointers

BLEServer* pServer = NULL;

BLECharacteristic* pCharacteristic = NULL;

BLECharacteristic* pCharacteristic_1 = NULL;

BLECharacteristic* pCharacteristic_2 = NULL;

BLECharacteristic* pCharacteristic_3 = NULL;

BLECharacteristic* pCharacteristic_4 = NULL;

BLECharacteristic* pCharacteristic_5 = NULL;

BLECharacteristic* pCharacteristic_6 = NULL;

BLECharacteristic* pCharacteristic_7 = NULL;

BLECharacteristic* pCharacteristic_8 = NULL;

BLECharacteristic* pCharacteristic_9 = NULL;

BLECharacteristic* pCharacteristic_10 = NULL;

BLEDescriptor *pDescr;

BLE2902 *pBLE2902;

bool deviceConnected = false;

bool oldDeviceConnected = false;

uint32_t value = 0;

String Current_cordinate = "140321000";
static BLEUUID BLESERVICE_UUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b");   // this allow the use of more than four services
#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHAR_UUID          "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define CHAR1_UUID          "e3223119-9445-4e96-a4a1-85358c4046a2"
#define CHAR2_UUID          "8a73ddbb-3fdd-4c04-9f0e-606546d8d36d"   
#define CHAR3_UUID          "9d4f2a6b-d642-40c2-8dad-1badfbb1abc3" 
#define CHAR4_UUID          "1ad44ffe-d29a-4a95-8577-56ffb0a03161" 
#define CHAR5_UUID          "628a8766-ea90-4c5d-b5c5-f4292aa3851e" 
#define CHAR6_UUID          "dce07269-15a4-4142-8941-abac53ff9f11" 
#define CHAR7_UUID          "219b5495-9311-4239-9a92-164a010b8bae" 
#define CHAR8_UUID          "bf8ad487-5081-4c86-b4b0-feec1d3c8620"
#define CHAR9_UUID          "dc4d0b1a-459d-4f9d-9642-03d98ff993fb"
#define CHAR10_UUID         "16de44f8-bc3a-4a81-9cd7-6a9a86a57efd" 

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

class CharacteristicCallBack: public BLECharacteristicCallbacks {
  void onWrite(BLECharacteristic *pChar) override {
    String pChar2_value_stdstr = pChar -> getValue(); 
    String pChar2_value_string = String (pChar2_value_stdstr.c_str());
   // try{
    int pChar2_value_int = pChar2_value_string.toInt();
static BLEUUID BLESERVICE_UUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b");   // this allow the use of more than four services
#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHAR_UUID          "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define CHAR1_UUID          "e3223119-9445-4e96-a4a1-85358c4046a2"
#define CHAR2_UUID          "8a73ddbb-3fdd-4c04-9f0e-606546d8d36d"   
#define CHAR3_UUID          "9d4f2a6b-d642-40c2-8dad-1badfbb1abc3" 
#define CHAR4_UUID          "1ad44ffe-d29a-4a95-8577-56ffb0a03161" 
#define CHAR5_UUID          "628a8766-ea90-4c5d-b5c5-f4292aa3851e" 
#define CHAR6_UUID          "dce07269-15a4-4142-8941-abac53ff9f11" 
#define CHAR7_UUID          "219b5495-9311-4239-9a92-164a010b8bae" 
#define CHAR8_UUID          "bf8ad487-5081-4c86-b4b0-feec1d3c8620"
#define CHAR9_UUID          "dc4d0b1a-459d-4f9d-9642-03d98ff993fb"
#define CHAR10_UUID         "16de44f8-bc3a-4a81-9cd7-6a9a86a57efd" 

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

class CharacteristicCallBack: public BLECharacteristicCallbacks {
  void onWrite(BLECharacteristic *pChar) override {
    String pChar2_value_stdstr = pChar -> getValue(); 
    String pChar2_value_string = String (pChar2_value_stdstr.c_str());
   // try{
    int pChar2_value_int = pChar2_value_string.toInt();
}

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

  // Create the BLE Device
  BLEDevice::init("ESP32");

  // Create the BLE Server
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());
 BLEService *pService = pServer->createService(BLESERVICE_UUID, 20, 0);       // this is the continuetion of the code that 
                                                                                // allow's the use of more than four services
  // Create a BLE Characteristic
  pCharacteristic = pService->createCharacteristic(
                      CHAR_UUID,
                      BLECharacteristic::PROPERTY_NOTIFY
                    ); 
pCharacteristic_1 = pService->createCharacteristic(
                      CHAR1_UUID,
                      BLECharacteristic::PROPERTY_NOTIFY |
                      BLECharacteristic::PROPERTY_READ  // |
                     // BLECharacteristic::PROPERTY_WRITE  
                    ); 
  pCharacteristic_2 = pService->createCharacteristic(
                      CHAR2_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    ); 
  pCharacteristic_3 = pService->createCharacteristic(
                      CHAR3_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    );                                      
pCharacteristic_4 = pService->createCharacteristic(
                      CHAR4_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    ); 
pCharacteristic_5 = pService->createCharacteristic(
                      CHAR5_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    ); 
pCharacteristic_6 = pService->createCharacteristic(
                      CHAR6_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    ); 
pCharacteristic_7 = pService->createCharacteristic(
                      CHAR7_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    ); 
 pCharacteristic_8 = pService->createCharacteristic(
                      CHAR8_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    ); 
pCharacteristic_9 = pService->createCharacteristic(
                      CHAR9_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    );
pCharacteristic_10 = pService->createCharacteristic(
                      CHAR10_UUID,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_WRITE  
                    );                                                                                                     
  // Create a BLE Descriptor
  
  pDescr = new BLEDescriptor((uint16_t)0x2901);
  pDescr->setValue("A very interesting variable");
  pCharacteristic->addDescriptor(pDescr);
  
  pBLE2902 = new BLE2902();
  pBLE2902->setNotifications(true);
  
  // Add all Descriptors here
  pCharacteristic->addDescriptor(pBLE2902);
  pCharacteristic_1->addDescriptor(new BLE2902());
  // After defining the desriptors, set the callback functions
  pCharacteristic_1->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_2->addDescriptor(new BLE2902());
  pCharacteristic_2->setCallbacks(new CharacteristicCallBack());   //Charateristics Callback for the descriptor
                                                                   // do same for rest of descriptors  
  pCharacteristic_3->addDescriptor(new BLE2902());
  pCharacteristic_3->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_4->addDescriptor(new BLE2902());
  pCharacteristic_4->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_5->addDescriptor(new BLE2902());
  pCharacteristic_5->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_6->addDescriptor(new BLE2902());
  pCharacteristic_6->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_7->addDescriptor(new BLE2902());
  pCharacteristic_7->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_8->addDescriptor(new BLE2902());
  pCharacteristic_8->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_9->addDescriptor(new BLE2902());
  pCharacteristic_9->setCallbacks(new CharacteristicCallBack());

  pCharacteristic_10->addDescriptor(new BLE2902());
  pCharacteristic_10->setCallbacks(new CharacteristicCallBack());
  
  
  
  // Start the service
  pService->start();
// Start advertising
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(false);
  pAdvertising->setMinPreferred(0x0);  // set value to 0x00 to not advertise this parameter
  BLEDevice::startAdvertising(); 
  pServer->getAdvertising()->start();  
  Serial.println("Waiting a client connection to notify...");
}

void loop() {
    // notify changed value
    if (deviceConnected) {
        pCharacteristic->setValue(value);
        pCharacteristic->notify();
        value++;
        delay(1000);
 pCharacteristic_1->setValue(Current_cordinate .c_str());
       pCharacteristic_1->notify();
       //Current_cordinate++;
       delay(1000);
    }
    // disconnecting
    if (!deviceConnected && oldDeviceConnected) {
        delay(500); // give the bluetooth stack the chance to get things ready
        pServer->startAdvertising(); // restart advertising
        Serial.println("start advertising");
        oldDeviceConnected = deviceConnected;
    }
    // connecting
    if (deviceConnected && !oldDeviceConnected) {
        // do stuff here on connecting
        oldDeviceConnected = deviceConnected;
    }
}

when i test it with nrfconnect the "value" data shows and update without requiring notify enabling however "current_cordinate" don't show unless i enable notification, with MIT app inventor "value" data shows but "current_cordinate" data don't show

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

export_and_upload_aia

.

BLE_controller.aia (663.8 KB)

image

Your BLE extension is old.
Where did you get it?

(I can't vouch for any extensions)

I see you registering for Bytes, and receiving Bytes, but I
see you receiving Strings without registering for Strings.

P.S. Here is your Screen1 blocks image, for the benefit of our BLE experts.