mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-12-19 05:22:32 +01:00
Compare commits
1 Commits
3.4.1
...
feat/energ
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba250787e6 |
@@ -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();
|
||||||
@@ -1239,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());
|
||||||
@@ -1461,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) {
|
||||||
|
|||||||
@@ -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
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user