add dynamic send for pir sensor
This commit is contained in:
parent
5f2e49f7a2
commit
5309dd7d8c
19
src/main.cpp
19
src/main.cpp
|
@ -14,7 +14,7 @@
|
||||||
float humidity; //[%RH] DHT
|
float humidity; //[%RH] DHT
|
||||||
float temperature; //[deg C] DHT
|
float temperature; //[deg C] DHT
|
||||||
float light; //[Lux] BH1750
|
float light; //[Lux] BH1750
|
||||||
bool movement //true bei pir output hight, false wenn low HC12?
|
bool movement //true bei pir output hight, false wenn low HC12?501?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ unsigned long lastsensorreadtime=0;
|
||||||
unsigned long sensorupdatedelay=60000; //delay for reading and transmitting
|
unsigned long sensorupdatedelay=60000; //delay for reading and transmitting
|
||||||
unsigned long lastPIRtime=0;
|
unsigned long lastPIRtime=0;
|
||||||
unsigned long PIRdelay=100; //polling delay
|
unsigned long PIRdelay=100; //polling delay
|
||||||
|
unsigned long lastPIRSendValueTime=0;
|
||||||
|
unsigned long PIRMaxDelay=1000*60*10; //maximum time until current value is send
|
||||||
bool motion=false;
|
bool motion=false;
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,22 +95,35 @@ void loop() {
|
||||||
void loopHandler() {
|
void loopHandler() {
|
||||||
|
|
||||||
if (millis() >= (lastPIRtime+PIRdelay)){
|
if (millis() >= (lastPIRtime+PIRdelay)){
|
||||||
|
|
||||||
if (digitalRead(PIRPIN)){
|
if (digitalRead(PIRPIN)){
|
||||||
if (!motion) { //changed?
|
if (!motion) { //changed?
|
||||||
Homie.getLogger() << "motion " << ": " << "true" << endl;
|
Homie.getLogger() << "motion " << ": " << "true" << endl;
|
||||||
sensorNode.setProperty("motion").send(String("true"));
|
sensorNode.setProperty("motion").send(String("true"));
|
||||||
}
|
}
|
||||||
motion=true;
|
motion=true;
|
||||||
|
lastPIRSendValueTime=millis();
|
||||||
}else{
|
}else{
|
||||||
if (motion) { //changed?
|
if (motion) { //changed?
|
||||||
Homie.getLogger() << "motion " << ": " << "false" << endl;
|
Homie.getLogger() << "motion " << ": " << "false" << endl;
|
||||||
sensorNode.setProperty("motion").send(String("false"));
|
sensorNode.setProperty("motion").send(String("false"));
|
||||||
}
|
}
|
||||||
motion=false;
|
motion=false;
|
||||||
|
lastPIRSendValueTime=millis();
|
||||||
}
|
}
|
||||||
lastPIRtime=millis();
|
lastPIRtime=millis();
|
||||||
}
|
}
|
||||||
|
if (millis() >= (lastPIRSendValueTime+PIRMaxDelay)) { //send current value after some long time
|
||||||
|
if (digitalRead(PIRPIN)){
|
||||||
|
Homie.getLogger() << "motion resend " << ": " << "true" << endl;
|
||||||
|
sensorNode.setProperty("motion").send(String("true"));
|
||||||
|
motion=true;
|
||||||
|
}else{
|
||||||
|
Homie.getLogger() << "motion resend " << ": " << "false" << endl;
|
||||||
|
sensorNode.setProperty("motion").send(String("false"));
|
||||||
|
motion=false;
|
||||||
|
}
|
||||||
|
lastPIRSendValueTime=millis();
|
||||||
|
}
|
||||||
|
|
||||||
if (millis() >= (lastsensorreadtime+sensorupdatedelay))
|
if (millis() >= (lastsensorreadtime+sensorupdatedelay))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue