|
|
@@ -26,7 +26,7 @@ char msg[50]; |
|
|
|
void setup() { |
|
|
|
Serial.begin(115200); |
|
|
|
setup_wifi(); |
|
|
|
client.setServer(MQTT_BROKER, 1883); |
|
|
|
client.setServer(MQTT_BROKER, 1883); |
|
|
|
pinMode(ledPin, OUTPUT); |
|
|
|
pinMode(pirPin1, INPUT); |
|
|
|
pinMode(pirPin2, INPUT); |
|
|
@@ -53,61 +53,61 @@ void setup_wifi() { |
|
|
|
} |
|
|
|
|
|
|
|
void reconnect() { |
|
|
|
while (!client.connected()) { |
|
|
|
Serial.print("Reconnecting..."); |
|
|
|
if (!client.connect("ESP8266Client")) { |
|
|
|
Serial.print("failed, rc="); |
|
|
|
Serial.print(client.state()); |
|
|
|
Serial.println(" retrying in 5 seconds"); |
|
|
|
delay(5000); |
|
|
|
} |
|
|
|
while (!client.connected()) { |
|
|
|
Serial.print("Reconnecting..."); |
|
|
|
if (!client.connect("ESP8266Client")) { |
|
|
|
Serial.print("failed, rc="); |
|
|
|
Serial.print(client.state()); |
|
|
|
Serial.println(" retrying in 5 seconds"); |
|
|
|
delay(5000); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void loop() { |
|
|
|
if (!client.connected()) { |
|
|
|
reconnect(); |
|
|
|
} |
|
|
|
client.loop(); |
|
|
|
if (!client.connected()) { |
|
|
|
reconnect(); |
|
|
|
} |
|
|
|
client.loop(); |
|
|
|
|
|
|
|
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 |
|
|
|
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); |
|
|
|
client.publish("/gso/bb/104/Pir/1", msg); |
|
|
|
} |
|
|
|
if(pirAn2){ |
|
|
|
Serial.println("Steigende Flanke von PIR2"); |
|
|
|
snprintf (msg,50,"%c%c",49,49); //Codierung PIR2 steigende Flanke: 11 |
|
|
|
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); |
|
|
|
client.publish("/gso/bb/104/Pir/2", msg); |
|
|
|
} |
|
|
|
if(pirAus1){ |
|
|
|
Serial.println("Fallende Flanke von PIR1"); |
|
|
|
snprintf (msg,50,"%c%c",48,48); //Codierung PIR1 fallende Flanke: 00 |
|
|
|
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); |
|
|
|
client.publish("/gso/bb/104/Pir/1", msg); |
|
|
|
} |
|
|
|
if(pirAus2){ |
|
|
|
Serial.println("Fallende Flanke von PIR2"); |
|
|
|
snprintf (msg,50,"%c%c",48,49); //Codierung PIR2 fallende Flanke: 01 |
|
|
|
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); |
|
|
|
client.publish("/gso/bb/104/Pir/2", msg); |
|
|
|
} |
|
|
|
|
|
|
|
pirValueAlt1=pirValueNeu1; |
|
|
|
pirValueAlt2=pirValueNeu2; |
|
|
|
} |
|
|
|
pirValueAlt1 = pirValueNeu1; |
|
|
|
pirValueAlt2 = pirValueNeu2; |
|
|
|
} |