mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-06-26 08:11:33 +02:00
Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
fd2cef153e | |||
507b958fdf | |||
335c29ebb1 | |||
2907d6f14e | |||
c8d5b546ed | |||
b7cfdc4c4d | |||
994d281e02 | |||
39470384e4 | |||
c25ba764bf | |||
826ff00f42 | |||
520550037d | |||
90f336dee7 | |||
0d39643e76 | |||
b7339de31f | |||
013fb94307 | |||
e16373a64d | |||
f929623443 | |||
59587ce2b7 | |||
9ec74450a5 | |||
28096e9faf | |||
682378a47c | |||
a1861be7b7 | |||
99ddd24432 | |||
03e2afbf54 |
@ -513,6 +513,7 @@ static void updatePm(void) {
|
||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||
Serial.printf("PM firmware version: %d\r\n", ag.pms5003.getFirmwareVersion());
|
||||
ag.pms5003.resetFailCount();
|
||||
} else {
|
||||
ag.pms5003.updateFailCount();
|
||||
|
@ -565,6 +565,7 @@ static void updatePm(void) {
|
||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||
Serial.printf("PM firmware version: %d\r\n", ag.pms5003.getFirmwareVersion());
|
||||
ag.pms5003.resetFailCount();
|
||||
} else {
|
||||
ag.pms5003.updateFailCount();
|
||||
|
@ -327,9 +327,7 @@ static void factoryConfigReset(void) {
|
||||
// }
|
||||
|
||||
/** Reset WIFI */
|
||||
// WiFi.enableSTA(true); // Incase offline mode
|
||||
// WiFi.disconnect(true, true);
|
||||
wifiConnector.reset();
|
||||
WiFi.disconnect(true, true);
|
||||
|
||||
/** Reset local config */
|
||||
configuration.reset();
|
||||
@ -608,6 +606,7 @@ static void updatePm(void) {
|
||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||
Serial.printf("PM firmware version: %d\r\n", ag.pms5003.getFirmwareVersion());
|
||||
ag.pms5003.resetFailCount();
|
||||
} else {
|
||||
ag.pms5003.updateFailCount();
|
||||
|
@ -423,8 +423,7 @@ static void factoryConfigReset(void) {
|
||||
}
|
||||
|
||||
/** Reset WIFI */
|
||||
Serial.println("Set wifi connect to 'airgradient' as default");
|
||||
WiFi.begin("airgradient", "cleanair");
|
||||
WiFi.disconnect(true, true);
|
||||
|
||||
/** Reset local config */
|
||||
configuration.reset();
|
||||
@ -698,7 +697,7 @@ static void oneIndoorInit(void) {
|
||||
ledBarEnabledUpdate();
|
||||
|
||||
/** Show message init sensor */
|
||||
oledDisplay.setText("Sensor", "initializing...", "");
|
||||
oledDisplay.setText("Monitor", "initializing...", "");
|
||||
|
||||
/** Init sensor SGP41 */
|
||||
if (sgp41Init() == false) {
|
||||
@ -779,27 +778,27 @@ static void openAirInit(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Try to find the PMS on other difference port with S8 */
|
||||
/** Attempt to detect PM sensors */
|
||||
if (fwMode == FW_MODE_O_1PST) {
|
||||
bool pmInitSuccess = false;
|
||||
if (serial0Available) {
|
||||
if (ag->pms5003t_1.begin(Serial0) == false) {
|
||||
configuration.hasSensorPMS1 = false;
|
||||
Serial.println("PMS1 sensor not found");
|
||||
Serial.println("No PM sensor detected on Serial0");
|
||||
} else {
|
||||
serial0Available = false;
|
||||
pmInitSuccess = true;
|
||||
Serial.println("Found PMS 1 on Serial0");
|
||||
Serial.println("Detected PM 1 on Serial0");
|
||||
}
|
||||
}
|
||||
if (pmInitSuccess == false) {
|
||||
if (serial1Available) {
|
||||
if (ag->pms5003t_1.begin(Serial1) == false) {
|
||||
configuration.hasSensorPMS1 = false;
|
||||
Serial.println("PMS1 sensor not found");
|
||||
Serial.println("No PM sensor detected on Serial1");
|
||||
} else {
|
||||
serial1Available = false;
|
||||
Serial.println("Found PMS 1 on Serial1");
|
||||
Serial.println("Detected PM 1 on Serial1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -807,15 +806,15 @@ static void openAirInit(void) {
|
||||
} else {
|
||||
if (ag->pms5003t_1.begin(Serial0) == false) {
|
||||
configuration.hasSensorPMS1 = false;
|
||||
Serial.println("PMS1 sensor not found");
|
||||
Serial.println("No PM sensor detected on Serial0");
|
||||
} else {
|
||||
Serial.println("Found PMS 1 on Serial0");
|
||||
Serial.println("Detected PM 1 on Serial0");
|
||||
}
|
||||
if (ag->pms5003t_2.begin(Serial1) == false) {
|
||||
configuration.hasSensorPMS2 = false;
|
||||
Serial.println("PMS2 sensor not found");
|
||||
Serial.println("No PM sensor detected on Serial1");
|
||||
} else {
|
||||
Serial.println("Found PMS 2 on Serial1");
|
||||
Serial.println("Detected PM 2 on Serial1");
|
||||
}
|
||||
|
||||
if (fwMode == FW_MODE_O_1PP) {
|
||||
@ -1021,10 +1020,11 @@ static void updatePm(void) {
|
||||
Serial.printf("PM2.5 ug/m3: %d\r\n", measurements.pm25_1);
|
||||
Serial.printf("PM10 ug/m3: %d\r\n", measurements.pm10_1);
|
||||
Serial.printf("PM0.3 Count: %d\r\n", measurements.pm03PCount_1);
|
||||
Serial.printf("PM firmware version: %d\r\n", ag->pms5003.getFirmwareVersion());
|
||||
ag->pms5003.resetFailCount();
|
||||
} else {
|
||||
ag->pms5003.updateFailCount();
|
||||
Serial.printf("PMS read faile %d times\r\n", ag->pms5003.getFailCount());
|
||||
Serial.printf("PMS read failed %d times\r\n", ag->pms5003.getFailCount());
|
||||
if (ag->pms5003.getFailCount() >= PMS_FAIL_COUNT_SET_INVALID) {
|
||||
measurements.pm01_1 = utils::getInvalidPmValue();
|
||||
measurements.pm25_1 = utils::getInvalidPmValue();
|
||||
@ -1060,6 +1060,7 @@ static void updatePm(void) {
|
||||
ag->pms5003t_1.compensateTemp(measurements.temp_1));
|
||||
Serial.printf("[1] Relative Humidity compensated: %0.2f\r\n",
|
||||
ag->pms5003t_1.compensateHum(measurements.hum_1));
|
||||
Serial.printf("[1] PM firmware version: %d\r\n", ag->pms5003t_1.getFirmwareVersion());
|
||||
|
||||
ag->pms5003t_1.resetFailCount();
|
||||
} else {
|
||||
@ -1103,6 +1104,7 @@ static void updatePm(void) {
|
||||
ag->pms5003t_1.compensateTemp(measurements.temp_2));
|
||||
Serial.printf("[2] Relative Humidity compensated: %0.2f\r\n",
|
||||
ag->pms5003t_1.compensateHum(measurements.hum_2));
|
||||
Serial.printf("[2] PM firmware version: %d\r\n", ag->pms5003t_2.getFirmwareVersion());
|
||||
|
||||
ag->pms5003t_2.resetFailCount();
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AirGradient Air Quality Sensor
|
||||
version=3.1.6
|
||||
version=3.1.8
|
||||
author=AirGradient <support@airgradient.com>
|
||||
maintainer=AirGradient <support@airgradient.com>
|
||||
sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display.
|
||||
|
@ -58,6 +58,7 @@ bool AgApiClient::fetchServerConfiguration(void) {
|
||||
}
|
||||
#else
|
||||
HTTPClient client;
|
||||
client.setTimeout(timeoutMs);
|
||||
if (client.begin(uri) == false) {
|
||||
getConfigFailed = true;
|
||||
return false;
|
||||
@ -113,14 +114,13 @@ bool AgApiClient::postToServer(String data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String uri =
|
||||
"http://hw.airgradient.com/sensors/airgradient:" + ag->deviceId() +
|
||||
"/measures";
|
||||
String uri = apiRoot + "/sensors/airgradient:" + ag->deviceId() + "/measures";
|
||||
// logInfo("Post uri: " + uri);
|
||||
// logInfo("Post data: " + data);
|
||||
|
||||
WiFiClient wifiClient;
|
||||
HTTPClient client;
|
||||
client.setTimeout(timeoutMs);
|
||||
if (client.begin(wifiClient, uri.c_str()) == false) {
|
||||
logError("Init client failed");
|
||||
return false;
|
||||
@ -190,3 +190,12 @@ bool AgApiClient::sendPing(int rssi, int bootCount) {
|
||||
String AgApiClient::getApiRoot() const { return apiRoot; }
|
||||
|
||||
void AgApiClient::setApiRoot(const String &apiRoot) { this->apiRoot = apiRoot; }
|
||||
|
||||
/**
|
||||
* @brief Set http request timeout. (Default: 10s)
|
||||
*
|
||||
* @param timeoutMs
|
||||
*/
|
||||
void AgApiClient::setTimeout(uint16_t timeoutMs) {
|
||||
this->timeoutMs = timeoutMs;
|
||||
}
|
@ -25,6 +25,7 @@ private:
|
||||
bool getConfigFailed;
|
||||
bool postToServerFailed;
|
||||
bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard.
|
||||
uint16_t timeoutMs = 10000; // Default set to 10s
|
||||
|
||||
public:
|
||||
AgApiClient(Stream &stream, Configuration &config);
|
||||
@ -40,6 +41,7 @@ public:
|
||||
bool sendPing(int rssi, int bootCount);
|
||||
String getApiRoot() const;
|
||||
void setApiRoot(const String &apiRoot);
|
||||
void setTimeout(uint16_t timeoutMs);
|
||||
};
|
||||
|
||||
#endif /** _AG_API_CLIENT_H_ */
|
||||
|
@ -519,7 +519,7 @@ void OledDisplay::showRebooting(void) {
|
||||
do {
|
||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||
// setCentralText(20, "Firmware Update");
|
||||
setCentralText(40, "Reboot...");
|
||||
setCentralText(40, "Rebooting...");
|
||||
// setCentralText(60, String("Retry after 24h"));
|
||||
} while (DISP()->nextPage());
|
||||
} else if (ag->isBasic()) {
|
||||
|
@ -141,7 +141,7 @@ void StateMachine::co2handleLeds(void) {
|
||||
*
|
||||
*/
|
||||
void StateMachine::pm25handleLeds(void) {
|
||||
int pm25Value = value.pm25_1;
|
||||
int pm25Value = ag->pms5003.compensate(value.pm25_1, value.Humidity);
|
||||
if (pm25Value < 5) {
|
||||
/** G; 1 */
|
||||
ag->ledBar.setColor(RGB_COLOR_G, ag->ledBar.getNumberOfLeds() - 1);
|
||||
|
@ -130,8 +130,8 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
|
||||
int pm25 = (ag->pms5003t_1.compensate(this->pm25_1, this->temp_1) +
|
||||
ag->pms5003t_2.compensate(this->pm25_2, this->temp_2)) /
|
||||
int pm25 = (ag->pms5003t_1.compensate(this->pm25_1, this->hum_1) +
|
||||
ag->pms5003t_2.compensate(this->pm25_2, this->hum_2)) /
|
||||
2;
|
||||
root["pm02Compensated"] = pm25;
|
||||
}
|
||||
@ -171,7 +171,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
}
|
||||
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
||||
if (!localServer) {
|
||||
root[json_prop_pmFirmware] =
|
||||
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||
@ -212,7 +212,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
}
|
||||
root["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->temp_2);
|
||||
root["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->hum_2);
|
||||
if(!localServer) {
|
||||
root[json_prop_pmFirmware] =
|
||||
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||
@ -253,7 +253,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
}
|
||||
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
||||
if(!localServer) {
|
||||
root[json_prop_pmFirmware] =
|
||||
pms5003TFirmwareVersion(ag->pms5003t_1.getFirmwareVersion());
|
||||
@ -291,7 +291,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
}
|
||||
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||
root["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
||||
if(!localServer) {
|
||||
root[json_prop_pmFirmware] =
|
||||
pms5003TFirmwareVersion(ag->pms5003t_2.getFirmwareVersion());
|
||||
@ -332,7 +332,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
}
|
||||
root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->temp_1);
|
||||
root["channels"]["1"]["pm02Compensated"] = ag->pms5003t_1.compensate(this->pm25_1, this->hum_1);
|
||||
|
||||
// PMS5003T version
|
||||
if(!localServer) {
|
||||
@ -374,7 +374,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
|
||||
}
|
||||
}
|
||||
}
|
||||
root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->temp_2);
|
||||
root["channels"]["2"]["pm02Compensated"] = ag->pms5003t_2.compensate(this->pm25_2, this->hum_2);
|
||||
// PMS5003T version
|
||||
if(!localServer) {
|
||||
root["channels"]["2"][json_prop_pmFirmware] =
|
||||
|
@ -41,6 +41,28 @@ bool WifiConnector::connect(void) {
|
||||
}
|
||||
}
|
||||
|
||||
WiFi.begin();
|
||||
String wifiSSID = WIFI()->getWiFiSSID(true);
|
||||
if (wifiSSID.isEmpty()) {
|
||||
logInfo("Connected WiFi is empty, connect to default wifi \"" +
|
||||
String(this->defaultSsid) + String("\""));
|
||||
|
||||
/** Set wifi connect */
|
||||
WiFi.begin(this->defaultSsid, this->defaultPassword);
|
||||
|
||||
/** Wait for wifi connect to AP */
|
||||
int count = 0;
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(1000);
|
||||
count++;
|
||||
if (count >= 15) {
|
||||
logError("Try connect to default wifi \"" + String(this->defaultSsid) +
|
||||
String("\" failed"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WIFI()->setConfigPortalBlocking(false);
|
||||
WIFI()->setConnectTimeout(15);
|
||||
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||
@ -50,7 +72,7 @@ bool WifiConnector::connect(void) {
|
||||
WIFI()->setSaveParamsCallback([this]() { _wifiSaveParamCallback(); });
|
||||
WIFI()->setConfigPortalTimeoutCallback([this]() {_wifiTimeoutCallback();});
|
||||
if (ag->isOne() || (ag->isPro4_2()) || ag->isPro3_3() || ag->isBasic()) {
|
||||
disp.setText("Connect to", "WiFi", "...");
|
||||
disp.setText("Connecting to", "WiFi", "...");
|
||||
} else {
|
||||
logInfo("Connecting to WiFi...");
|
||||
}
|
||||
@ -383,3 +405,11 @@ bool WifiConnector::hasConfigurated(void) {
|
||||
* @return false
|
||||
*/
|
||||
bool WifiConnector::isConfigurePorttalTimeout(void) { return connectorTimeout; }
|
||||
|
||||
/**
|
||||
* @brief Set wifi connect to default WiFi
|
||||
*
|
||||
*/
|
||||
void WifiConnector::setDefault(void) {
|
||||
WiFi.begin("airgradient", "cleanair");
|
||||
}
|
||||
|
@ -46,6 +46,10 @@ public:
|
||||
String localIpStr(void);
|
||||
bool hasConfigurated(void);
|
||||
bool isConfigurePorttalTimeout(void);
|
||||
|
||||
const char* defaultSsid = "airgradient";
|
||||
const char* defaultPassword = "cleanair";
|
||||
void setDefault(void);
|
||||
};
|
||||
|
||||
#endif /** _AG_WIFI_CONNECTOR_H_ */
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "Main/utils.h"
|
||||
|
||||
#ifndef GIT_VERSION
|
||||
#define GIT_VERSION "3.1.6-snap"
|
||||
#define GIT_VERSION "3.1.8-snap"
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -2,34 +2,48 @@
|
||||
#include "../Main/BoardDef.h"
|
||||
|
||||
/**
|
||||
* @brief Init and check that sensor has connected
|
||||
* @brief Initializes the sensor and attempts to read data.
|
||||
*
|
||||
* @param stream UART stream
|
||||
* @return true Sucecss
|
||||
* @return false Failure
|
||||
*/
|
||||
bool PMSBase::begin(Stream *stream) {
|
||||
Serial.printf("initializing PM sensor\n");
|
||||
this->stream = stream;
|
||||
|
||||
failed = true;
|
||||
failCount = 0;
|
||||
lastRead = 0; // To read buffer on handle without wait after 1.5sec
|
||||
|
||||
this->stream->flush();
|
||||
// empty first
|
||||
int bytesCleared = 0;
|
||||
while (this->stream->read() != -1) {
|
||||
bytesCleared++;
|
||||
}
|
||||
Serial.printf("cleared %d byte(s)\n", bytesCleared);
|
||||
|
||||
// explicitly put the sensor into active mode, this seems to be be needed for the Cubic PM2009X
|
||||
Serial.printf("setting active mode\n");
|
||||
uint8_t activeModeCommand[] = { 0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71 };
|
||||
size_t bytesWritten = this->stream->write(activeModeCommand, sizeof(activeModeCommand));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
|
||||
// Run and check sensor data for 4sec
|
||||
while (1) {
|
||||
handle();
|
||||
if (failed == false) {
|
||||
return true;
|
||||
Serial.printf("PM sensor initialized\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
delay(1);
|
||||
delay(10);
|
||||
uint32_t ms = (uint32_t)(millis() - lastRead);
|
||||
if (ms >= 4000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.printf("PM sensor initialization failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
#define PMS_FAIL_COUNT_SET_INVALID 3
|
||||
|
||||
/**
|
||||
* Known to work with these sensors: Plantower PMS5003, Plantower PMS5003, Cubic PM2009X
|
||||
*/
|
||||
class PMSBase {
|
||||
public:
|
||||
bool begin(Stream *stream);
|
||||
|
@ -38,14 +38,11 @@ bool PMS5003::begin(HardwareSerial &serial) {
|
||||
PMS5003::PMS5003(BoardType def) : _boardDef(def) {}
|
||||
|
||||
/**
|
||||
* @brief Init sensor
|
||||
*
|
||||
* @return true Success
|
||||
* @return false Failure
|
||||
* Initializes the sensor.
|
||||
*/
|
||||
bool PMS5003::begin(void) {
|
||||
if (this->_isBegin) {
|
||||
AgLog("Initialized, call end() then try again");
|
||||
AgLog("Already initialized, call end() then try again");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user