mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-04 11:46:32 +02:00
Add postDataToAirGradient checkbox to WiFi Manager
This commit is contained in:
@ -82,7 +82,7 @@ static AirGradient *ag;
|
||||
static OledDisplay oledDisplay(configuration, measurements, Serial);
|
||||
static StateMachine stateMachine(oledDisplay, Serial, measurements,
|
||||
configuration);
|
||||
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine);
|
||||
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine, configuration);
|
||||
static OpenMetrics openMetrics(measurements, configuration, wifiConnector,
|
||||
apiClient);
|
||||
static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
||||
|
@ -728,3 +728,13 @@ void Configuration::jsonInvalid(void) {
|
||||
}
|
||||
|
||||
String Configuration::getFailedMesage(void) { return failedMessage; }
|
||||
|
||||
void Configuration::setPostToAirGradient(bool enable) {
|
||||
if (enable != config.postDataToAirGradient) {
|
||||
config.postDataToAirGradient = enable;
|
||||
logInfo("postDataToAirGradient set to: " + String(enable));
|
||||
saveConfig();
|
||||
} else {
|
||||
logInfo("postDataToAirGradient: Ignored set to " + String(enable));
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ public:
|
||||
String getModel(void);
|
||||
bool isUpdated(void);
|
||||
String getFailedMesage(void);
|
||||
void setPostToAirGradient(bool enable);
|
||||
};
|
||||
|
||||
#endif /** _AG_CONFIG_H_ */
|
||||
|
@ -21,8 +21,8 @@ void WifiConnector::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||
* @param log Stream
|
||||
* @param sm StateMachine
|
||||
*/
|
||||
WifiConnector::WifiConnector(OledDisplay &disp, Stream &log, StateMachine &sm)
|
||||
: PrintLog(log, "WifiConnector"), disp(disp), sm(sm) {}
|
||||
WifiConnector::WifiConnector(OledDisplay &disp, Stream &log, StateMachine &sm,Configuration& config)
|
||||
: PrintLog(log, "WifiConnector"), disp(disp), sm(sm), config(config) {}
|
||||
#else
|
||||
WifiConnector::WifiConnector(Stream &log) : PrintLog(log, "WiFiConnector") {}
|
||||
#endif
|
||||
@ -61,6 +61,11 @@ bool WifiConnector::connect(void) {
|
||||
ssid = "AG-" + String(ESP.getChipId(), HEX);
|
||||
#endif
|
||||
WIFI()->setConfigPortalTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||
|
||||
WiFiManagerParameter lineBreak("<p>Check to enabled post data to AirGradient cloud</p>");
|
||||
WIFI()->addParameter(&lineBreak);
|
||||
WiFiManagerParameter postToAg("chbPostToAg", "Post To AirGradient", "T", 2, "type=\"checkbox\" ", WFM_LABEL_AFTER);
|
||||
WIFI()->addParameter(&postToAg);
|
||||
WIFI()->autoConnect(ssid.c_str(), WIFI_HOTSPOT_PASSWORD_DEFAULT);
|
||||
|
||||
#ifdef ESP32
|
||||
@ -134,6 +139,10 @@ bool WifiConnector::connect(void) {
|
||||
} else {
|
||||
hasConfig = true;
|
||||
logInfo("WiFi Connected: " + WiFi.SSID() + " IP: " + localIpStr());
|
||||
|
||||
String result = String(postToAg.getValue());
|
||||
logInfo("Post to AirGradient Configure: " + result);
|
||||
config.setPostToAirGradient(result == "T");
|
||||
}
|
||||
#else
|
||||
_wifiProcess();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "AgOledDisplay.h"
|
||||
#include "AgStateMachine.h"
|
||||
#include "AirGradient.h"
|
||||
#include "AgConfigure.h"
|
||||
#include "Main/PrintLog.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
@ -14,6 +15,7 @@ private:
|
||||
#ifdef ESP32
|
||||
OledDisplay &disp;
|
||||
StateMachine &sm;
|
||||
Configuration &config;
|
||||
#else
|
||||
void displayShowText(String ln1, String ln2, String ln3);
|
||||
#endif
|
||||
@ -27,7 +29,7 @@ private:
|
||||
public:
|
||||
void setAirGradient(AirGradient *ag);
|
||||
#ifdef ESP32
|
||||
WifiConnector(OledDisplay &disp, Stream &log, StateMachine &sm);
|
||||
WifiConnector(OledDisplay &disp, Stream &log, StateMachine &sm, Configuration& config);
|
||||
#else
|
||||
WifiConnector(Stream &log);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user