Added Koridor MyS
This commit is contained in:
@@ -85,18 +85,83 @@
|
||||
#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED
|
||||
|
||||
#include <MySensors.h>
|
||||
//#include <SdsDustSensor.h>
|
||||
#include <SDS011.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
unsigned long cRun;
|
||||
int cSec;
|
||||
#define RX_PIN 2
|
||||
#define TX_PIN 3
|
||||
SoftwareSerial sSerial(RX_PIN, TX_PIN);
|
||||
SDS011 sds;
|
||||
//SdsDustSensor sds(sSerial);
|
||||
MyMessage msgHum25(0, V_LEVEL);
|
||||
MyMessage msgHum25_UN(0, V_UNIT_PREFIX);
|
||||
MyMessage msgHum10(1, V_LEVEL);
|
||||
MyMessage msgHum10_UN(1, V_UNIT_PREFIX);
|
||||
void set_per(uint8_t per, SoftwareSerial *ser);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Setup locally attached sensors
|
||||
Serial.begin(115200);
|
||||
sSerial.begin(9600);
|
||||
set_per(2, &sSerial);
|
||||
sds.begin(&sSerial);
|
||||
Serial.println("Begin");
|
||||
//Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
|
||||
//Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
|
||||
//Serial.println(sds.setCustomWorkingPeriod(3).toString()); // sensor sends data every 3 minutes
|
||||
//sds.setActiveReportingMode();
|
||||
//sds.setCustomWorkingPeriod(1);
|
||||
cRun = millis();
|
||||
cSec = 0;
|
||||
}
|
||||
|
||||
void presentation()
|
||||
{
|
||||
// Present locally attached sensors
|
||||
present(0, S_DUST, "pm2.5");
|
||||
present(1, S_DUST, "pm10");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Send locally attached sensor data here
|
||||
float p25, p10;
|
||||
if(cRun + 999 < millis()){
|
||||
cRun = millis();
|
||||
|
||||
int error = sds.read(&p25, &p10);
|
||||
if (!error) {
|
||||
Serial.println(millis()/1000);
|
||||
Serial.println("P2.5: " + String(p25));
|
||||
Serial.println("P10: " + String(p10));
|
||||
}
|
||||
/* PmResult pm = sds.readPm();
|
||||
if (pm.isOk()) {
|
||||
send(msgHum25.set(pm.pm25, 2));
|
||||
wait(100);
|
||||
send(msgHum10.set(pm.pm10, 2));
|
||||
}
|
||||
if(++cSec == 60){
|
||||
wait(100);
|
||||
send(msgHum25_UN.set("pm2.5"));
|
||||
wait(100);
|
||||
send(msgHum10_UN.set("pm10"));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
void set_per(uint8_t per, SoftwareSerial *ser)
|
||||
{
|
||||
ser->write(0xAA);
|
||||
ser->write(0xB4);
|
||||
ser->write(0x08);
|
||||
ser->write(0xAA);
|
||||
ser->write(0x01);
|
||||
for(int i = 0; i < 10; i++) ser->print(0x00);
|
||||
ser->write(0xFF);
|
||||
ser->write(0xFF);
|
||||
uint8_t crc = 0x07 + per;
|
||||
ser->write(crc);
|
||||
ser->write(0xAB);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user