Compare commits

...

7 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
Samuel Siburian
75be7d9fc5 Merge pull request #342 from mtlynch/no-trailing-spaces
Eliminate trailing whitespace
2025-09-25 13:45:11 +07:00
Samuel Siburian
309d322100 Merge pull request #343 from sysboy/typo-fix-failuire
Simple typo fix
2025-09-25 11:37:54 +07:00
Steve
89ebe6c39f Simple typo fix 2025-09-23 15:40:36 +01:00
Michael Lynch
29db5469f5 Eliminate trailing whitespace 2025-09-17 20:06:50 -04:00
30 changed files with 264 additions and 143 deletions

View File

@@ -1,5 +1,36 @@
on: [push, pull_request]
jobs:
trailing-whitespace:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
- name: Check for trailing whitespace
run: |
set -u
# Don't enforce checks on vendored libraries.
readonly EXCLUDED_DIR='src/Libraries'
has_trailing_whitespace=false
while read -r line; do
if grep \
"\s$" \
--line-number \
--with-filename \
--binary-files=without-match \
"${line}"; then
has_trailing_whitespace=true
fi
done < <(git ls-files | grep --invert-match "^${EXCLUDED_DIR}/")
if [ "$has_trailing_whitespace" = true ]; then
echo "ERROR: Found trailing whitespace"
exit 1
fi
compile:
strategy:
fail-fast: false

View File

@@ -294,7 +294,7 @@ static bool sgp41Init(void) {
configuration.hasSensorSGP = true;
return true;
} else {
Serial.println("Init SGP41 failuire");
Serial.println("Init SGP41 failure");
configuration.hasSensorSGP = false;
}
return false;

View File

@@ -351,7 +351,7 @@ static bool sgp41Init(void) {
configuration.hasSensorSGP = true;
return true;
} else {
Serial.println("Init SGP41 failuire");
Serial.println("Init SGP41 failure");
configuration.hasSensorSGP = false;
}
return false;

View File

@@ -374,7 +374,7 @@ static bool sgp41Init(void) {
configuration.hasSensorSGP = true;
return true;
} else {
Serial.println("Init SGP41 failuire");
Serial.println("Init SGP41 failure");
configuration.hasSensorSGP = false;
}
return false;

View File

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

View File

@@ -21,10 +21,15 @@ bool PMSBase::begin(Stream *stream) {
}
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
Serial.printf("setting active mode\n");
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);
// Run and check sensor data for 4sec
@@ -314,7 +319,6 @@ int PMSBase::pm25ToAQI(int pm02) {
return 500;
}
/**
* @brief SLR correction for PM2.5
*

View File

@@ -266,3 +266,44 @@ int PMS5003::getFailCount(void) { return pms.getFailCount(); }
* @return int
*/
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
bool begin(HardwareSerial &serial);
#endif
// Modes
void sleep();
void wakeUp();
void activeMode();
void passiveMode();
void requestRead();
void end(void);
void handle(void);
void updateFailCount(void);

View File

@@ -835,3 +835,13 @@ bool S8::setAbcPeriod(int hours) {
* @return int Hour
*/
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 setAbcPeriod(int hours);
int getAbcPeriod(void);
void printInformation(void);
private:
/** Variables */