ordnerstruktur verändert
This commit is contained in:
parent
29fdc20ea2
commit
4441a65bfc
3
arduino/Abmessungen bb104.txt
Normal file
3
arduino/Abmessungen bb104.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Höhe 3,0m
|
||||||
|
Breite 5,9m
|
||||||
|
Länge 8,9m
|
@ -26,7 +26,7 @@ char msg[50];
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
setup_wifi();
|
setup_wifi();
|
||||||
client.setServer(MQTT_BROKER, 1883);
|
client.setServer(MQTT_BROKER, 1883);
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
pinMode(pirPin1, INPUT);
|
pinMode(pirPin1, INPUT);
|
||||||
pinMode(pirPin2, INPUT);
|
pinMode(pirPin2, INPUT);
|
||||||
@ -53,61 +53,61 @@ void setup_wifi() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
while (!client.connected()) {
|
while (!client.connected()) {
|
||||||
Serial.print("Reconnecting...");
|
Serial.print("Reconnecting...");
|
||||||
if (!client.connect("ESP8266Client")) {
|
if (!client.connect("ESP8266Client")) {
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
Serial.print(client.state());
|
Serial.print(client.state());
|
||||||
Serial.println(" retrying in 5 seconds");
|
Serial.println(" retrying in 5 seconds");
|
||||||
delay(5000);
|
delay(5000);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
reconnect();
|
reconnect();
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
pirValueNeu1 = digitalRead(pirPin1);
|
pirValueNeu1 = digitalRead(pirPin1);
|
||||||
pirValueNeu2 = digitalRead(pirPin2);
|
pirValueNeu2 = digitalRead(pirPin2);
|
||||||
digitalWrite(ledPin,(pirValueNeu1|pirValueNeu2));
|
digitalWrite(ledPin, (pirValueNeu1 | pirValueNeu2));
|
||||||
pirAn1= ((pirValueNeu1==1)&&(pirValueAlt1==0));
|
pirAn1 = ((pirValueNeu1 == 1) && (pirValueAlt1 == 0));
|
||||||
pirAn2= ((pirValueNeu2==1)&&(pirValueAlt2==0));
|
pirAn2 = ((pirValueNeu2 == 1) && (pirValueAlt2 == 0));
|
||||||
pirAus1= ((pirValueNeu1==0)&&(pirValueAlt1==1));
|
pirAus1 = ((pirValueNeu1 == 0) && (pirValueAlt1 == 1));
|
||||||
pirAus2= ((pirValueNeu2==0)&&(pirValueAlt2==1));
|
pirAus2 = ((pirValueNeu2 == 0) && (pirValueAlt2 == 1));
|
||||||
|
|
||||||
if(pirAn1){
|
if (pirAn1) {
|
||||||
Serial.println("Steigende Flanke von PIR1");
|
Serial.println("Steigende Flanke von PIR1");
|
||||||
snprintf (msg,50,"%c%c",49,48); //Codierung PIR1 steigende Flanke: 10
|
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("/gso/bb/104/Pir/1", msg);
|
||||||
}
|
}
|
||||||
if(pirAn2){
|
if (pirAn2) {
|
||||||
Serial.println("Steigende Flanke von PIR2");
|
Serial.println("Steigende Flanke von PIR2");
|
||||||
snprintf (msg,50,"%c%c",49,49); //Codierung PIR2 steigende Flanke: 11
|
snprintf (msg, 50, "%c%c", 49, 49); //Codierung PIR2 steigende Flanke: 11
|
||||||
Serial.print("Publish Motion: ");
|
Serial.print("Publish Motion: ");
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
client.publish("/home/data", msg);
|
client.publish("/gso/bb/104/Pir/2", msg);
|
||||||
}
|
}
|
||||||
if(pirAus1){
|
if (pirAus1) {
|
||||||
Serial.println("Fallende Flanke von PIR1");
|
Serial.println("Fallende Flanke von PIR1");
|
||||||
snprintf (msg,50,"%c%c",48,48); //Codierung PIR1 fallende Flanke: 00
|
snprintf (msg, 50, "%c%c", 48, 48); //Codierung PIR1 fallende Flanke: 00
|
||||||
Serial.print("Publish Motion: ");
|
Serial.print("Publish Motion: ");
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
client.publish("/home/data", msg);
|
client.publish("/gso/bb/104/Pir/1", msg);
|
||||||
}
|
}
|
||||||
if(pirAus2){
|
if (pirAus2) {
|
||||||
Serial.println("Fallende Flanke von PIR2");
|
Serial.println("Fallende Flanke von PIR2");
|
||||||
snprintf (msg,50,"%c%c",48,49); //Codierung PIR2 fallende Flanke: 01
|
snprintf (msg, 50, "%c%c", 48, 49); //Codierung PIR2 fallende Flanke: 01
|
||||||
Serial.print("Publish Motion: ");
|
Serial.print("Publish Motion: ");
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
client.publish("/home/data", msg);
|
client.publish("/gso/bb/104/Pir/2", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pirValueAlt1=pirValueNeu1;
|
pirValueAlt1 = pirValueNeu1;
|
||||||
pirValueAlt2=pirValueNeu2;
|
pirValueAlt2 = pirValueNeu2;
|
||||||
}
|
}
|
@ -2,11 +2,11 @@
|
|||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
//Eigene zu trackende Entfernung festlegen
|
//Eigene zu trackende Entfernung festlegen
|
||||||
#define DISTANCE 15
|
#define DISTANCE 155
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@ -84,38 +84,46 @@ void loop() {
|
|||||||
// Calculating the distance
|
// Calculating the distance
|
||||||
distance = duration * 0.034 / 2;
|
distance = duration * 0.034 / 2;
|
||||||
// Prints the distance on the Serial Monitor
|
// Prints the distance on the Serial Monitor
|
||||||
/* if ((distance != (distance_alt - 1)) && (distance != (distance_alt)) && (distance != (distance_alt + 1))) { //+-1 um störungen herauszufiltern
|
/* if ((distance != (distance_alt - 1)) && (distance != (distance_alt)) && (distance != (distance_alt + 1))) { //+-1 um störungen herauszufiltern
|
||||||
snprintf (msg, 50, "%d", distance);
|
snprintf (msg, 50, "%d", distance);
|
||||||
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(200);
|
delay(200);
|
||||||
} */
|
} */
|
||||||
if (bool1 == 0) {
|
if (bool1 == 0) {
|
||||||
//alternativ: if ((distance != (DISTANCE - 1)) && (distance != (DISTANCE)) && (distance != (DISTANCE + 1))) { //+-1
|
//alternativ: if ((distance != (DISTANCE - 1)) && (distance != (DISTANCE)) && (distance != (DISTANCE + 1))) { //+-1
|
||||||
if (((DISTANCE + 2) < distance) || ((DISTANCE - 2) > distance)) { //darf +- 2 um festgelegte entfernung schwanken, um störungen herauszufiltern
|
if (((DISTANCE + 2) < distance) || ((DISTANCE - 2) > distance)) { //darf +- 2 um festgelegte entfernung schwanken, um störungen herauszufiltern
|
||||||
//Meldung an PI, dass die Distanz gestört ist
|
//Meldung an PI, dass die Distanz gestört ist
|
||||||
snprintf (msg, 50, "%d", 1);
|
snprintf (msg, 50, "%d", 1);
|
||||||
client.publish("/home/data", msg);
|
client.publish("/gso/bb/104/ultraschall/1", msg);
|
||||||
//Serieller Monitor
|
//Serieller Monitor
|
||||||
Serial.print("Motion detected! Distance: ");
|
Serial.print("Motion detected! Distance: ");
|
||||||
Serial.println(msg);
|
Serial.println(distance);
|
||||||
|
|
||||||
//Flag auf 1
|
//Flag auf 1
|
||||||
bool1 = 1;
|
bool1 = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snprintf (msg, 50, "%d", 0);
|
||||||
|
client.publish("/gso/bb/104/ultraschall/1", msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (bool1 == 1) {
|
else if (bool1 == 1) {
|
||||||
if (((DISTANCE + 2) < distance) || ((DISTANCE - 2) > distance)) { //darf +- 2 um festgelegte entfernung schwanken, um störungen herauszufiltern
|
if (((DISTANCE + 2) < distance) || ((DISTANCE - 2) > distance)) { //darf +- 2 um festgelegte entfernung schwanken, um störungen herauszufiltern
|
||||||
Serial.print("Still motion detected! Distance: ");
|
Serial.print("Still motion detected! Distance: ");
|
||||||
Serial.println(distance);
|
Serial.println(distance);
|
||||||
|
//Meldung an PI, dass die Ausgangsdistanz wieder gemessen wird
|
||||||
|
snprintf (msg, 50, "%d", 1);
|
||||||
|
client.publish("/gso/bb/104/ultraschall/1", msg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Meldung an PI, dass die Ausgangsdistanz wieder gemessen wird
|
//Meldung an PI, dass die Ausgangsdistanz wieder gemessen wird
|
||||||
snprintf (msg, 50, "%d", 0);
|
snprintf (msg, 50, "%d", 0);
|
||||||
client.publish("/home/data", msg);
|
client.publish("/gso/bb/104/ultraschall/1", msg);
|
||||||
|
|
||||||
//Flag wieder auf 0
|
//Flag wieder auf 0
|
||||||
bool1 = 0;
|
bool1 = 0;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user