mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-28 07:57:18 +02:00
Update diy samples
That accomodate ApiClient changes Fix apiClient begin on OneOpenAir
This commit is contained in:
@ -149,7 +149,10 @@ void setup() {
|
|||||||
initMqtt();
|
initMqtt();
|
||||||
sendDataToAg();
|
sendDataToAg();
|
||||||
|
|
||||||
|
if (configuration.getConfigurationControl() !=
|
||||||
|
ConfigurationControl::ConfigurationControlLocal) {
|
||||||
apiClient.fetchServerConfiguration();
|
apiClient.fetchServerConfiguration();
|
||||||
|
}
|
||||||
configSchedule.update();
|
configSchedule.update();
|
||||||
if (apiClient.isFetchConfigureFailed()) {
|
if (apiClient.isFetchConfigureFailed()) {
|
||||||
if (apiClient.isNotAvailableOnDashboard()) {
|
if (apiClient.isNotAvailableOnDashboard()) {
|
||||||
@ -415,6 +418,14 @@ static void failedHandler(String msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void configurationUpdateSchedule(void) {
|
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.resetFetchConfigureState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (apiClient.fetchServerConfiguration()) {
|
if (apiClient.fetchServerConfiguration()) {
|
||||||
configUpdateHandle();
|
configUpdateHandle();
|
||||||
}
|
}
|
||||||
@ -521,17 +532,21 @@ static void sendDataToServer(void) {
|
|||||||
int bootCount = measurements.bootCount() + 1;
|
int bootCount = measurements.bootCount() + 1;
|
||||||
measurements.setBootCount(bootCount);
|
measurements.setBootCount(bootCount);
|
||||||
|
|
||||||
/** Ignore send data to server if postToAirGradient disabled */
|
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
|
||||||
if (configuration.isPostDataToAirGradient() == false ||
|
Serial.println("Ignore send data to server. Either mode is offline "
|
||||||
configuration.isOfflineMode()) {
|
"or post data to server disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wifiConnector.isConnected() == false) {
|
||||||
|
Serial.println("WiFi not connected, skip post data to server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
|
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
|
||||||
if (apiClient.postToServer(syncData)) {
|
if (apiClient.postToServer(syncData)) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println(
|
Serial.println("Online mode and isPostToAirGradient = true");
|
||||||
"Online mode and isPostToAirGradient = true: watchdog reset");
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,10 @@ void setup() {
|
|||||||
initMqtt();
|
initMqtt();
|
||||||
sendDataToAg();
|
sendDataToAg();
|
||||||
|
|
||||||
|
if (configuration.getConfigurationControl() !=
|
||||||
|
ConfigurationControl::ConfigurationControlLocal) {
|
||||||
apiClient.fetchServerConfiguration();
|
apiClient.fetchServerConfiguration();
|
||||||
|
}
|
||||||
configSchedule.update();
|
configSchedule.update();
|
||||||
if (apiClient.isFetchConfigureFailed()) {
|
if (apiClient.isFetchConfigureFailed()) {
|
||||||
if (apiClient.isNotAvailableOnDashboard()) {
|
if (apiClient.isNotAvailableOnDashboard()) {
|
||||||
@ -467,6 +470,14 @@ static void failedHandler(String msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void configurationUpdateSchedule(void) {
|
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.resetFetchConfigureState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (apiClient.fetchServerConfiguration()) {
|
if (apiClient.fetchServerConfiguration()) {
|
||||||
configUpdateHandle();
|
configUpdateHandle();
|
||||||
}
|
}
|
||||||
@ -573,17 +584,21 @@ static void sendDataToServer(void) {
|
|||||||
int bootCount = measurements.bootCount() + 1;
|
int bootCount = measurements.bootCount() + 1;
|
||||||
measurements.setBootCount(bootCount);
|
measurements.setBootCount(bootCount);
|
||||||
|
|
||||||
/** Ignore send data to server if postToAirGradient disabled */
|
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
|
||||||
if (configuration.isPostDataToAirGradient() == false ||
|
Serial.println("Ignore send data to server. Either mode is offline "
|
||||||
configuration.isOfflineMode()) {
|
"or post data to server disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wifiConnector.isConnected() == false) {
|
||||||
|
Serial.println("WiFi not connected, skip post data to server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
|
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
|
||||||
if (apiClient.postToServer(syncData)) {
|
if (apiClient.postToServer(syncData)) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println(
|
Serial.println("Online mode and isPostToAirGradient = true");
|
||||||
"Online mode and isPostToAirGradient = true: watchdog reset");
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,10 @@ void setup() {
|
|||||||
initMqtt();
|
initMqtt();
|
||||||
sendDataToAg();
|
sendDataToAg();
|
||||||
|
|
||||||
|
if (configuration.getConfigurationControl() !=
|
||||||
|
ConfigurationControl::ConfigurationControlLocal) {
|
||||||
apiClient.fetchServerConfiguration();
|
apiClient.fetchServerConfiguration();
|
||||||
|
}
|
||||||
configSchedule.update();
|
configSchedule.update();
|
||||||
if (apiClient.isFetchConfigureFailed()) {
|
if (apiClient.isFetchConfigureFailed()) {
|
||||||
if (apiClient.isNotAvailableOnDashboard()) {
|
if (apiClient.isNotAvailableOnDashboard()) {
|
||||||
@ -507,6 +510,14 @@ static void failedHandler(String msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void configurationUpdateSchedule(void) {
|
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.resetFetchConfigureState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (apiClient.fetchServerConfiguration()) {
|
if (apiClient.fetchServerConfiguration()) {
|
||||||
configUpdateHandle();
|
configUpdateHandle();
|
||||||
}
|
}
|
||||||
@ -614,17 +625,21 @@ static void sendDataToServer(void) {
|
|||||||
int bootCount = measurements.bootCount() + 1;
|
int bootCount = measurements.bootCount() + 1;
|
||||||
measurements.setBootCount(bootCount);
|
measurements.setBootCount(bootCount);
|
||||||
|
|
||||||
/** Ignore send data to server if postToAirGradient disabled */
|
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
|
||||||
if (configuration.isPostDataToAirGradient() == false ||
|
Serial.println("Ignore send data to server. Either mode is offline "
|
||||||
configuration.isOfflineMode()) {
|
"or post data to server disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wifiConnector.isConnected() == false) {
|
||||||
|
Serial.println("WiFi not connected, skip post data to server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
|
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(), ag, configuration);
|
||||||
if (apiClient.postToServer(syncData)) {
|
if (apiClient.postToServer(syncData)) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println(
|
Serial.println("Online mode and isPostToAirGradient = true");
|
||||||
"Online mode and isPostToAirGradient = true: watchdog reset");
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -861,7 +861,7 @@ void initiateNetwork() {
|
|||||||
// Initiate local network configuration
|
// Initiate local network configuration
|
||||||
mdnsInit();
|
mdnsInit();
|
||||||
localServer.begin();
|
localServer.begin();
|
||||||
// Apply mqtt connection
|
// Apply mqtt connection if configured
|
||||||
initMqtt();
|
initMqtt();
|
||||||
|
|
||||||
// Ignore the rest if cloud connection to AirGradient is disabled
|
// Ignore the rest if cloud connection to AirGradient is disabled
|
||||||
@ -869,7 +869,10 @@ void initiateNetwork() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send ping to aigradient server
|
// Initialize api client
|
||||||
|
apiClient.begin();
|
||||||
|
|
||||||
|
// Send ping to airgradient server
|
||||||
sendDataToAg();
|
sendDataToAg();
|
||||||
|
|
||||||
// OTA check
|
// OTA check
|
||||||
|
Reference in New Issue
Block a user