This commit is contained in:
lash404 committed 2026-11-09 16:26:26 +01:00
1 parent 1114564e2b
commit 05530c4398
3 files changed
+140 -29

No files matched your search

+30 -29
View File
@@ -17,7 +17,7 @@ unsigned long HOUR=0;
unsigned long DAY=0;
unsigned long MONTH=0;
unsigned long YEAR=20;
unsigned long YEAR=2026;
String message = "";
@@ -30,22 +30,22 @@ bool timeChanged = false;
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, -1);
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, 0, true, 240, 240, 0, 0);
#define SERVICE_UUID "791cadd7-de87-49f9-8986-94b7ae11940b"
const uint16_t SERVICE_TD_UUID = 0x4d43;
#define CHAR_MESSAGE_UUID "3e4eac5b-eaa2-4e0c-a705-dcac4f606e01"
#define CHAR_TIME_UUID "3e4eac5b-eaa2-4e0c-a705-dcac4f606e02"
#define CHAR_DATE_UUID "3e4eac5b-eaa2-4e0c-a705-dcac4f606e03"
const uint16_t CHAR_MESSAGE_UUID = 0xb331;
const uint16_t CHAR_TIME_UUID = 0x3c4b;
const uint16_t CHAR_DATE_UUID = 0x6ecf;
#define SERVICE_NOTIFICATION_UUID "791cadd7-de87-49f9-8986-94b7ae11941b"
const uint16_t SERVICE_NOTIFICATION_UUID = 0xa7fa;
#define CHAR_NOTIF_APP_UUID "9ff3d4a9-2082-424d-bf34-8dfaf752ff90"
#define CHAR_NOTIF_TITLE_UUID "9ff3d4a9-2082-424d-bf34-8dfaf752ff91"
#define CHAR_NOTIF_TEXT_UUID "9ff3d4a9-2082-424d-bf34-8dfaf752ff92"
const uint16_t CHAR_NOTIF_APP_UUID = 0x375f;
const uint16_t CHAR_NOTIF_TITLE_UUID = 0x6e40;
const uint16_t CHAR_NOTIF_TEXT_UUID = 0x2eef;
#define deviceName "ESP32-Watch"
class CharacteristicCallbacksService: public BLECharacteristicCallbacks {
class CharacteristicCallbacksServiceTD: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) override {
String value = pCharacteristic->getValue();
@@ -84,7 +84,6 @@ class CharacteristicCallbacksNotification: public BLECharacteristicCallbacks {
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_NOTIF_APP_UUID))) {
Serial.print("Notification App: ");
Serial.println(value);
message = value;
}
if (pCharacteristic->getUUID().equals(BLEUUID(CHAR_NOTIF_TITLE_UUID))) {
@@ -160,7 +159,8 @@ void initDevice(){
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
BLEService *pServiceNotif = pServer->createService(SERVICE_NOTIFICATION_UUID);
BLEService *pServiceTD = pServer->createService(SERVICE_TD_UUID);
BLESecurity *pSecurity = new BLESecurity();
pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);
@@ -168,55 +168,56 @@ void initDevice(){
pSecurity->setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);
//---------------ServiceNotificationChar---------------------------------
BLECharacteristic *pCharacteristicApp = pService->createCharacteristic(
BLECharacteristic *pCharacteristicApp = pServiceNotif->createCharacteristic(
CHAR_NOTIF_APP_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristicApp->setCallbacks(new CharacteristicCallbacksService());
pCharacteristicApp->setValue("Hello World");
pCharacteristicApp->setCallbacks(new CharacteristicCallbacksNotification());
pCharacteristicApp->setValue("App");
BLECharacteristic *pCharacteristicTitle = pService->createCharacteristic(
BLECharacteristic *pCharacteristicTitle = pServiceNotif->createCharacteristic(
CHAR_NOTIF_TITLE_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristicTitle->setCallbacks(new CharacteristicCallbacksService());
pCharacteristicTitle->setValue("Hello World");
pCharacteristicTitle->setCallbacks(new CharacteristicCallbacksNotification());
pCharacteristicTitle->setValue("Title");
BLECharacteristic *pCharacteristicText = pService->createCharacteristic(
BLECharacteristic *pCharacteristicText = pServiceNotif->createCharacteristic(
CHAR_NOTIF_TEXT_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristicText->setCallbacks(new CharacteristicCallbacksService());
pCharacteristicText->setValue("Hello World");
pCharacteristicText->setCallbacks(new CharacteristicCallbacksNotification());
pCharacteristicText->setValue("Text");
//---------------ServiceChar--------------------------
BLECharacteristic *pCharacteristicMessage = pService->createCharacteristic(
BLECharacteristic *pCharacteristicMessage = pServiceTD->createCharacteristic(
CHAR_MESSAGE_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristicMessage->setCallbacks(new CharacteristicCallbacksService());
pCharacteristicMessage->setCallbacks(new CharacteristicCallbacksServiceTD());
pCharacteristicMessage->setValue("Hello World");
//Time
BLECharacteristic *pCharacteristicTime = pService->createCharacteristic(
BLECharacteristic *pCharacteristicTime = pServiceTD->createCharacteristic(
CHAR_TIME_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristicTime->setCallbacks(new CharacteristicCallbacksService());
pCharacteristicTime->setCallbacks(new CharacteristicCallbacksServiceTD());
pCharacteristicTime->setValue("TIME");
BLECharacteristic *pCharacteristicDate = pService->createCharacteristic(
BLECharacteristic *pCharacteristicDate = pServiceTD->createCharacteristic(
CHAR_DATE_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE);
pCharacteristicDate->setCallbacks(new CharacteristicCallbacksService());
pCharacteristicDate->setCallbacks(new CharacteristicCallbacksServiceTD());
pCharacteristicDate->setValue("Date");
pService->start();
pServiceTD->start();
Serial.println(ESP.getFreeHeap());
pServiceNotif->start();
Serial.println(ESP.getFreeHeap());
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();