Browse Source

Wlan Datenübertragung an PIR und Ultraschallsensor funktioniert

master
Johannes Krug 5 years ago
parent
commit
0821b8ed9f

+ 41
- 5
arduino/wlan_2bewegungssensoren/wlan_2bewegungssensoren.ino View File



const char* SSID = "smartroom"; const char* SSID = "smartroom";
const char* PSK = "smarthome"; const char* PSK = "smarthome";
const char* MQTT_BROKER = "192.168.4.1";
const char* MQTT_BROKER = "192.168.252.1";
WiFiClient espClient; WiFiClient espClient;
PubSubClient client(espClient); PubSubClient client(espClient);






void loop() { 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.print("Publish Motion: ");
Serial.println(msg); Serial.println(msg);
client.publish("/home/data", 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;
}

+ 2
- 2
arduino/wlan_ultraschall/wlan_ultraschall.ino View File

PubSubClient client(espClient); PubSubClient client(espClient);


// defines pins numbers // defines pins numbers
const int trigPin = 2; //D4
const int echoPin = 0; //D3
const int trigPin = D4; //D4
const int echoPin = D3; //D3


long duration; long duration;
int distance; int distance;

Loading…
Cancel
Save