Hi everebody, i need help with my Bluetooth.
For example I'm on my application,
I want to change the name so in my console: (changeNameArduinoCallBacks())
Name changed
I want to change the password so in my console: (changePasswordArduinoCallBacks())
Password changed
I want to change the time so in my console: (changeTimedArduinoCallBacks())
Updating the time
I want to run a manual launch so in my console: (startingCircuitCallBacks())
Wattering circuit n°1
And then if I want to make a backup of my automatic circuit in my console I have all that added: (saveFirtAutomaticLaunchCallBacks())
Name change made
Password change made
Updating the time performed
Wattering circuit n°1
Saving the launch 1 done
When the saveFirtAutomaticLaunchCallBacks() callback is called, it looks like it runs all other callbacks.
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <EEPROM.h>
#include <ArduinoJson.h>
#include <Solenoid.h>
#include <RTClib.h>
#define NB_RELAY "12"
#define nameBLEServeurForInit "testBLE"
BLEServer *pServer;
BLECharacteristic *nbRelayCharacteristic;
BLECharacteristic *pChangeNameCharacteristic;
BLECharacteristic *pChangePasswordCharacteristic;
BLECharacteristic *pSetTimeCharacteristic;
BLECharacteristic *pStartLaunchManualCharacteristic;
BLECharacteristic *psaveAutomaticLaunchCharacteristic;
#define SERVICE_CHANGE_PARAMS_ARDUINO_UUID "e660bdcb-638c-4dc6-b613-31610945bddb" //Service Params Arduino
#define NB_RELAY_CHARACTERISTIC_UUID "b6c0a045-715f-468d-a271-22d135b4762f" //Read the number of solenoid valves available
#define CHANGENAME_CHARACTERISTIC_UUID "9354398f-9105-44da-a58e-80de9a7f5fdc" //Rename Scheduler
#define PASSWORD_CHARACTERISTIC_UUID "27349bf0-cd6b-4391-a08f-d7745058b985" //Change password of Scheduler
#define TIME_CHARACTERISTIC_UUID "ee1c0d7f-fec3-4f89-ab2f-bb1a1807260d" //Set Time for Scheduler
#define START_M_LAUNCH_CHARACTERISTIC_UUID "caada16d-3b79-4fe2-a6e0-bc923f3d09bc" //Start a manual start of a solenoid valve
#define SAVE_A_LAUNCH_CHARACTERISTIC_UUID "d66addbe-49eb-480d-a8d8-54bac35aaf12" //Start a manual start of a solenoid valve
class changeNameArduinoCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pChangeNameCharacteristic)
{
std::string value = pChangeNameCharacteristic->getValue();
Serial.println("Name changed");
}
};
class changePasswordArduinoCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pChangePasswordCharacteristic)
{
std::string value = pChangePasswordCharacteristic->getValue();
Serial.println("Password changed");
}
};
class changeTimedArduinoCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pSetTimeCharacteristic)
{
std::string value = pSetTimeCharacteristic->getValue();
Serial.println("Updating the time");
}
};
class startingCircuitCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *pStartLaunchManualCharacteristic)
{
std::string value = pStartLaunchManualCharacteristic->getValue();
Serial.println("Wattering circuit n°1");
}
};
class saveFirtAutomaticLaunchCallBacks : public BLECharacteristicCallbacks
{
void onWrite(BLECharacteristic *psaveAutomaticLaunchCharacteristic)
{
std::string value = psaveAutomaticLaunchCharacteristic->getValue();
Serial.println("Saving the launch 1 done");
}
};
void setup()
{
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init(nameBLEServeurForInit);
// Create the BLE Server
pServer = BLEDevice::createServer();
// Create the BLE Service
BLEService *pMyService = pServer->createService(SERVICE_CHANGE_PARAMS_ARDUINO_UUID);
// *** Characteristics nombre de relay ***
nbRelayCharacteristic = pMyService->createCharacteristic(
NB_RELAY_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ);
nbRelayCharacteristic->setValue(NB_RELAY);
// *** Characteristics changement du nom de l'Arduino ***
pChangeNameCharacteristic = pMyService->createCharacteristic(
CHANGENAME_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
pChangeNameCharacteristic->setCallbacks(new changeNameArduinoCallBacks());
// *** Characteristics changement du mdp de l'Arduino ***
pChangePasswordCharacteristic = pMyService->createCharacteristic(
PASSWORD_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
pChangePasswordCharacteristic->setCallbacks(new changePasswordArduinoCallBacks());
// *** Characteristics for launch ***
pSetTimeCharacteristic = pMyService->createCharacteristic(
START_M_LAUNCH_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
pSetTimeCharacteristic->setCallbacks(new changeTimedArduinoCallBacks());
// *** Characteristics for save auto ***
psaveAutomaticLaunchCharacteristic = pMyService->createCharacteristic(
SAVE_A_LAUNCH_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_WRITE);
psaveAutomaticLaunchCharacteristic->setCallbacks(new saveFirtAutomaticLaunchCallBacks());
// start services
pMyService->start();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_CHANGE_PARAMS_ARDUINO_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Go ! ");
}
void loop() {
}