atomic pointers - apparently helps coherence between cores.
This commit is contained in:
@@ -20,12 +20,12 @@ static std::string PASS = "";
|
|||||||
static std::string UNAME = "";
|
static std::string UNAME = "";
|
||||||
|
|
||||||
// Global pointers to characteristics for notification support
|
// Global pointers to characteristics for notification support
|
||||||
NimBLECharacteristic* ssidListChar = nullptr;
|
std::atomic<NimBLECharacteristic*> ssidListChar = nullptr;
|
||||||
NimBLECharacteristic* connectConfirmChar = nullptr;
|
std::atomic<NimBLECharacteristic*> connectConfirmChar = nullptr;
|
||||||
NimBLECharacteristic* authConfirmChar = nullptr;
|
std::atomic<NimBLECharacteristic*> authConfirmChar = nullptr;
|
||||||
NimBLECharacteristic* credsChar = nullptr;
|
std::atomic<NimBLECharacteristic*> credsChar = nullptr;
|
||||||
NimBLECharacteristic* tokenChar = nullptr;
|
std::atomic<NimBLECharacteristic*> tokenChar = nullptr;
|
||||||
NimBLECharacteristic* ssidRefreshChar = nullptr;
|
std::atomic<NimBLECharacteristic*> ssidRefreshChar = nullptr;
|
||||||
|
|
||||||
NimBLEAdvertising* initBLE() {
|
NimBLEAdvertising* initBLE() {
|
||||||
NimBLEDevice::init("BlindMaster-C6");
|
NimBLEDevice::init("BlindMaster-C6");
|
||||||
@@ -51,7 +51,7 @@ NimBLEAdvertising* initBLE() {
|
|||||||
"0000",
|
"0000",
|
||||||
NIMBLE_PROPERTY::READ
|
NIMBLE_PROPERTY::READ
|
||||||
);
|
);
|
||||||
ssidListChar->createDescriptor("2902"); // Add BLE2902 descriptor for notifications
|
ssidListChar.load()->createDescriptor("2902"); // Add BLE2902 descriptor for notifications
|
||||||
|
|
||||||
// 0x0001 - Credentials JSON (WRITE) - Replaces separate SSID/Password/Uname
|
// 0x0001 - Credentials JSON (WRITE) - Replaces separate SSID/Password/Uname
|
||||||
// Expected JSON format: {"ssid":"network","password":"pass"}
|
// Expected JSON format: {"ssid":"network","password":"pass"}
|
||||||
@@ -59,35 +59,35 @@ NimBLEAdvertising* initBLE() {
|
|||||||
"0001",
|
"0001",
|
||||||
NIMBLE_PROPERTY::WRITE
|
NIMBLE_PROPERTY::WRITE
|
||||||
);
|
);
|
||||||
credsChar->setCallbacks(charCallbacks);
|
credsChar.load()->setCallbacks(charCallbacks);
|
||||||
|
|
||||||
// 0x0002 - Token (WRITE)
|
// 0x0002 - Token (WRITE)
|
||||||
tokenChar = pService->createCharacteristic(
|
tokenChar = pService->createCharacteristic(
|
||||||
"0002",
|
"0002",
|
||||||
NIMBLE_PROPERTY::WRITE
|
NIMBLE_PROPERTY::WRITE
|
||||||
);
|
);
|
||||||
tokenChar->setCallbacks(charCallbacks);
|
tokenChar.load()->setCallbacks(charCallbacks);
|
||||||
|
|
||||||
// 0x0003 - Auth Confirmation (READ + NOTIFY)
|
// 0x0003 - Auth Confirmation (READ + NOTIFY)
|
||||||
authConfirmChar = pService->createCharacteristic(
|
authConfirmChar = pService->createCharacteristic(
|
||||||
"0003",
|
"0003",
|
||||||
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
|
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
|
||||||
);
|
);
|
||||||
authConfirmChar->createDescriptor("2902"); // Add BLE2902 descriptor for notifications
|
authConfirmChar.load()->createDescriptor("2902"); // Add BLE2902 descriptor for notifications
|
||||||
|
|
||||||
// 0x0004 - SSID Refresh (WRITE)
|
// 0x0004 - SSID Refresh (WRITE)
|
||||||
ssidRefreshChar = pService->createCharacteristic(
|
ssidRefreshChar = pService->createCharacteristic(
|
||||||
"0004",
|
"0004",
|
||||||
NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
|
NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
|
||||||
);
|
);
|
||||||
ssidRefreshChar->setCallbacks(charCallbacks);
|
ssidRefreshChar.load()->setCallbacks(charCallbacks);
|
||||||
|
|
||||||
// 0x0005 - Connect Confirmation (READ + NOTIFY)
|
// 0x0005 - Connect Confirmation (READ + NOTIFY)
|
||||||
connectConfirmChar = pService->createCharacteristic(
|
connectConfirmChar = pService->createCharacteristic(
|
||||||
"0005",
|
"0005",
|
||||||
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
|
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY
|
||||||
);
|
);
|
||||||
connectConfirmChar->createDescriptor("2902"); // Add BLE2902 descriptor for notifications
|
connectConfirmChar.load()->createDescriptor("2902"); // Add BLE2902 descriptor for notifications
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
pService->start();
|
pService->start();
|
||||||
@@ -106,14 +106,16 @@ NimBLEAdvertising* initBLE() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void notifyConnectionStatus(bool success) {
|
void notifyConnectionStatus(bool success) {
|
||||||
connectConfirmChar->setValue(success ? "Connected" : "Error");
|
NimBLECharacteristic* tmpConfChar = connectConfirmChar.load();
|
||||||
connectConfirmChar->notify();
|
tmpConfChar->setValue(success ? "Connected" : "Error");
|
||||||
connectConfirmChar->setValue(""); // Clear value after notify
|
tmpConfChar->notify();
|
||||||
|
tmpConfChar->setValue(""); // Clear value after notify
|
||||||
}
|
}
|
||||||
void notifyAuthStatus(bool success) {
|
void notifyAuthStatus(bool success) {
|
||||||
authConfirmChar->setValue(success ? "Authenticated" : "Error");
|
NimBLECharacteristic* tmpConfChar = authConfirmChar.load();
|
||||||
authConfirmChar->notify();
|
tmpConfChar->setValue(success ? "Authenticated" : "Error");
|
||||||
authConfirmChar->setValue(""); // Clear value after notify
|
tmpConfChar->notify();
|
||||||
|
tmpConfChar->setValue(""); // Clear value after notify
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BLEtick(NimBLEAdvertising* pAdvertising) {
|
bool BLEtick(NimBLEAdvertising* pAdvertising) {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#include "esp_wifi_types.h"
|
#include "esp_wifi_types.h"
|
||||||
|
|
||||||
// Global pointers to characteristics for notification support
|
// Global pointers to characteristics for notification support
|
||||||
extern NimBLECharacteristic* ssidListChar;
|
extern std::atomic<NimBLECharacteristic*> ssidListChar;
|
||||||
extern NimBLECharacteristic* ssidRefreshChar;
|
extern std::atomic<NimBLECharacteristic*> ssidRefreshChar;
|
||||||
extern std::atomic<bool> isBLEClientConnected;
|
extern std::atomic<bool> isBLEClientConnected;
|
||||||
|
|
||||||
class MyServerCallbacks : public NimBLEServerCallbacks {
|
class MyServerCallbacks : public NimBLEServerCallbacks {
|
||||||
|
|||||||
@@ -232,9 +232,10 @@ void WiFi::processScanResults() {
|
|||||||
|
|
||||||
// 5. Update BLE
|
// 5. Update BLE
|
||||||
if (ssidListChar != nullptr) {
|
if (ssidListChar != nullptr) {
|
||||||
ssidListChar->setValue(std::string(json_string));
|
ssidListChar.load()->setValue(std::string(json_string));
|
||||||
ssidRefreshChar->setValue("Ready");
|
NimBLECharacteristic *tmpRefreshChar = ssidRefreshChar.load();
|
||||||
ssidRefreshChar->notify();
|
tmpRefreshChar->setValue("Ready");
|
||||||
|
tmpRefreshChar->notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Cleanup Memory
|
// 6. Cleanup Memory
|
||||||
|
|||||||
Reference in New Issue
Block a user