2024-09-2302
This commit is contained in:
parent
1b24959c5f
commit
126879fc0d
28
src/main.cpp
28
src/main.cpp
|
@ -22,8 +22,8 @@ PubSubClient client(espClient);
|
|||
#define mqtt_port 1883
|
||||
|
||||
//cf:d7:ab:1f:24:2c
|
||||
String Adresse = "96:33:bb:bf:ff:ab"; // Bluetooth Adresse die zu Anwesenheitserkennung überwacht wird ET585
|
||||
//String Adresse = "cf:d7:ab:1f:24:2c"; // Bluetooth Adresse die zu Anwesenheitserkennung überwacht wird Holy-IOT
|
||||
//String Adresse = "96:33:bb:bf:ff:ab"; // Bluetooth Adresse die zu Anwesenheitserkennung überwacht wird ET585
|
||||
String Adresse = "cf:d7:ab:1f:24:2c"; // Bluetooth Adresse die zu Anwesenheitserkennung überwacht wird Holy-IOT
|
||||
const int RelaisPin = LED_BUILTIN; // Pin an dem Relais hängt
|
||||
int Verzoegerung = 15; // Auschaltverzögerung wenn das Signal von BLE ibeacon fehlt
|
||||
|
||||
|
@ -32,7 +32,7 @@ int VerzoegerungZaeler = 0;
|
|||
Ticker Tic;
|
||||
static BLEAddress *pServerAddress;
|
||||
BLEScan* pBLEScan ;
|
||||
int scanTime = 30; //In seconds
|
||||
int scanTime = 10; //In seconds
|
||||
|
||||
long int Feldstaerke;
|
||||
|
||||
|
@ -45,6 +45,7 @@ String hostname = NAME;
|
|||
char msg[20];
|
||||
char clientName[30];
|
||||
char topic[50];
|
||||
bool gefunden = false;
|
||||
|
||||
const char* mqtt_zentrale = mqtt_server;
|
||||
|
||||
|
@ -140,9 +141,12 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks
|
|||
Serial.print(" ");
|
||||
digitalWrite (RelaisPin, HIGH); // Relais Einschalten
|
||||
VerzoegerungZaeler = 0; // Ausschaltverzögerung zurücksetzen
|
||||
printf(topic, "%s%ld%s", "hjk/devices/", clientName, "/telemetry/status" );
|
||||
/* sprintf(topic, "%s%s%s", "hjk/devices/", "Wohnung", "/telemetry/status" );
|
||||
client.publish(topic, "DA", true);
|
||||
Serial.println();
|
||||
Serial.print(topic); Serial.println(" DA"); */
|
||||
advertisedDevice.getScan()->stop(); // Scanvorgang beenden
|
||||
gefunden = true;
|
||||
} // Found our server
|
||||
Serial.println("");
|
||||
}
|
||||
|
@ -154,8 +158,9 @@ VerzoegerungZaeler++; // Sekundenzähler
|
|||
//ZZ++;
|
||||
if (VerzoegerungZaeler >= Verzoegerung){
|
||||
digitalWrite (RelaisPin, LOW); // Wenn Verzögerungszeit erreicht wurde Auschalten
|
||||
printf(topic, "%s%ld%s", "hjk/devices/", clientName, "/telemetry/status" );
|
||||
client.publish(topic, "FERN", true);
|
||||
/* sprintf(topic, "%s%ld%s", "hjk/devices/", clientName, "/telemetry/status" );
|
||||
client.publish(topic, "FERN", true); */
|
||||
gefunden = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,5 +187,16 @@ void loop()
|
|||
}
|
||||
client.loop();
|
||||
pBLEScan->start(scanTime);
|
||||
if (gefunden == true){
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", "Wohnung", "/telemetry/status" );
|
||||
client.publish(topic, "DA", true);
|
||||
Serial.println();
|
||||
Serial.print(topic); Serial.println(" DA");
|
||||
} else {
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", "Wohnung", "/telemetry/status" );
|
||||
client.publish(topic, "FERN", true);
|
||||
Serial.println();
|
||||
Serial.print(topic); Serial.println(" FERN");
|
||||
}
|
||||
delay(2000); // Alle 2s nach ibeacon scannen
|
||||
}
|
Loading…
Reference in New Issue
Block a user