|
|
@@ -3,7 +3,7 @@ |
|
|
|
|
|
|
|
const char* SSID = "smartroom"; |
|
|
|
const char* PSK = "smarthome"; |
|
|
|
const char* MQTT_BROKER = "192.168.4.1"; |
|
|
|
const char* MQTT_BROKER = "192.168.252.1"; |
|
|
|
WiFiClient espClient; |
|
|
|
PubSubClient client(espClient); |
|
|
|
|
|
|
@@ -66,12 +66,48 @@ void reconnect() { |
|
|
|
|
|
|
|
|
|
|
|
void loop() { |
|
|
|
if (!client.connected()) { |
|
|
|
reconnect(); |
|
|
|
} |
|
|
|
client.loop(); |
|
|
|
|
|
|
|
if((distance!=(distance_alt-1))&&(distance!=(distance_alt))&&(distance!=(distance_alt+1))){//+-1 um störungen herauszufiltern |
|
|
|
snprintf (msg,50,"%d", distance); |
|
|
|
pirValueNeu1 = digitalRead(pirPin1); |
|
|
|
pirValueNeu2 = digitalRead(pirPin2); |
|
|
|
digitalWrite(ledPin,(pirValueNeu1|pirValueNeu2)); |
|
|
|
pirAn1= ((pirValueNeu1==1)&&(pirValueAlt1==0)); |
|
|
|
pirAn2= ((pirValueNeu2==1)&&(pirValueAlt2==0)); |
|
|
|
pirAus1= ((pirValueNeu1==0)&&(pirValueAlt1==1)); |
|
|
|
pirAus2= ((pirValueNeu2==0)&&(pirValueAlt2==1)); |
|
|
|
|
|
|
|
if(pirAn1){ |
|
|
|
Serial.println("Steigende Flanke von PIR1"); |
|
|
|
snprintf (msg,50,"%c%c",49,48); //Codierung PIR1 steigende Flanke: 10 |
|
|
|
Serial.print("Publish Motion: "); |
|
|
|
Serial.println(msg); |
|
|
|
client.publish("/home/data", msg); |
|
|
|
delay(500); |
|
|
|
} |
|
|
|
} |
|
|
|
if(pirAn2){ |
|
|
|
Serial.println("Steigende Flanke von PIR2"); |
|
|
|
snprintf (msg,50,"%c%c",49,49); //Codierung PIR2 steigende Flanke: 11 |
|
|
|
Serial.print("Publish Motion: "); |
|
|
|
Serial.println(msg); |
|
|
|
client.publish("/home/data", msg); |
|
|
|
} |
|
|
|
if(pirAus1){ |
|
|
|
Serial.println("Fallende Flanke von PIR1"); |
|
|
|
snprintf (msg,50,"%c%c",48,48); //Codierung PIR1 fallende Flanke: 00 |
|
|
|
Serial.print("Publish Motion: "); |
|
|
|
Serial.println(msg); |
|
|
|
client.publish("/home/data", msg); |
|
|
|
} |
|
|
|
if(pirAus2){ |
|
|
|
Serial.println("Fallende Flanke von PIR2"); |
|
|
|
snprintf (msg,50,"%c%c",48,49); //Codierung PIR2 fallende Flanke: 01 |
|
|
|
Serial.print("Publish Motion: "); |
|
|
|
Serial.println(msg); |
|
|
|
client.publish("/home/data", msg); |
|
|
|
} |
|
|
|
|
|
|
|
pirValueAlt1=pirValueNeu1; |
|
|
|
pirValueAlt2=pirValueNeu2; |
|
|
|
} |