Salut tout le monde, j'ai un petit soucis avec mes callbacks de BLE.
Voici mon code pour l'init du BLE
BLEDevice::init(nameBLEServeurForInit);
BLEServer *pServer = BLEDevice::createServer();
//Servive écriture mes paramètres
BLEService *pMyService = pServer->createService(SERVICE_CHANGE_PARAMS_ARDUINO_UUID);
//Characteristics nombre de relay
BLECharacteristic *nbRelayCharacteristic = pMyService->createCharacteristic(
NB_RELAY_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ);
//Characteristics changement du nom de l'Arduino
BLECharacteristic *pChangeNameCharacteristic = pMyService->createCharacteristic(
CHANGENAME_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
//Characteristics changement du mdp de l'Arduino
BLECharacteristic *pChangePasswordCharacteristic = pMyService->createCharacteristic(
PASSWORD_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
//Characteristics mise à jour de l'heure de l'Arduino
BLECharacteristic *pSetTimeCharacteristic = pMyService->createCharacteristic(
TIME_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
//Service Lancement Circuit
BLEService *pMyLaunchService = pServer->createService(SERVICE_LAUNCH_UUID);
//Characteristics lancement d'un circuit manuellement
BLECharacteristic *pStartLaunchManualCharacteristic = pMyLaunchService->createCharacteristic(
START_M_LAUNCH_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
//Characteristics lancements automatique
BLECharacteristic *psaveAutomaticLaunchCharacteristic = pMyLaunchService->createCharacteristic(
SAVE_A_LAUNCH_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
pChangePasswordCharacteristic->setCallbacks(new changePasswordArduinoCallBacks());
pChangeNameCharacteristic->setCallbacks(new changeNameArduinoCallBacks());
pSetTimeCharacteristic->setCallbacks(new changeTimedArduinoCallBacks());
// pStartLaunchManualCharacteristic->setCallbacks(new startingCircuitCallBacks());
psaveAutomaticLaunchCharacteristic->setCallbacks(new saveFirtAutomaticLaunchCallBacks());
nbRelayCharacteristic->setValue(NB_RELAY);
pMyService->start();
pMyLaunchService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
Voici mes Callbacks :
class changeNameArduinoCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pCharacteristic)
{
std::string value = pCharacteristic->getValue();
if (value.length() > 0)
{
eraseEEPROM(addr_name, 50);
for (int i = 0; i < value.length(); i++)
EEPROM.write(addr_name + i, value[i]);
}
EEPROM.commit();
Serial.println("Changement du nom effectué");
}
};
class changePasswordArduinoCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pCharacteristic)
{
std::string value = pCharacteristic->getValue();
if (value.length() > 0)
{
eraseEEPROM(addr_password, 50);
for (int i = 0; i < value.length(); i++)
{
EEPROM.write(addr_password + i, value[i]);
}
}
EEPROM.commit();
Serial.println("Changement du mot de passe effectué");
}
};
class changeTimedArduinoCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pCharacteristic)
{
std::string value = pCharacteristic->getValue();
String written_time;
if (value.length() > 0)
{
for (int i = 0; i < value.length(); i++)
{
written_time.concat(value[i]);
}
}
rtc.adjust(DateTime(2020, 10, 20, written_time.substring(0, written_time.indexOf(":")).toInt(), written_time.substring(written_time.indexOf(":") + 1, written_time.indexOf(":") * 2 + 1).toInt(), written_time.substring(written_time.indexOf(":") * 3).toInt()));
Serial.println("Mise à jour de l''heure effectué");
afficher_date_heure();
}
};
class startingCircuitCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pCharacteristic)
{
std::string value = pCharacteristic->getValue();
String startCircuit;
if (value.length() > 0)
{
for (int i = 0; i < value.length(); i++)
{
startCircuit.concat(value[i]);
}
}
solenoidNumber = startCircuit.substring(0, 2).toInt();
durationforLaunch = startCircuit.substring(startCircuit.indexOf(" ")).toInt() * 60000;
time_machine = millis();
}
};
Pour mettre dans le contexte, dans mon exemple ci-dessous, tous les appels de callbacks sont depuis mon téléphone en Bluetooth.
Mon problème est très bizarre si j'appelle la callback changeNameArduinoCallBacks(), ça fonctionne parfait pareil pour changePasswordArduinoCallBacks() et changeTimedArduinoCallBacks().
Par contre si j'exécute startingCircuitCallBacks() ou saveFirtAutomaticLaunchCallBacks() toutes les callbacks s'éxécutent.
Si j'exécute startingCircuitCallBacks(), ça m'éxecute changeNameArduinoCallBacks(), changePasswordArduinoCallBacks() et changeTimedArduinoCallBacks()
Merci pour votre aide