From 3a56ee448d43a2cab2df0274210828bfa68ec65b Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Fri, 31 Oct 2025 02:08:02 +0700 Subject: [PATCH] Provision status BLE proper definition --- examples/OneOpenAir/OneOpenAir.ino | 12 ++++++------ src/AgWiFiConnector.cpp | 6 +++--- src/AgWiFiConnector.h | 12 ++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/examples/OneOpenAir/OneOpenAir.ino b/examples/OneOpenAir/OneOpenAir.ino index 304269d..b3636e1 100644 --- a/examples/OneOpenAir/OneOpenAir.ino +++ b/examples/OneOpenAir/OneOpenAir.ino @@ -691,7 +691,7 @@ static void sendDataToAg() { stateMachine.displayHandle(AgStateMachineWiFiOkServerConnecting); } stateMachine.handleLeds(AgStateMachineWiFiOkServerConnecting); - wifiConnector.bleNotifyStatus(1); + wifiConnector.bleNotifyStatus(PROV_CONNECTING_TO_SERVER); /** Task handle led connecting animation */ xTaskCreate( @@ -720,13 +720,13 @@ static void sendDataToAg() { stateMachine.displayHandle(AgStateMachineWiFiOkServerConnected); } stateMachine.handleLeds(AgStateMachineWiFiOkServerConnected); - wifiConnector.bleNotifyStatus(2); + wifiConnector.bleNotifyStatus(PROV_SERVER_REACHABLE); } else { if (ag->isOne()) { stateMachine.displayHandle(AgStateMachineWiFiOkServerConnectFailed); } stateMachine.handleLeds(AgStateMachineWiFiOkServerConnectFailed); - wifiConnector.bleNotifyStatus(11); + wifiConnector.bleNotifyStatus(PROV_ERR_SERVER_UNREACHABLE); } stateMachine.handleLeds(AgStateMachineNormal); @@ -1048,17 +1048,17 @@ void initializeNetwork() { if (agClient->isRegisteredOnAgServer() == false) { stateMachine.displaySetAddToDashBoard(); stateMachine.displayHandle(AgStateMachineWiFiOkServerOkSensorConfigFailed); - wifiConnector.bleNotifyStatus(13); + wifiConnector.bleNotifyStatus(PROV_ERR_MONITOR_NOT_REGISTERED); } else { stateMachine.displayClearAddToDashBoard(); - wifiConnector.bleNotifyStatus(12); + wifiConnector.bleNotifyStatus(PROV_ERR_GET_MONITOR_CONFIG_FAILED); } } stateMachine.handleLeds(AgStateMachineWiFiOkServerOkSensorConfigFailed); delay(DISPLAY_DELAY_SHOW_CONTENT_MS); } else { ledBarEnabledUpdate(); - wifiConnector.bleNotifyStatus(3); + wifiConnector.bleNotifyStatus(PROV_MONITOR_CONFIGURED); } } diff --git a/src/AgWiFiConnector.cpp b/src/AgWiFiConnector.cpp index e5c7821..dac8aed 100644 --- a/src/AgWiFiConnector.cpp +++ b/src/AgWiFiConnector.cpp @@ -242,7 +242,7 @@ bool WifiConnector::connect(void) { // If not connect send status through BLE while also turn led and display indicator WiFi.disconnect(); wifiConnecting = false; - bleNotifyStatus(10); + bleNotifyStatus(PROV_ERR_WIFI_CONNECT_FAILED); // Show failed inficator then revert back to provision mode sm.ledAnimationInit(); @@ -295,7 +295,7 @@ bool WifiConnector::connect(void) { config.setDisableCloudConnection(result == "T"); } hasPortalConfig = false; - bleNotifyStatus(0); + bleNotifyStatus(PROV_WIFI_CONNECT); } return true; @@ -715,7 +715,7 @@ void WifiConnector::stopBLE() { if (bleServerRunning) { Serial.println("Stopping BLE"); NimBLEDevice::deinit(); - } + } bleServerRunning = false; } diff --git a/src/AgWiFiConnector.h b/src/AgWiFiConnector.h index c148902..cf51369 100644 --- a/src/AgWiFiConnector.h +++ b/src/AgWiFiConnector.h @@ -14,6 +14,18 @@ #include #include +// Provisioning Status Codes +#define PROV_WIFI_CONNECT 0 // WiFi Connect +#define PROV_CONNECTING_TO_SERVER 1 // Connecting to server +#define PROV_SERVER_REACHABLE 2 // Server reachable +#define PROV_MONITOR_CONFIGURED 3 // Monitor configured properly on dashboard + +// Provisioning Error Codes +#define PROV_ERR_WIFI_CONNECT_FAILED 10 // Failed to connect to WiFi +#define PROV_ERR_SERVER_UNREACHABLE 11 // Server unreachable +#define PROV_ERR_GET_MONITOR_CONFIG_FAILED 12 // Failed to get monitor configuration from dashboard +#define PROV_ERR_MONITOR_NOT_REGISTERED 13 // Monitor is not registered on dashboard + class WifiConnector : public PrintLog { public: enum class ProvisionMethod {