mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-16 18:22:09 +02:00
Merge pull request #124 from airgradienthq/hotfix/configuration-handle
Configuration failed response message and failed condition handle.
This commit is contained in:
@ -39,7 +39,11 @@ String LocalServer::getHostname(void) {
|
|||||||
void LocalServer::_handle(void) { server.handleClient(); }
|
void LocalServer::_handle(void) { server.handleClient(); }
|
||||||
|
|
||||||
void LocalServer::_GET_config(void) {
|
void LocalServer::_GET_config(void) {
|
||||||
server.send(200, "application/json", config.toString());
|
if(ag->isOne()) {
|
||||||
|
server.send(200, "application/json", config.toString());
|
||||||
|
} else {
|
||||||
|
server.send(200, "application/json", config.toString(fwMode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalServer::_PUT_config(void) {
|
void LocalServer::_PUT_config(void) {
|
||||||
|
@ -804,9 +804,11 @@ static void configUpdateHandle() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ledBarEnabledUpdate();
|
if (ag->isOne()) {
|
||||||
|
ledBarEnabledUpdate();
|
||||||
|
stateMachine.executeLedBarTest();
|
||||||
|
}
|
||||||
stateMachine.executeCo2Calibration();
|
stateMachine.executeCo2Calibration();
|
||||||
stateMachine.executeLedBarTest();
|
|
||||||
|
|
||||||
String mqttUri = configuration.getMqttBrokerUri();
|
String mqttUri = configuration.getMqttBrokerUri();
|
||||||
if (mqttClient.isCurrentUri(mqttUri) == false) {
|
if (mqttClient.isCurrentUri(mqttUri) == false) {
|
||||||
@ -814,38 +816,42 @@ static void configUpdateHandle() {
|
|||||||
initMqtt();
|
initMqtt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.noxLearnOffsetChanged() ||
|
if (configuration.hasSensorSGP) {
|
||||||
configuration.tvocLearnOffsetChanged()) {
|
if (configuration.noxLearnOffsetChanged() ||
|
||||||
ag->sgp41.end();
|
configuration.tvocLearnOffsetChanged()) {
|
||||||
|
ag->sgp41.end();
|
||||||
|
|
||||||
int oldTvocOffset = ag->sgp41.getTvocLearningOffset();
|
int oldTvocOffset = ag->sgp41.getTvocLearningOffset();
|
||||||
int oldNoxOffset = ag->sgp41.getNoxLearningOffset();
|
int oldNoxOffset = ag->sgp41.getNoxLearningOffset();
|
||||||
bool result = sgp41Init();
|
bool result = sgp41Init();
|
||||||
const char *resultStr = "successful";
|
const char *resultStr = "successful";
|
||||||
if (!result) {
|
if (!result) {
|
||||||
resultStr = "failure";
|
resultStr = "failure";
|
||||||
}
|
}
|
||||||
if (oldTvocOffset != configuration.getTvocLearningOffset()) {
|
if (oldTvocOffset != configuration.getTvocLearningOffset()) {
|
||||||
Serial.printf("Setting tvocLearningOffset from %d to %d hours %s\r\n",
|
Serial.printf("Setting tvocLearningOffset from %d to %d hours %s\r\n",
|
||||||
oldTvocOffset, configuration.getTvocLearningOffset(),
|
oldTvocOffset, configuration.getTvocLearningOffset(),
|
||||||
resultStr);
|
resultStr);
|
||||||
}
|
}
|
||||||
if (oldNoxOffset != configuration.getNoxLearningOffset()) {
|
if (oldNoxOffset != configuration.getNoxLearningOffset()) {
|
||||||
Serial.printf("Setting noxLearningOffset from %d to %d hours %s\r\n",
|
Serial.printf("Setting noxLearningOffset from %d to %d hours %s\r\n",
|
||||||
oldNoxOffset, configuration.getNoxLearningOffset(),
|
oldNoxOffset, configuration.getNoxLearningOffset(),
|
||||||
resultStr);
|
resultStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.isLedBarBrightnessChanged()) {
|
if (ag->isOne()) {
|
||||||
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
|
if (configuration.isLedBarBrightnessChanged()) {
|
||||||
Serial.println("Set 'LedBarBrightness' brightness: " +
|
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
|
||||||
String(configuration.getLedBarBrightness()));
|
Serial.println("Set 'LedBarBrightness' brightness: " +
|
||||||
}
|
String(configuration.getLedBarBrightness()));
|
||||||
if (configuration.isDisplayBrightnessChanged()) {
|
}
|
||||||
oledDisplay.setBrightness(configuration.getDisplayBrightness());
|
if (configuration.isDisplayBrightnessChanged()) {
|
||||||
Serial.println("Set 'DisplayBrightness' brightness: " +
|
oledDisplay.setBrightness(configuration.getDisplayBrightness());
|
||||||
String(configuration.getDisplayBrightness()));
|
Serial.println("Set 'DisplayBrightness' brightness: " +
|
||||||
|
String(configuration.getDisplayBrightness()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fwNewVersion = configuration.newFirmwareVersion();
|
fwNewVersion = configuration.newFirmwareVersion();
|
||||||
|
@ -411,6 +411,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
failedMessage =
|
||||||
jsonValueInvalidMessage(String(jprop_displayMode), mode);
|
jsonValueInvalidMessage(String(jprop_displayMode), mode);
|
||||||
jsonInvalid();
|
jsonInvalid();
|
||||||
return false;
|
return false;
|
||||||
@ -503,10 +504,16 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (JSON.typeof_(root[jprop_mqttBrokerUrl]) == "string") {
|
if (JSON.typeof_(root[jprop_mqttBrokerUrl]) == "string") {
|
||||||
String broker = root[jprop_mqttBrokerUrl];
|
String broker = root[jprop_mqttBrokerUrl];
|
||||||
String oldBroker = jconfig[jprop_mqttBrokerUrl];
|
String oldBroker = jconfig[jprop_mqttBrokerUrl];
|
||||||
if (broker != oldBroker) {
|
if (broker.length() <= 255) {
|
||||||
changed = true;
|
if (broker != oldBroker) {
|
||||||
configLogInfo(String(jprop_mqttBrokerUrl), oldBroker, broker);
|
changed = true;
|
||||||
jconfig[jprop_mqttBrokerUrl] = broker;
|
configLogInfo(String(jprop_mqttBrokerUrl), oldBroker, broker);
|
||||||
|
jconfig[jprop_mqttBrokerUrl] = broker;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
failedMessage = "\"mqttBrokerUrl\" length should <= 255";
|
||||||
|
jsonInvalid();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root[jprop_mqttBrokerUrl], "string")) {
|
if (jsonTypeInvalid(root[jprop_mqttBrokerUrl], "string")) {
|
||||||
@ -528,7 +535,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
configLogInfo(String(jprop_temperatureUnit), oldUnit, unit);
|
configLogInfo(String(jprop_temperatureUnit), oldUnit, unit);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jsonValueInvalidMessage(String(jprop_temperatureUnit), unit);
|
failedMessage = jsonValueInvalidMessage(String(jprop_temperatureUnit), unit);
|
||||||
jsonInvalid();
|
jsonInvalid();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -665,6 +672,20 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
*/
|
*/
|
||||||
String Configuration::toString(void) { return JSON.stringify(jconfig); }
|
String Configuration::toString(void) { return JSON.stringify(jconfig); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get current configuration value as JSON string
|
||||||
|
*
|
||||||
|
* @param fwMode Firmware mode value
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String Configuration::toString(AgFirmwareMode fwMode) {
|
||||||
|
String model = jconfig[jprop_model];
|
||||||
|
jconfig[jprop_model] = AgFirmwareModeName(fwMode);
|
||||||
|
String value = toString();
|
||||||
|
jconfig[jprop_model] = model;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Temperature unit (F or C)
|
* @brief Temperature unit (F or C)
|
||||||
*
|
*
|
||||||
|
@ -48,6 +48,7 @@ public:
|
|||||||
bool begin(void);
|
bool begin(void);
|
||||||
bool parse(String data, bool isLocal);
|
bool parse(String data, bool isLocal);
|
||||||
String toString(void);
|
String toString(void);
|
||||||
|
String toString(AgFirmwareMode fwMode);
|
||||||
bool isTemperatureUnitInF(void);
|
bool isTemperatureUnitInF(void);
|
||||||
String getCountry(void);
|
String getCountry(void);
|
||||||
bool isPmStandardInUSAQI(void);
|
bool isPmStandardInUSAQI(void);
|
||||||
|
@ -394,6 +394,9 @@ StateMachine::~StateMachine() {}
|
|||||||
void StateMachine::displayHandle(AgStateMachineState state) {
|
void StateMachine::displayHandle(AgStateMachineState state) {
|
||||||
// Ignore handle if not ONE_INDOOR board
|
// Ignore handle if not ONE_INDOOR board
|
||||||
if (!ag->isOne()) {
|
if (!ag->isOne()) {
|
||||||
|
if (state == AgStateMachineCo2Calibration) {
|
||||||
|
co2Calibration();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user