mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-15 08:56:34 +02:00
fix: O-1PS not recognized
This commit is contained in:
@ -382,7 +382,9 @@ bool hasSensorS8 = true;
|
|||||||
bool hasSensorPMS = true;
|
bool hasSensorPMS = true;
|
||||||
bool hasSensorSHT = true;
|
bool hasSensorSHT = true;
|
||||||
int pmFailCount = 0;
|
int pmFailCount = 0;
|
||||||
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, updateServerConfiguration);
|
int getCO2FailCount = 0;
|
||||||
|
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
||||||
|
updateServerConfiguration);
|
||||||
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
|
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
|
||||||
AgSchedule dispSchedule(DISP_UPDATE_INTERVAL, dispHandler);
|
AgSchedule dispSchedule(DISP_UPDATE_INTERVAL, dispHandler);
|
||||||
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update);
|
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update);
|
||||||
@ -591,7 +593,7 @@ static void updateServerConfiguration(void) {
|
|||||||
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
||||||
agServer.getCo2AbcDaysConfig(), newHour);
|
agServer.getCo2AbcDaysConfig(), newHour);
|
||||||
int curHour = ag.s8.getAbcPeriod();
|
int curHour = ag.s8.getAbcPeriod();
|
||||||
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
Serial.printf("Current config: %d (hours)\r\n", curHour);
|
||||||
if (curHour == newHour) {
|
if (curHour == newHour) {
|
||||||
Serial.println("set 'abcDays' ignored");
|
Serial.println("set 'abcDays' ignored");
|
||||||
} else {
|
} else {
|
||||||
@ -610,8 +612,18 @@ static void updateServerConfiguration(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void co2Update() {
|
static void co2Update() {
|
||||||
co2Ppm = ag.s8.getCo2();
|
int value = ag.s8.getCo2();
|
||||||
|
if (value >= 0) {
|
||||||
|
co2Ppm = value;
|
||||||
|
getCO2FailCount = 0;
|
||||||
Serial.printf("CO2 index: %d\r\n", co2Ppm);
|
Serial.printf("CO2 index: %d\r\n", co2Ppm);
|
||||||
|
} else {
|
||||||
|
getCO2FailCount++;
|
||||||
|
Serial.printf("Get CO2 failed: %d\r\n", getCO2FailCount);
|
||||||
|
if (getCO2FailCount >= 3) {
|
||||||
|
co2Ppm = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pmUpdate() {
|
void pmUpdate() {
|
||||||
|
@ -712,6 +712,7 @@ bool hasSensorSHT = true;
|
|||||||
int pmFailCount = 0;
|
int pmFailCount = 0;
|
||||||
uint32_t factoryBtnPressTime = 0;
|
uint32_t factoryBtnPressTime = 0;
|
||||||
String mdnsModelName = "";
|
String mdnsModelName = "";
|
||||||
|
int getCO2FailCount = 0;
|
||||||
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate);
|
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate);
|
||||||
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
||||||
updateServerConfiguration);
|
updateServerConfiguration);
|
||||||
@ -910,8 +911,18 @@ static void ledTest2Min(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void co2Update(void) {
|
static void co2Update(void) {
|
||||||
co2Ppm = ag.s8.getCo2();
|
int value = ag.s8.getCo2();
|
||||||
|
if (value >= 0) {
|
||||||
|
co2Ppm = value;
|
||||||
|
getCO2FailCount = 0;
|
||||||
Serial.printf("CO2 index: %d\r\n", co2Ppm);
|
Serial.printf("CO2 index: %d\r\n", co2Ppm);
|
||||||
|
} else {
|
||||||
|
getCO2FailCount++;
|
||||||
|
Serial.printf("Get CO2 failed: %d\r\n", getCO2FailCount);
|
||||||
|
if (getCO2FailCount >= 3) {
|
||||||
|
co2Ppm = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void showNr(void) { Serial.println("Serial nr: " + getDevId()); }
|
static void showNr(void) { Serial.println("Serial nr: " + getDevId()); }
|
||||||
@ -1752,7 +1763,7 @@ static void updateServerConfiguration(void) {
|
|||||||
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
||||||
agServer.getCo2AbcDaysConfig(), newHour);
|
agServer.getCo2AbcDaysConfig(), newHour);
|
||||||
int curHour = ag.s8.getAbcPeriod();
|
int curHour = ag.s8.getAbcPeriod();
|
||||||
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
Serial.printf("Current config: %d (hours)\r\n", curHour);
|
||||||
if (curHour == newHour) {
|
if (curHour == newHour) {
|
||||||
Serial.println("set 'abcDays' ignored");
|
Serial.println("set 'abcDays' ignored");
|
||||||
} else {
|
} else {
|
||||||
|
@ -77,9 +77,9 @@ enum {
|
|||||||
APP_SM_SERVER_LOST, /** Connected to WiFi network but the server cannot be
|
APP_SM_SERVER_LOST, /** Connected to WiFi network but the server cannot be
|
||||||
reached through the internet, e.g. blocked by firewall
|
reached through the internet, e.g. blocked by firewall
|
||||||
*/
|
*/
|
||||||
APP_SM_SENSOR_CONFIG_FAILED, /** Server is reachabFirmware nodele but there is some
|
APP_SM_SENSOR_CONFIG_FAILED, /** Server is reachabFirmware nodele but there is
|
||||||
configuration issue to be fixed on the server
|
some configuration issue to be fixed on the
|
||||||
side */
|
server side */
|
||||||
APP_SM_NORMAL,
|
APP_SM_NORMAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -667,7 +667,7 @@ int tvocIndex = -1;
|
|||||||
int tvocRawIndex = -1;
|
int tvocRawIndex = -1;
|
||||||
int noxIndex = -1;
|
int noxIndex = -1;
|
||||||
int noxRawIndex = -1;
|
int noxRawIndex = -1;
|
||||||
int co2Ppm = 0;
|
int co2Ppm = -1;
|
||||||
|
|
||||||
int pm25_1 = -1;
|
int pm25_1 = -1;
|
||||||
int pm01_1 = -1;
|
int pm01_1 = -1;
|
||||||
@ -728,6 +728,7 @@ bool hasSensorPMS2 = true;
|
|||||||
bool hasSensorSGP = true;
|
bool hasSensorSGP = true;
|
||||||
uint32_t factoryBtnPressTime = 0;
|
uint32_t factoryBtnPressTime = 0;
|
||||||
String mdnsModelName = "";
|
String mdnsModelName = "";
|
||||||
|
int getCO2FailCount = 0;
|
||||||
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
||||||
updateServerConfiguration);
|
updateServerConfiguration);
|
||||||
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
|
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
|
||||||
@ -914,16 +915,35 @@ void boardInit(void) {
|
|||||||
ag.statusLed.begin();
|
ag.statusLed.begin();
|
||||||
|
|
||||||
/** detect sensor: PMS5003, PMS5003T, SGP41 and S8 */
|
/** detect sensor: PMS5003, PMS5003T, SGP41 and S8 */
|
||||||
|
/**
|
||||||
|
* Serial1 and Serial0 is use for connect S8 and PM sensor or both PM
|
||||||
|
*/
|
||||||
|
bool serial1Available = true;
|
||||||
|
bool serial0Available = true;
|
||||||
|
|
||||||
if (ag.s8.begin(Serial1) == false) {
|
if (ag.s8.begin(Serial1) == false) {
|
||||||
|
Serial1.end();
|
||||||
|
delay(200);
|
||||||
|
Serial.println("Can not detect S8 on Serial1, try on Serial0");
|
||||||
|
/** Check on other port */
|
||||||
|
if (ag.s8.begin(Serial0) == false) {
|
||||||
hasSensorS8 = false;
|
hasSensorS8 = false;
|
||||||
|
|
||||||
Serial.println("CO2 S8 sensor not found");
|
Serial.println("CO2 S8 sensor not found");
|
||||||
Serial.println("Can not detect S8 run mode 'PPT'");
|
Serial.println("Can not detect S8 run mode 'PPT'");
|
||||||
fw_mode = FW_MODE_PPT;
|
fw_mode = FW_MODE_PPT;
|
||||||
|
|
||||||
/** De-initialize Serial1 */
|
Serial0.end();
|
||||||
Serial1.end();
|
delay(200);
|
||||||
|
} else {
|
||||||
|
Serial.println("Found S8 on Serial0");
|
||||||
|
serial0Available = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println("Found S8 on Serial1");
|
||||||
|
serial1Available = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (ag.sgp41.begin(Wire) == false) {
|
if (ag.sgp41.begin(Wire) == false) {
|
||||||
hasSensorSGP = false;
|
hasSensorSGP = false;
|
||||||
Serial.println("SGP sensor not found");
|
Serial.println("SGP sensor not found");
|
||||||
@ -932,20 +952,43 @@ void boardInit(void) {
|
|||||||
fw_mode = FW_MODE_PP;
|
fw_mode = FW_MODE_PP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Try to find the PMS on other difference port with S8 */
|
||||||
|
if (fw_mode == FW_MODE_PST) {
|
||||||
|
bool pmInitSuccess = false;
|
||||||
|
if (serial0Available) {
|
||||||
if (ag.pms5003t_1.begin(Serial0) == false) {
|
if (ag.pms5003t_1.begin(Serial0) == false) {
|
||||||
hasSensorPMS1 = false;
|
hasSensorPMS1 = false;
|
||||||
Serial.println("PMS1 sensor not found");
|
Serial.println("PMS1 sensor not found");
|
||||||
|
} else {
|
||||||
if (ag.pms5003t_2.begin(Serial1) == false) {
|
serial0Available = false;
|
||||||
hasSensorPMS2 = false;
|
pmInitSuccess = true;
|
||||||
Serial.println("PMS2 sensor not found");
|
Serial.println("Found PMS 1 on Serial0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pmInitSuccess == false) {
|
||||||
if (fw_mode != FW_MODE_PST) {
|
if (serial1Available) {
|
||||||
|
if (ag.pms5003t_1.begin(Serial1) == false) {
|
||||||
|
hasSensorPMS1 = false;
|
||||||
|
Serial.println("PMS1 sensor not found");
|
||||||
|
} else {
|
||||||
|
serial1Available = false;
|
||||||
|
Serial.println("Found PMS 1 on Serial1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hasSensorPMS2 = false; // Disable PM2
|
||||||
|
} else {
|
||||||
|
if (ag.pms5003t_1.begin(Serial0) == false) {
|
||||||
|
hasSensorPMS1 = false;
|
||||||
|
Serial.println("PMS1 sensor not found");
|
||||||
|
} else {
|
||||||
|
Serial.println("Found PMS 1 on Serial0");
|
||||||
|
}
|
||||||
if (ag.pms5003t_2.begin(Serial1) == false) {
|
if (ag.pms5003t_2.begin(Serial1) == false) {
|
||||||
hasSensorPMS2 = false;
|
hasSensorPMS2 = false;
|
||||||
Serial.println("PMS2 sensor not found");
|
Serial.println("PMS2 sensor not found");
|
||||||
|
} else {
|
||||||
|
Serial.println("Found PMS 2 on Serial1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1142,8 +1185,18 @@ static void pmUpdate(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void co2Update(void) {
|
static void co2Update(void) {
|
||||||
co2Ppm = ag.s8.getCo2();
|
int value = ag.s8.getCo2();
|
||||||
|
if (value >= 0) {
|
||||||
|
co2Ppm = value;
|
||||||
|
getCO2FailCount = 0;
|
||||||
Serial.printf("CO2 index: %d\r\n", co2Ppm);
|
Serial.printf("CO2 index: %d\r\n", co2Ppm);
|
||||||
|
} else {
|
||||||
|
getCO2FailCount++;
|
||||||
|
Serial.printf("Get CO2 failed: %d\r\n", getCO2FailCount);
|
||||||
|
if (getCO2FailCount >= 3) {
|
||||||
|
co2Ppm = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateServerConfiguration(void) {
|
static void updateServerConfiguration(void) {
|
||||||
@ -1164,7 +1217,7 @@ static void updateServerConfiguration(void) {
|
|||||||
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
Serial.printf("abcDays config: %d days(%d hours)\r\n",
|
||||||
agServer.getCo2AbcDaysConfig(), newHour);
|
agServer.getCo2AbcDaysConfig(), newHour);
|
||||||
int curHour = ag.s8.getAbcPeriod();
|
int curHour = ag.s8.getAbcPeriod();
|
||||||
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
|
Serial.printf("Current config: %d (hours)\r\n", curHour);
|
||||||
if (curHour == newHour) {
|
if (curHour == newHour) {
|
||||||
Serial.println("set 'abcDays' ignored");
|
Serial.println("set 'abcDays' ignored");
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,7 @@ void setup()
|
|||||||
if (ag.s8.begin(&Serial) == false)
|
if (ag.s8.begin(&Serial) == false)
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
if (ag.s8.begin(Serial1) == false)
|
if (ag.s8.begin(Serial0) == false)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
failedHandler("SenseAir S8 init failed");
|
failedHandler("SenseAir S8 init failed");
|
||||||
|
@ -79,19 +79,21 @@ bool PMS5003T::begin(void) {
|
|||||||
|
|
||||||
#if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
|
#if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
|
||||||
if (this->_serial == &Serial0) {
|
if (this->_serial == &Serial0) {
|
||||||
|
AgLog("Init Serial0");
|
||||||
|
_serial->begin(9600, SERIAL_8N1);
|
||||||
#else
|
#else
|
||||||
if (this->_serial == &Serial) {
|
if (this->_serial == &Serial) {
|
||||||
#endif
|
|
||||||
AgLog("Init Serial");
|
AgLog("Init Serial");
|
||||||
this->_serial->begin(9600, SERIAL_8N1, bsp->Pms5003.uart_rx_pin,
|
this->_serial->begin(9600, SERIAL_8N1, bsp->Pms5003.uart_rx_pin,
|
||||||
bsp->Pms5003.uart_tx_pin);
|
bsp->Pms5003.uart_tx_pin);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
/** Share with sensor air s8*/
|
||||||
if (bsp->SenseAirS8.supported == false) {
|
if (bsp->SenseAirS8.supported == false) {
|
||||||
AgLog("Board [%d] PMS5003T_2 not supported", this->_boardDef);
|
AgLog("Board [%d] PMS5003T_2 not supported", this->_boardDef);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Share with sensor air s8*/
|
|
||||||
AgLog("Init Serialx");
|
AgLog("Init Serialx");
|
||||||
this->_serial->begin(9600, SERIAL_8N1, bsp->SenseAirS8.uart_rx_pin,
|
this->_serial->begin(9600, SERIAL_8N1, bsp->SenseAirS8.uart_rx_pin,
|
||||||
bsp->SenseAirS8.uart_tx_pin);
|
bsp->SenseAirS8.uart_tx_pin);
|
||||||
|
@ -228,7 +228,7 @@ int16_t S8::getCo2(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t co2 = 0;
|
int16_t co2 = -1;
|
||||||
|
|
||||||
// Ask CO2 value
|
// Ask CO2 value
|
||||||
sendCommand(MODBUS_FUNC_READ_INPUT_REGISTERS, MODBUS_IR4, 0x0001);
|
sendCommand(MODBUS_FUNC_READ_INPUT_REGISTERS, MODBUS_IR4, 0x0001);
|
||||||
@ -649,11 +649,25 @@ bool S8::init(int txPin, int rxPin, uint32_t baud) {
|
|||||||
uart->begin(baud);
|
uart->begin(baud);
|
||||||
this->_uartStream = uart;
|
this->_uartStream = uart;
|
||||||
#else
|
#else
|
||||||
|
#if ARDUINO_USB_CDC_ON_BOOT
|
||||||
|
/** The 'Serial0' can ont configure tx, rx pin, only use as default */
|
||||||
|
if (_serial == &Serial0) {
|
||||||
|
AgLog("Init on 'Serial0'");
|
||||||
|
_serial->begin(baud, SERIAL_8N1);
|
||||||
|
} else {
|
||||||
|
AgLog("Init on 'Serialx'");
|
||||||
|
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
|
||||||
|
}
|
||||||
|
this->_uartStream = this->_serial;
|
||||||
|
#else
|
||||||
|
AgLog("Init on 'Serialx'");
|
||||||
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
|
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
|
||||||
this->_uartStream = this->_serial;
|
this->_uartStream = this->_serial;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Check communication by get firmware version */
|
/** Check communication by get firmware version */
|
||||||
|
delay(100);
|
||||||
char fwVers[11];
|
char fwVers[11];
|
||||||
this->_isBegin = true;
|
this->_isBegin = true;
|
||||||
this->getFirmwareVersion(fwVers);
|
this->getFirmwareVersion(fwVers);
|
||||||
@ -712,7 +726,7 @@ uint8_t S8::uartReadBytes(uint8_t max_bytes, uint32_t timeout_ms) {
|
|||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
// Relax 5ms to avoid watchdog reset
|
// Relax 5ms to avoid watchdog reset
|
||||||
vTaskDelay(pdMS_TO_TICKS(5));
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return nb;
|
return nb;
|
||||||
|
@ -91,7 +91,7 @@ void Sgp41::handle(void) {
|
|||||||
if (getRawSignal(srawVoc, srawNox)) {
|
if (getRawSignal(srawVoc, srawNox)) {
|
||||||
nox = noxAlgorithm()->process(srawNox);
|
nox = noxAlgorithm()->process(srawNox);
|
||||||
tvoc = vocAlgorithm()->process(srawVoc);
|
tvoc = vocAlgorithm()->process(srawVoc);
|
||||||
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
|
// AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ void Sgp41::_handle(void) {
|
|||||||
noxRaw = srawNox;
|
noxRaw = srawNox;
|
||||||
nox = noxAlgorithm()->process(srawNox);
|
nox = noxAlgorithm()->process(srawNox);
|
||||||
tvoc = vocAlgorithm()->process(srawVoc);
|
tvoc = vocAlgorithm()->process(srawVoc);
|
||||||
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
|
// AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user