Good day friends i a with mit app i need your help.
i want to write and receive string with different characteristic uuid however writing is not successful unless i disable receiving characteristic uuid block then i can i write to arduino.
Again concerning receiving characteristic uuid I'm receiving more than 64 byte data so i request for MTU increase however enable this block too prevent the app from writing to arduino
with the image attach UUID_Char2 is writing to arduino and UUID_Char3 is receiving
Maybe do the registers in this event?
ask you may know, request must happened first before .MTUChanged event can run and when ever the request block is enable i can write to arduino
Perhaps if you post all your blocks, and the Arduino sketch (inline between ``` lines), one of our BLE experts can help. Be sure you have the current BLE aix version.
Arduino code.
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
BLECharacteristic* pCharacteristic_2 = NULL;
BLECharacteristic* pCharacteristic_3 = NULL;
BLEDescriptor* pDescr;
BLE2902* pBLE2902;
bool deviceConnected = false;
bool oldDeviceConnected = false;
uint32_t value = 0;
String longitudeCordinate = "";
String latitudeCordinate = "";
String recieverTracker_Proximity = "";
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHAR1_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define CHAR2_UUID "e3223119-9445-4e96-a4a1-85358c4046a2"
#define CHAR3_UUID "702b76bb-0434-47d6-bbf9-d7705dbd56d1"
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_string = pChar->getValue(); // This part is updated slightly from the video
int pChar2_value_int = pChar2_value_string.toInt();
Serial.println("pChar2: " + String(pChar2_value_int));
}
};
void setup() {
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("ESP32");
BLEDevice::setMTU(100);
// Create the BLE Server
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
// Create the BLE Service
BLEService* pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pCharacteristic = pService->createCharacteristic(
CHAR1_UUID,
BLECharacteristic::PROPERTY_NOTIFY);
pCharacteristic_2 = pService->createCharacteristic(
CHAR2_UUID,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
pCharacteristic_3 = pService->createCharacteristic(
CHAR3_UUID,
//BLECharacteristic::PROPERTY_NOTIFY |
//BLECharacteristic::PROPERTY_READ |
// BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_INDICATE);
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_2->addDescriptor(new BLE2902());
// After defining the desriptors, set the callback functions
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();
Serial.println("Waiting a client connection to notify...");
}
void loop() {
// notify changed value
if (deviceConnected) {
pCharacteristic->setValue(value);
pCharacteristic->notify();
value++;}
if (deviceConnected) {
String CombineData = longitudeCordinate + "|" + latitudeCordinate + "|"
+ recieverTracker_Proximity;
pCharacteristic_3->setValue(CombineData.c_str());
pCharacteristic_3->indicate();
Serial.print("All data combine.......");
Serial.println(CombineData.c_str());
}
delay(1000);
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;
}
}
APP BLOCKS
BLE.aia (203.5 KB)
Here's the Downloaded Blocks image you could have posted to speed things up.
I also wrapped your code with ``` to show the indentation.
Now all we need is some one who can figure out where your sketch does its data transmission.
Regarding the slider changed event, be aware that those fire in rapid succession, causing torrential data flow.
If you just want the new slider setting and not a violin concerto, keep the prior thumb value in a global value and have a clock timer check for changes between cycles. Only transmit from the clock timer, if the thumb has changed.
This lets you throttle the data traffic from the slider.
As for slider i'm ok with the data it send, the problem is in BluetoothLE1 function
once i enable uuid _char3's register for string component then the slider can no longer write to arduino also if enable bluetoothLE1.request MTU this one slider can not write to arduino