Hi team i need help. I want to check and identify each data receive using bluetooth BLE with this block i can't receive the data
Post your exported aia file and the sketch of the device transmitting the data.
#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;
BLEDescriptor *pDescr;
BLE2902 *pBLE2902;
bool deviceConnected = false;
bool oldDeviceConnected = false;
uint32_t value = 0;
String Current_cordinate = "140321000";
uint32_t Reci_cellSite_Dist = 8500;
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"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
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(SERVICE_UUID);
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_INDICATE |
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());
}
// 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() {
if(Serial.available() > 0){
Current_cordinate = Serial.read();
Current_cordinate.c_str();
}
// notify changed value
if (deviceConnected) {
pCharacteristic->setValue(value);
pCharacteristic->notify();
value++;
// delay(1000);
Serial.println("Sending current_cordinate.......");
pCharacteristic_1->setValue( Current_cordinate .c_str());
pCharacteristic_1->indicate();
Serial.println("Sent" + Current_cordinate);
//Current_cordinate++;
pCharacteristic_2->setValue(Reci_cellSite_Dist);
pCharacteristic_2->indicate();
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;
}
}
BLE_controller (2).aia (693.5 KB)
Bytevalues is a list of hopefully four numbers in the range 0 to 255.
If I read the sketch right it should be a uint32.
Applying text operators to a list forces JSON conversion, which you don't want, if you hope to access individual list items 1-4.
Use blue list select blocks on bytevalues to make get its items
Verify you got all 4 items first, by checking length of list bytevalues.
If no bytes arrive, that might be because of those delay() calls in the sketch. Those prevent other code sections in the void loop from getting a chance to run.
Better to replace those with time checks against deadlines, so you don't block execution.
I forgot to mention that there is a ble Register for Bytes block that would make it unnecessary to keep asking for reads from the sketch.
The data would arrive in the bytes received event on its own.
I can find list select block can you please give me an example of BLE list select block