Compare commits

...

3 Commits

Author SHA1 Message Date
samuelbles07
ba250787e6 WIP - trial energy saving 2025-10-13 02:58:11 +07:00
Samuel Siburian
23f8c383fd Merge pull request #345 from airgradienthq/feat/print-s8-info
Print S8 sensor information
2025-10-02 19:22:22 +07:00
samuelbles07
c0ad1dbfad Print S8 sensor information 2025-10-02 19:18:59 +07:00
7 changed files with 112 additions and 22 deletions

View File

@@ -175,6 +175,9 @@ AgSchedule checkForUpdateSchedule(FIRMWARE_CHECK_FOR_UPDATE_MS, checkForFirmware
AgSchedule networkSignalCheckSchedule(10000, networkSignalCheck); AgSchedule networkSignalCheckSchedule(10000, networkSignalCheck);
AgSchedule printMeasurementsSchedule(6000, printMeasurements); AgSchedule printMeasurementsSchedule(6000, printMeasurements);
static int pmsValueTaken = 0;
void setup() { void setup() {
/** Serial for print debug message */ /** Serial for print debug message */
Serial.begin(115200); Serial.begin(115200);
@@ -275,6 +278,9 @@ void setup() {
} }
configSchedule.setPeriod(CELLULAR_TRANSMISSION_INTERVAL);
transmissionSchedule.setPeriod(CELLULAR_TRANSMISSION_INTERVAL);
if (networkOption == UseCellular) { if (networkOption == UseCellular) {
// If using cellular re-set scheduler interval // If using cellular re-set scheduler interval
configSchedule.setPeriod(CELLULAR_SERVER_CONFIG_SYNC_INTERVAL); configSchedule.setPeriod(CELLULAR_SERVER_CONFIG_SYNC_INTERVAL);
@@ -347,6 +353,8 @@ void loop() {
if (configuration.hasSensorSGP) { if (configuration.hasSensorSGP) {
tvocSchedule.run(); tvocSchedule.run();
} }
if (pmsValueTaken < 60) {
if (ag->isOne()) { if (ag->isOne()) {
if (configuration.hasSensorPMS1) { if (configuration.hasSensorPMS1) {
ag->pms5003.handle(); ag->pms5003.handle();
@@ -364,6 +372,7 @@ void loop() {
ag->pms5003t_2.handle(); ag->pms5003t_2.handle();
} }
} }
}
/* Run measurement schedule */ /* Run measurement schedule */
printMeasurementsSchedule.run(); printMeasurementsSchedule.run();
@@ -952,6 +961,8 @@ static void boardInit(void) {
} else { } else {
Serial.println("Set S8 AbcDays failure"); Serial.println("Set S8 AbcDays failure");
} }
ag->s8.printInformation();
} }
localServer.setFwMode(fwMode); localServer.setFwMode(fwMode);
@@ -1237,6 +1248,16 @@ static void updateTvoc(void) {
} }
static void updatePMS5003() { static void updatePMS5003() {
pmsValueTaken++;
if (pmsValueTaken >= 60) {
if (pmsValueTaken == 60) {
ag->pms5003.sleep();
Serial.println("PMS go sleep");
}
return;
}
if (ag->pms5003.connected()) { if (ag->pms5003.connected()) {
measurements.update(Measurements::PM01, ag->pms5003.getPm01Ae()); measurements.update(Measurements::PM01, ag->pms5003.getPm01Ae());
measurements.update(Measurements::PM25, ag->pms5003.getPm25Ae()); measurements.update(Measurements::PM25, ag->pms5003.getPm25Ae());
@@ -1459,6 +1480,11 @@ void sendDataToServer(void) {
} else if (networkOption == UseCellular) { } else if (networkOption == UseCellular) {
postUsingCellular(false); postUsingCellular(false);
} }
pmsValueTaken = 0;
ag->pms5003.wakeUp();
ag->pms5003.activeMode();
Serial.println("run PMS again");
} }
static void tempHumUpdate(void) { static void tempHumUpdate(void) {

View File

@@ -21,10 +21,15 @@ bool PMSBase::begin(Stream *stream) {
} }
Serial.printf("cleared %d byte(s)\n", bytesCleared); Serial.printf("cleared %d byte(s)\n", bytesCleared);
uint8_t command[] = {0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74};
size_t bytesWritten = stream->write(command, sizeof(command));
Serial.printf("%d byte(s) written\n", bytesWritten);
// explicitly put the sensor into active mode, this seems to be be needed for the Cubic PM2009X // explicitly put the sensor into active mode, this seems to be be needed for the Cubic PM2009X
Serial.printf("setting active mode\n"); Serial.printf("setting active mode\n");
uint8_t activeModeCommand[] = { 0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71 }; uint8_t activeModeCommand[] = {0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71};
size_t bytesWritten = stream->write(activeModeCommand, sizeof(activeModeCommand)); bytesWritten = stream->write(activeModeCommand, sizeof(activeModeCommand));
Serial.printf("%d byte(s) written\n", bytesWritten); Serial.printf("%d byte(s) written\n", bytesWritten);
// Run and check sensor data for 4sec // Run and check sensor data for 4sec
@@ -314,7 +319,6 @@ int PMSBase::pm25ToAQI(int pm02) {
return 500; return 500;
} }
/** /**
* @brief SLR correction for PM2.5 * @brief SLR correction for PM2.5
* *

View File

@@ -84,7 +84,7 @@ private:
int16_t toI16(const uint8_t *buf); int16_t toI16(const uint8_t *buf);
uint16_t toU16(const uint8_t *buf); uint16_t toU16(const uint8_t *buf);
bool validate(const uint8_t *buf); bool validate(const uint8_t *buf);
void parse(const uint8_t* buf); void parse(const uint8_t *buf);
}; };
#endif /** _PMS5003_BASE_H_ */ #endif /** _PMS5003_BASE_H_ */

View File

@@ -266,3 +266,44 @@ int PMS5003::getFailCount(void) { return pms.getFailCount(); }
* @return int * @return int
*/ */
int PMS5003::getFailCountMax(void) { return pms.getFailCountMax(); } int PMS5003::getFailCountMax(void) { return pms.getFailCountMax(); }
// Standby mode. For low power consumption and prolong the life of the sensor.
void PMS5003::sleep() {
uint8_t command[] = {0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73};
size_t bytesWritten = this->_serial->write(command, sizeof(command));
Serial.printf("%d byte(s) written\n", bytesWritten);
}
// Operating mode. Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan's performance.
void PMS5003::wakeUp() {
uint8_t command[] = {0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74};
size_t bytesWritten = this->_serial->write(command, sizeof(command));
Serial.printf("%d byte(s) written\n", bytesWritten);
}
// Active mode. Default mode after power up. In this mode sensor would send serial data to the host automatically.
void PMS5003::activeMode() {
uint8_t command[] = {0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71};
size_t bytesWritten = this->_serial->write(command, sizeof(command));
Serial.printf("%d byte(s) written\n", bytesWritten);
// _mode = MODE_ACTIVE;
}
// Passive mode. In this mode sensor would send serial data to the host only for request.
void PMS5003::passiveMode() {
uint8_t command[] = {0x42, 0x4D, 0xE1, 0x00, 0x00, 0x01, 0x70};
size_t bytesWritten = this->_serial->write(command, sizeof(command));
Serial.printf("%d byte(s) written\n", bytesWritten);
// _mode = MODE_PASSIVE;
}
// Request read in Passive Mode.
void PMS5003::requestRead() {
// if (_mode == MODE_PASSIVE)
// {
uint8_t command[] = {0x42, 0x4D, 0xE2, 0x00, 0x00, 0x01, 0x71};
size_t bytesWritten = this->_serial->write(command, sizeof(command));
Serial.printf("%d byte(s) written\n", bytesWritten);
// }
}

View File

@@ -19,6 +19,14 @@ public:
#else #else
bool begin(HardwareSerial &serial); bool begin(HardwareSerial &serial);
#endif #endif
// Modes
void sleep();
void wakeUp();
void activeMode();
void passiveMode();
void requestRead();
void end(void); void end(void);
void handle(void); void handle(void);
void updateFailCount(void); void updateFailCount(void);

View File

@@ -835,3 +835,13 @@ bool S8::setAbcPeriod(int hours) {
* @return int Hour * @return int Hour
*/ */
int S8::getAbcPeriod(void) { return getCalibPeriodABC(); } int S8::getAbcPeriod(void) { return getCalibPeriodABC(); }
void S8::printInformation(void) {
Serial.print("S8 type ID: 0x");
Serial.println(getSensorTypeId(), HEX);
Serial.print("S8 serial number: 0x");
Serial.println(getSensorId(), HEX);
Serial.print("S8 memory map version: 0x");
Serial.println(getMemoryMapVersion(), HEX);
}

View File

@@ -80,6 +80,7 @@ public:
bool isBaseLineCalibrationDone(void); bool isBaseLineCalibrationDone(void);
bool setAbcPeriod(int hours); bool setAbcPeriod(int hours);
int getAbcPeriod(void); int getAbcPeriod(void);
void printInformation(void);
private: private:
/** Variables */ /** Variables */