sonstiges:tuerklingel
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
sonstiges:tuerklingel [2023-09-29 22:37] – [Funk-Türklingel] schuballaa | sonstiges:tuerklingel [2025-02-05 20:12] (aktuell) – [Sender in Haustelefon einbauen] schuballaa | ||
---|---|---|---|
Zeile 9: | Zeile 9: | ||
**Optional: | **Optional: | ||
- | Es könnte zu jeder zeit an sender und oder Empfängern eine Li-ion Akku (via JST) angeschlossen werden und somit auch mobil betrieben werden z.b bei Veranstaltungen die im Hinnenhof stattfinden um kein Klingeln zu verpassen. | + | Es könnte zu jeder zeit an den Empfängern eine Li-ion Akku (via JST) angeschlossen werden und somit auch mobil betrieben werden z.b bei Veranstaltungen die im Hinnenhof stattfinden um kein Klingeln zu verpassen. |
**Achtung bei Powerbanks!** | **Achtung bei Powerbanks!** | ||
Zeile 21: | Zeile 21: | ||
Das Haustelefon ist vom Typ STR HT 3033. | Das Haustelefon ist vom Typ STR HT 3033. | ||
- | Das Steuergerät ist ein SP 333 ({{: | + | Das Steuergerät ist ein SP 333 ({{: |
===== Pinout ===== | ===== Pinout ===== | ||
Zeile 37: | Zeile 37: | ||
Da uns keine Leitung zwischen den Räumen Bornstr. 14-15 sowie 16-17 zur Verfügung steht, mussten wir auf eine [[http:// | Da uns keine Leitung zwischen den Räumen Bornstr. 14-15 sowie 16-17 zur Verfügung steht, mussten wir auf eine [[http:// | ||
- | Wenn geklingelt wird, zieht ein [[[https:// | + | Änderungen am 04.02.2025: |
+ | |||
+ | Der Mosfet (siehe Bild) hat nicht mehr das Klingel Signal zum ESPNOW Sender weitergeleitet. Daher dedektiere ich das Klingelsignal nun über einen H11LX (Optokoppler) der beim Klingeln | ||
+ | |||
+ | Zusätzlich habe ich den Empfängern mit einem Watchchdog und ein auto restart (jede Minute) ausgestattet. | ||
+ | |||
+ | Nachtrag am 05.02.2025: | ||
+ | |||
+ | Es kam gelegentlich zu Fehlauslösungen. Daher habe ich in der Software eingestellt, | ||
===== Sender in Haustelefon einbauen ===== | ===== Sender in Haustelefon einbauen ===== | ||
- | Der Sender ist ein ESP32 Lolin Lite welcher auf ein Trigger auf Pin 4 wartet | + | Der Sender ist ein ESP32 Lolin Lite welcher auf ein Trigger auf Pin 4 wartet. |
{{https:// | {{https:// | ||
+ | |||
===== Sourcecode ===== | ===== Sourcecode ===== | ||
Sender: | Sender: | ||
- | |||
< | < | ||
- | #include < | + | |
- | #include < | + | #include < |
+ | #include < | ||
#include < | #include < | ||
- | //Set your new MAC Address\\ | + | // Set your new MAC Address |
- | uint8_t newMACAddress[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; | + | uint8_t newMACAddress[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; |
- | uint8_t broadcastAddress1[] = {0x30, 0xAF, 0xA1, 0x05, 0x1D, 0x63};\\ | + | uint8_t broadcastAddress1[] = {0x30, 0xAF, 0xA1, 0x05, 0x1D, 0x63}; |
uint8_t broadcastAddress2[] = {0x30, 0xAF, 0xA2, 0x05, 0x1D, 0x63}; | uint8_t broadcastAddress2[] = {0x30, 0xAF, 0xA2, 0x05, 0x1D, 0x63}; | ||
- | typedef struct bell_struct {\\ | + | unsigned long TestpreviousMillis = 0; |
- | uint64_t trigger;\\ | + | unsigned long DebugpreviousMillis = 0; |
+ | |||
+ | const long Testinterval = 60000; | ||
+ | const long Debuginterval = 1000; | ||
+ | |||
+ | int testPin = 33; | ||
+ | int triggerPin = 4; | ||
+ | |||
+ | int testmode = 0; | ||
+ | int testmodeState = 0; | ||
+ | int triggerState = 0; | ||
+ | |||
+ | typedef struct bell_struct { | ||
+ | uint64_t trigger; | ||
} bell_struct; | } bell_struct; | ||
Zeile 67: | Zeile 90: | ||
esp_now_peer_info_t peerInfo; | esp_now_peer_info_t peerInfo; | ||
- | //callback when data is sent\\ | + | // Variable, die von der ISR gesetzt wird |
- | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {\\ | + | volatile bool bellTriggered = false; |
- | char macStr[18]; | + | |
- | Serial.print(" | + | |
- | Copies the sender mac address to a string\\ | + | |
- | snprintf(macStr, | + | |
- | + | ||
- | | + | |
- | Serial.print(macStr); | + | // Callback when data is sent |
- | Serial.print(" | + | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { |
- | Serial.println(status == ESP_NOW_SEND_SUCCESS ? " | + | char macStr[18]; |
+ | snprintf(macStr, | ||
+ | | ||
+ | Serial.print(" | ||
+ | | ||
+ | Serial.print(" | ||
+ | Serial.println(status == ESP_NOW_SEND_SUCCESS ? " | ||
} | } | ||
- | void setup() {\\ | + | void setup() { |
- | Serial.begin(115200); | + | Serial.begin(115200); |
- | WiFi.mode(WIFI_STA); | + | |
- | //Set the ESP32 Board MAC Address.\\ | + | |
- | esp_wifi_set_mac(WIFI_IF_STA, | + | esp_wifi_set_mac(WIFI_IF_STA, |
- | Serial.print(" | + | Serial.print(" |
- | Serial.println(WiFi.macAddress()); | + | Serial.println(WiFi.macAddress()); |
- | if (esp_now_init() != ESP_OK) { | + | |
- | Serial.println(" | + | Serial.println(" |
- | ESP.restart(); | + | ESP.restart(); |
+ | } | ||
- | } | + | esp_now_register_send_cb(OnDataSent); |
- | esp_now_register_send_cb(OnDataSent); | + | // Register first peer |
+ | peerInfo.channel = 0; | ||
+ | peerInfo.encrypt = false; | ||
+ | memcpy(peerInfo.peer_addr, | ||
+ | if (esp_now_add_peer(& | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
- | //register | + | |
- | peerInfo.channel = 0;\\ | + | memcpy(peerInfo.peer_addr, |
- | peerInfo.encrypt = false;// \\ | + | if (esp_now_add_peer(& |
- | register first peer\\ | + | Serial.println(" |
- | memcpy(peerInfo.peer_addr, | + | return; |
- | if (esp_now_add_peer(& | + | } |
- | Serial.println(" | + | |
- | return;\\ | + | |
+ | // Set pin 4 as an interrupt | ||
+ | pinMode(triggerPin, | ||
+ | pinMode(testPin, | ||
+ | attachInterrupt(digitalPinToInterrupt(triggerPin), | ||
} | } | ||
- | //register second peer\\ | + | // Minimal Interrupt-Service-Routine |
- | memcpy(peerInfo.peer_addr, | + | void triggerbell() { |
- | if (esp_now_add_peer(& | + | |
- | Serial.println(" | + | |
- | return;\\ | + | |
- | } //Set pin 4 as an interrupt\\ | + | |
- | pinMode(4, INPUT_PULLUP); | + | |
- | attachInterrupt(digitalPinToInterrupt(4), | + | |
} | } | ||
- | void triggerbell() {\\ | + | void testbell() { |
- | bell.trigger = 8562190430; | + | bell.trigger = 4042190430; |
- | esp_err_t result = esp_now_send(0, | + | |
- | if (result == ESP_OK) { | + | |
+ | Serial.println(" | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
- | Serial.println("Sent with success");\\ | + | |
- | + | Serial.println(WiFi.macAddress()); | |
- | } else { | + | |
- | Serial.println("Error sending the data");\\ | + | |
} | } | ||
- | Serial.print("[NEW] ESP32 Board MAC Address: ");\\ | + | void loop() { |
- | Serial.println(WiFi.macAddress()); | + | |
- | } | + | testmodeState = digitalRead(testPin); |
+ | triggerState = digitalRead(triggerPin); | ||
- | void loop() { | + | // Verarbeitung, |
+ | if (bellTriggered) { | ||
+ | bellTriggered = false; // Zurücksetzen der Flag-Variable | ||
+ | // Senden des Klingelsignals | ||
+ | bell.trigger = 8562190430; | ||
+ | |||
+ | esp_err_t result = esp_now_send(0, | ||
+ | |||
+ | if (result == ESP_OK) { | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.macAddress()); | ||
+ | } | ||
+ | |||
+ | // Testmodus umschalten | ||
+ | if (testmodeState == 0 && testmode == 0) { | ||
+ | Serial.println(" | ||
+ | testmode = 1; | ||
+ | TestpreviousMillis = Testinterval + currentMillis; | ||
+ | } | ||
+ | |||
+ | if (testmodeState == 1 && testmode == 1) { | ||
+ | Serial.println(" | ||
+ | testmode = 0; | ||
+ | TestpreviousMillis = Testinterval + currentMillis; | ||
+ | } | ||
+ | |||
+ | // Debugging-Ausgabe | ||
+ | if (currentMillis - DebugpreviousMillis> | ||
+ | DebugpreviousMillis = currentMillis; | ||
+ | Serial.print(" | ||
+ | Serial.print(testmodeState); | ||
+ | Serial.print(" | ||
+ | Serial.println(triggerState); | ||
+ | } | ||
+ | |||
+ | // Testklingelsignal im Testmodus senden | ||
+ | if (currentMillis - TestpreviousMillis> | ||
+ | TestpreviousMillis = currentMillis; | ||
+ | if (testmode == 1) { | ||
+ | Serial.println(" | ||
+ | testbell(); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
} | } | ||
+ | |||
</ | </ | ||
Zeile 146: | Zeile 227: | ||
< | < | ||
- | #include < | + | #include < |
- | #include < | + | #include < |
#include < | #include < | ||
+ | #include < | ||
- | //Set MAC Address this device (bell receiver 1)\\ | + | // Set MAC Address this device (bell receiver 1) |
- | uint8_t newMACAddress[] = {0x30, 0xAF, 0xA1, 0x05, 0x1D, 0x63}; uint8_t addr[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; unsigned long lastPrintoutTime = 0;\\ | + | uint8_t newMACAddress[] = {0x30, 0xAF, 0xA1, 0x05, 0x1D, 0x63}; |
- | bool isTriggered | + | uint8_t addr[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; |
- | unsigned long lastTriggeredTime | + | unsigned long lastPrintoutTime = 0; |
- | uint64_t trigger;\\ | + | unsigned long lastRebootTime |
- | } bell_struct; //Create a struct_message called myData\\ | + | unsigned long lastDebugTime |
- | bell_struct myData; | + | const unsigned long DebugIntervall = 1000; |
+ | const unsigned long REBOOT_INTERVAL = 60000; // Periodischer Neustart nach 60 Sekunden | ||
- | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, | + | bool isTriggered |
- | memcpy(& | + | unsigned long lastTriggeredTime |
- | Serial.print(" | + | |
- | Serial.println(len); | + | |
- | Serial.print(" | + | |
- | Serial.println(myData.trigger); | + | |
- | if (memcmp(mac, | + | |
- | Serial.println(" | + | |
- | if (myData.trigger | + | |
- | Serial.println(" | + | |
- | triggerbell(); | + | |
- | }\\ | + | |
- | }\\ | + | |
- | } void setup() { Serial.begin(115200); | + | |
- | Serial.println(WiFi.macAddress()); | + | |
- | // | + | |
- | esp_wifi_set_mac(WIFI_IF_STA, | + | |
- | Serial.print(" | + | int selftest = 0; |
- | Serial.println(WiFi.macAddress()); | + | |
- | pinMode(LED_BUILTIN, | + | typedef struct bell_struct { |
- | pinMode(4, OUTPUT); | + | uint64_t trigger; |
+ | } bell_struct; | ||
- | digitalWrite(LED_BUILTIN, | + | // Create |
- | digitalWrite(4, | + | bell_struct myData; |
- | delay(100); | + | |
- | digitalWrite(4, | + | |
- | digitalWrite(LED_BUILTIN, | + | |
- | delay(100); | + | |
- | WiFi.mode(WIFI_STA); | + | |
- | //Init ESP-NOW\\ | + | //INITIALIZE WATCHDOG//////// |
- | if (esp_now_init() != ESP_OK) {\\ | + | //watchdogCount==30 means it will wait 30 seconds before it will automatically reset on a hang |
- | Serial.println(" | + | //got this watchdog code from Andreas Spiess "The Guy with the Swiss Accent" |
- | ESP.restart(); | + | |
- | } //Once ESPNow is successfully Init, we will register for recv CB to\\ | + | |
- | //get recv packer info\\ | + | |
- | esp_now_register_recv_cb(OnDataRecv); | + | |
- | }\\ | + | |
- | void triggerbell() {\\ | + | |
- | if (!isTriggered || (millis() - lastTriggeredTime > 10000)) {\\ | + | |
- | isTriggered | + | |
- | lastTriggeredTime | + | |
- | digitalWrite(4, | + | |
- | delay(100);\\ | + | Ticker secondTick; |
- | digitalWrite(4, LOW);\\ | + | volatile int watchdogCount = 0; |
- | digitalWrite(LED_BUILTIN, | + | |
- | Serial.println(" | + | void ISRwatchdog() { |
+ | watchdogCount ++; | ||
+ | | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
} | } | ||
+ | //END WATCHDOG | ||
+ | |||
+ | void printRestartReason() { | ||
+ | esp_reset_reason_t reason = esp_reset_reason(); | ||
+ | Serial.print(" | ||
+ | switch (reason) { | ||
+ | case ESP_RST_POWERON: | ||
+ | case ESP_RST_EXT: | ||
+ | case ESP_RST_SW: Serial.println(" | ||
+ | case ESP_RST_PANIC: | ||
+ | case ESP_RST_INT_WDT: | ||
+ | case ESP_RST_TASK_WDT: | ||
+ | case ESP_RST_WDT: | ||
+ | case ESP_RST_DEEPSLEEP: | ||
+ | case ESP_RST_BROWNOUT: | ||
+ | case ESP_RST_SDIO: | ||
+ | default: Serial.println(" | ||
+ | } | ||
} | } | ||
- | void loop() {\\ | + | void OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, |
- | //Print out the `isTriggered` variable every second\\ | + | |
- | if (millis() - lastPrintoutTime > 1000) {\\ | + | Serial.print(" |
- | Serial.print(" | + | Serial.println(len); |
- | Serial.println(isTriggered);\\ | + | |
- | lastPrintoutTime = millis();\\ | + | |
- | }// \\ | + | |
- | \\ | + | |
- | Reset the `isTriggered` variable after 5 seconds\\ | + | |
- | if (millis() - lastTriggeredTime > 5000) { | + | |
- | isTriggered | + | // Prüfen, ob die MAC-Adresse übereinstimmt |
+ | if (memcmp(info-> | ||
+ | Serial.println(" | ||
+ | if (myData.trigger == 8562190430) { | ||
+ | Serial.println(" | ||
+ | triggerbell(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(); | ||
+ | secondTick.attach(1, | ||
+ | printRestartReason(); | ||
+ | |||
+ | WiFi.mode(WIFI_STA); | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.macAddress()); | ||
+ | |||
+ | esp_wifi_set_mac(WIFI_IF_STA, | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.macAddress()); | ||
+ | |||
+ | pinMode(LED_BUILTIN, | ||
+ | pinMode(4, OUTPUT); | ||
+ | |||
+ | if (selftest == 1) { | ||
+ | Serial.println(" | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(4, | ||
+ | delay(100); | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(100); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | WiFi.mode(WIFI_STA); | ||
+ | |||
+ | // ESP-NOW initialisieren | ||
+ | if (esp_now_init() != ESP_OK) { | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | |||
+ | esp_now_register_recv_cb(OnDataRecv); | ||
+ | |||
+ | lastRebootTime = millis(); // Zeit des letzten Neustarts speichern | ||
} | } | ||
+ | void triggerbell() { | ||
+ | if (!isTriggered || (millis() - lastTriggeredTime> | ||
+ | isTriggered = true; | ||
+ | lastTriggeredTime = millis(); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(4, | ||
+ | |||
+ | delay(100); | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | Serial.println(" | ||
+ | } | ||
} | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | // Reset der `isTriggered`-Variable nach 5 Sekunden | ||
+ | if (millis() - lastTriggeredTime> | ||
+ | isTriggered = false; | ||
+ | } | ||
+ | |||
+ | // Periodischer Neustart alle 60 Sekunden | ||
+ | if (millis() - lastRebootTime> | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | |||
+ | if (millis() - lastDebugTime> | ||
+ | lastDebugTime = millis(); | ||
+ | Serial.print(" | ||
+ | Serial.println(isTriggered); | ||
+ | } | ||
+ | |||
+ | watchdogCount = 0; | ||
+ | } | ||
+ | |||
</ | </ | ||
Empfänger2 | Empfänger2 | ||
- | |||
< | < | ||
- | #include < | + | |
- | #include < | + | #include < |
+ | #include < | ||
#include < | #include < | ||
+ | #include < | ||
- | //Set MAC Address this device (bell receiver 2)\\ | + | // Set MAC Address this device (bell receiver 2) |
- | uint8_t newMACAddress[] = {0x30, 0xAF, 0xA2, 0x05, 0x1D, 0x63}; uint8_t addr[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; unsigned long lastPrintoutTime = 0;\\ | + | uint8_t newMACAddress[] = {0x30, 0xAF, 0xA2, 0x05, 0x1D, 0x63}; |
- | bool isTriggered | + | uint8_t addr[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; |
- | unsigned long lastTriggeredTime | + | unsigned long lastPrintoutTime = 0; |
- | uint64_t trigger;\\ | + | unsigned long lastRebootTime |
- | } bell_struct; //Create a struct_message called myData\\ | + | unsigned long lastDebugTime |
- | bell_struct myData; | + | const unsigned long DebugIntervall = 1000; |
+ | const unsigned long REBOOT_INTERVAL = 60000; // Periodischer Neustart nach 60 Sekunden | ||
- | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, | + | bool isTriggered |
- | memcpy(& | + | unsigned long lastTriggeredTime |
- | Serial.print(" | + | |
- | Serial.println(len); | + | |
- | Serial.print(" | + | |
- | Serial.println(myData.trigger); | + | |
- | if (memcmp(mac, | + | |
- | Serial.println(" | + | |
- | if (myData.trigger | + | |
- | Serial.println(" | + | |
- | triggerbell(); | + | |
- | }\\ | + | |
- | }\\ | + | |
- | } void setup() { Serial.begin(115200); | + | |
- | Serial.println(WiFi.macAddress()); | + | |
- | // | + | |
- | esp_wifi_set_mac(WIFI_IF_STA, | + | |
- | Serial.print(" | + | int selftest = 0; |
- | Serial.println(WiFi.macAddress()); | + | |
- | pinMode(LED_BUILTIN, | + | typedef struct bell_struct { |
- | pinMode(4, OUTPUT); | + | uint64_t trigger; |
+ | } bell_struct; | ||
- | digitalWrite(LED_BUILTIN, | + | // Create |
- | digitalWrite(4, | + | bell_struct myData; |
- | delay(100); | + | |
- | digitalWrite(4, | + | |
- | digitalWrite(LED_BUILTIN, | + | |
- | delay(100); | + | |
- | WiFi.mode(WIFI_STA); | + | |
- | //Init ESP-NOW\\ | + | //INITIALIZE WATCHDOG//////// |
- | if (esp_now_init() != ESP_OK) {\\ | + | //watchdogCount==30 means it will wait 30 seconds before it will automatically reset on a hang |
- | Serial.println(" | + | //got this watchdog code from Andreas Spiess "The Guy with the Swiss Accent" |
- | ESP.restart(); | + | |
- | } //Once ESPNow is successfully Init, we will register for recv CB to\\ | + | |
- | //get recv packer info\\ | + | |
- | esp_now_register_recv_cb(OnDataRecv); | + | |
- | }\\ | + | |
- | void triggerbell() {\\ | + | |
- | if (!isTriggered || (millis() - lastTriggeredTime > 10000)) {\\ | + | |
- | isTriggered | + | |
- | lastTriggeredTime | + | |
- | digitalWrite(4, | + | |
- | delay(100);\\ | + | Ticker secondTick; |
- | digitalWrite(4, | + | volatile int watchdogCount = 0; |
- | digitalWrite(LED_BUILTIN, | + | |
- | Serial.println(" | + | |
+ | void ISRwatchdog() { | ||
+ | watchdogCount ++; | ||
+ | if (watchdogCount> | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
} | } | ||
+ | //END WATCHDOG | ||
+ | |||
+ | void printRestartReason() { | ||
+ | esp_reset_reason_t reason = esp_reset_reason(); | ||
+ | Serial.print(" | ||
+ | switch (reason) { | ||
+ | case ESP_RST_POWERON: | ||
+ | case ESP_RST_EXT: | ||
+ | case ESP_RST_SW: Serial.println(" | ||
+ | case ESP_RST_PANIC: | ||
+ | case ESP_RST_INT_WDT: | ||
+ | case ESP_RST_TASK_WDT: | ||
+ | case ESP_RST_WDT: | ||
+ | case ESP_RST_DEEPSLEEP: | ||
+ | case ESP_RST_BROWNOUT: | ||
+ | case ESP_RST_SDIO: | ||
+ | default: Serial.println(" | ||
+ | } | ||
} | } | ||
- | void loop() {\\ | + | void OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, |
- | //Print out the `isTriggered` variable every second\\ | + | |
- | if (millis() - lastPrintoutTime > 1000) {\\ | + | Serial.print(" |
- | Serial.print(" | + | Serial.println(len); |
- | Serial.println(isTriggered);\\ | + | |
- | lastPrintoutTime = millis();\\ | + | |
- | }// \\ | + | |
- | \\ | + | |
- | Reset the `isTriggered` variable after 5 seconds\\ | + | |
- | if (millis() - lastTriggeredTime > 5000) { | + | |
- | isTriggered | + | // Prüfen, ob die MAC-Adresse übereinstimmt |
+ | if (memcmp(info-> | ||
+ | Serial.println(" | ||
+ | if (myData.trigger == 8562190430) { | ||
+ | Serial.println(" | ||
+ | triggerbell(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(); | ||
+ | secondTick.attach(1, | ||
+ | printRestartReason(); | ||
+ | |||
+ | WiFi.mode(WIFI_STA); | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.macAddress()); | ||
+ | |||
+ | esp_wifi_set_mac(WIFI_IF_STA, | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.macAddress()); | ||
+ | |||
+ | pinMode(LED_BUILTIN, | ||
+ | pinMode(4, OUTPUT); | ||
+ | |||
+ | if (selftest == 1) { | ||
+ | Serial.println(" | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(4, | ||
+ | delay(100); | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(100); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | WiFi.mode(WIFI_STA); | ||
+ | |||
+ | // ESP-NOW initialisieren | ||
+ | if (esp_now_init() != ESP_OK) { | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | |||
+ | esp_now_register_recv_cb(OnDataRecv); | ||
+ | lastRebootTime = millis(); // Zeit des letzten Neustarts speichern | ||
} | } | ||
+ | void triggerbell() { | ||
+ | if (!isTriggered || (millis() - lastTriggeredTime> | ||
+ | isTriggered = true; | ||
+ | lastTriggeredTime = millis(); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(4, | ||
+ | |||
+ | delay(100); | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | Serial.println(" | ||
+ | } | ||
} | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | // Reset der `isTriggered`-Variable nach 5 Sekunden | ||
+ | if (millis() - lastTriggeredTime> | ||
+ | isTriggered = false; | ||
+ | } | ||
+ | |||
+ | // Periodischer Neustart alle 60 Sekunden | ||
+ | if (millis() - lastRebootTime> | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | |||
+ | if (millis() - lastDebugTime> | ||
+ | lastDebugTime = millis(); | ||
+ | Serial.print(" | ||
+ | Serial.println(isTriggered); | ||
+ | } | ||
+ | |||
+ | watchdogCount = 0; | ||
+ | } | ||
+ | |||
</ | </ | ||
sonstiges/tuerklingel.1696019875.txt.gz · Zuletzt geändert: 2023-09-29 22:37 von schuballaa