Skip to content

Fully disable cloud connection to airgradient server option #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/local-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ If the monitor is set up on the AirGradient dashboard, it will also receive the
| `ledBarTestRequested` | Can be set to trigger a test. | Boolean | `true` : LEDs will run test sequence | `{"ledBarTestRequested": true}` |
| `noxLearningOffset` | Set NOx learning gain offset. | Number | 0-720 (default 12) | `{"noxLearningOffset": 12}` |
| `tvocLearningOffset` | Set VOC learning gain offset. | Number | 0-720 (default 12) | `{"tvocLearningOffset": 12}` |
| `offlineMode` | Set monitor to run without WiFi. | Boolean | `false`: Disabled (default) <br> `true`: Enabled | `{"offlineMode": true}` |
| `monitorDisplayCompensatedValues` | Set the display show the PM value with/without compensate value (only on [3.1.9]()) | Boolean | `false`: Without compensate (default) <br> `true`: with compensate | `{"monitorDisplayCompensatedValues": false }` |
| `corrections` | Sets correction options to display and measurement values on local server response. (version >= [3.1.11]()) | Object | _see corrections section_ | _see corrections section_ |


**Notes**

- `offlineMode` : the device will disable all network operation, and only show measurements on the display and ledbar; Read-Only; Change can be apply using reset button on boot.
- `disableCloudConnection` : disable every request to AirGradient server, means features like post data to AirGradient server, configuration from AirGradient server and automatic firmware updates are disabled. This configuration overrides `configurationControl` and `postDataToAirGradient`; Read-Only; Change can be apply from wifi setup webpage.

#### Corrections

Expand Down
31 changes: 23 additions & 8 deletions examples/BASIC/BASIC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ void setup() {
initMqtt();
sendDataToAg();

apiClient.fetchServerConfiguration();
if (configuration.getConfigurationControl() !=
ConfigurationControl::ConfigurationControlLocal) {
apiClient.fetchServerConfiguration();
}
configSchedule.update();
if (apiClient.isFetchConfigureFailed()) {
if (apiClient.isFetchConfigurationFailed()) {
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displaySetAddToDashBoard();
stateMachine.displayHandle(
Expand Down Expand Up @@ -415,6 +418,14 @@ static void failedHandler(String msg) {
}

static void configurationUpdateSchedule(void) {
if (configuration.isOfflineMode() ||
configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
Serial.println("Ignore fetch server configuration. Either mode is offline "
"or configurationControl set to local");
apiClient.resetFetchConfigurationStatus();
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore vs reset
also propose to log what the mode is

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore vs reset

Relate to this comment #278 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much redundancy code added to only log the exact mode. I think it's enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should start with a verb. e.g.
update ConfigurationSchedule()
it this is what it does. Within the method we then say resetFetchConfigurationStatus() so we have update vs. reset. Not entirely sure how to resolve this.


if (apiClient.fetchServerConfiguration()) {
configUpdateHandle();
}
Expand Down Expand Up @@ -472,7 +483,7 @@ static void appDispHandler(void) {
if (configuration.isOfflineMode() == false) {
if (wifiConnector.isConnected() == false) {
state = AgStateMachineWiFiLost;
} else if (apiClient.isFetchConfigureFailed()) {
} else if (apiClient.isFetchConfigurationFailed()) {
state = AgStateMachineSensorConfigFailed;
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displaySetAddToDashBoard();
Expand Down Expand Up @@ -521,17 +532,21 @@ static void sendDataToServer(void) {
int bootCount = measurements.bootCount() + 1;
measurements.setBootCount(bootCount);

/** Ignore send data to server if postToAirGradient disabled */
if (configuration.isPostDataToAirGradient() == false ||
configuration.isOfflineMode()) {
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
Serial.println("Skipping transmission of data to AG server. Either mode is offline "
"or post data to server disabled");
return;
}

if (wifiConnector.isConnected() == false) {
Serial.println("WiFi not connected, skipping data transmission to AG server");
return;
}

String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
if (apiClient.postToServer(syncData)) {
Serial.println();
Serial.println(
"Online mode and isPostToAirGradient = true: watchdog reset");
Serial.println("Online mode and isPostToAirGradient = true");
Serial.println();
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/BASIC/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ String OpenMetrics::getPayload(void) {
"1 if the AirGradient device was able to successfully fetch its "
"configuration from the server",
"gauge");
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
add_metric_point("", apiClient.isFetchConfigurationFailed() ? "0" : "1");

add_metric(
"post_ok",
Expand Down
31 changes: 23 additions & 8 deletions examples/DiyProIndoorV3_3/DiyProIndoorV3_3.ino
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ void setup() {
initMqtt();
sendDataToAg();

apiClient.fetchServerConfiguration();
if (configuration.getConfigurationControl() !=
ConfigurationControl::ConfigurationControlLocal) {
apiClient.fetchServerConfiguration();
}
configSchedule.update();
if (apiClient.isFetchConfigureFailed()) {
if (apiClient.isFetchConfigurationFailed()) {
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displaySetAddToDashBoard();
stateMachine.displayHandle(
Expand Down Expand Up @@ -467,6 +470,14 @@ static void failedHandler(String msg) {
}

static void configurationUpdateSchedule(void) {
if (configuration.isOfflineMode() ||
configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
Serial.println("Ignore fetch server configuration. Either mode is offline "
"or configurationControl set to local");
apiClient.resetFetchConfigurationStatus();
return;
}

if (apiClient.fetchServerConfiguration()) {
configUpdateHandle();
}
Expand Down Expand Up @@ -524,7 +535,7 @@ static void appDispHandler(void) {
if (configuration.isOfflineMode() == false) {
if (wifiConnector.isConnected() == false) {
state = AgStateMachineWiFiLost;
} else if (apiClient.isFetchConfigureFailed()) {
} else if (apiClient.isFetchConfigurationFailed()) {
state = AgStateMachineSensorConfigFailed;
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displaySetAddToDashBoard();
Expand Down Expand Up @@ -573,17 +584,21 @@ static void sendDataToServer(void) {
int bootCount = measurements.bootCount() + 1;
measurements.setBootCount(bootCount);

/** Ignore send data to server if postToAirGradient disabled */
if (configuration.isPostDataToAirGradient() == false ||
configuration.isOfflineMode()) {
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
Serial.println("Skipping transmission of data to AG server. Either mode is offline "
"or post data to server disabled");
return;
}

if (wifiConnector.isConnected() == false) {
Serial.println("WiFi not connected, skipping data transmission to AG server");
return;
}

String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
if (apiClient.postToServer(syncData)) {
Serial.println();
Serial.println(
"Online mode and isPostToAirGradient = true: watchdog reset");
Serial.println("Online mode and isPostToAirGradient = true");
Serial.println();
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/DiyProIndoorV3_3/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ String OpenMetrics::getPayload(void) {
"1 if the AirGradient device was able to successfully fetch its "
"configuration from the server",
"gauge");
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
add_metric_point("", apiClient.isFetchConfigurationFailed() ? "0" : "1");

add_metric(
"post_ok",
Expand Down
31 changes: 23 additions & 8 deletions examples/DiyProIndoorV4_2/DiyProIndoorV4_2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ void setup() {
initMqtt();
sendDataToAg();

apiClient.fetchServerConfiguration();
if (configuration.getConfigurationControl() !=
ConfigurationControl::ConfigurationControlLocal) {
apiClient.fetchServerConfiguration();
}
configSchedule.update();
if (apiClient.isFetchConfigureFailed()) {
if (apiClient.isFetchConfigurationFailed()) {
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displaySetAddToDashBoard();
stateMachine.displayHandle(
Expand Down Expand Up @@ -507,6 +510,14 @@ static void failedHandler(String msg) {
}

static void configurationUpdateSchedule(void) {
if (configuration.isOfflineMode() ||
configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
Serial.println("Ignore fetch server configuration. Either mode is offline "
"or configurationControl set to local");
apiClient.resetFetchConfigurationStatus();
return;
}

if (apiClient.fetchServerConfiguration()) {
configUpdateHandle();
}
Expand Down Expand Up @@ -564,7 +575,7 @@ static void appDispHandler(void) {
if (configuration.isOfflineMode() == false) {
if (wifiConnector.isConnected() == false) {
state = AgStateMachineWiFiLost;
} else if (apiClient.isFetchConfigureFailed()) {
} else if (apiClient.isFetchConfigurationFailed()) {
state = AgStateMachineSensorConfigFailed;
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displaySetAddToDashBoard();
Expand Down Expand Up @@ -614,17 +625,21 @@ static void sendDataToServer(void) {
int bootCount = measurements.bootCount() + 1;
measurements.setBootCount(bootCount);

/** Ignore send data to server if postToAirGradient disabled */
if (configuration.isPostDataToAirGradient() == false ||
configuration.isOfflineMode()) {
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
Serial.println("Skipping transmission of data to AG server. Either mode is offline "
"or post data to server disabled");
return;
}

if (wifiConnector.isConnected() == false) {
Serial.println("WiFi not connected, skipping data transmission to AG server");
return;
}

String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
if (apiClient.postToServer(syncData)) {
Serial.println();
Serial.println(
"Online mode and isPostToAirGradient = true: watchdog reset");
Serial.println("Online mode and isPostToAirGradient = true");
Serial.println();
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/DiyProIndoorV4_2/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ String OpenMetrics::getPayload(void) {
"1 if the AirGradient device was able to successfully fetch its "
"configuration from the server",
"gauge");
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
add_metric_point("", apiClient.isFetchConfigurationFailed() ? "0" : "1");

add_metric(
"post_ok",
Expand Down
Loading