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:15] – 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 n channel mosfet den Pin 4 des [[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 den Pin 04 LOW setzt und ein ESPNOW signal zu den Empfängern | ||
+ | |||
+ | 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 66: | 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, | + | |
- | < | + | |
- | mac_addr[0], | + | // Callback when data is sent |
+ | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { | ||
+ | char macStr[18]; | ||
+ | snprintf(macStr, | ||
+ | mac_addr[0], | ||
+ | Serial.print(" | ||
+ | Serial.print(macStr); | ||
+ | Serial.print(" | ||
+ | Serial.println(status == ESP_NOW_SEND_SUCCESS ? " | ||
+ | } | ||
- | </ | + | void setup() { |
+ | Serial.begin(115200); | ||
- | Serial.print(macStr);\\ | + | WiFi.mode(WIFI_STA); |
- | Serial.print(" | + | |
- | Serial.println(status == ESP_NOW_SEND_SUCCESS ? " | + | |
- | } | + | |
- | void setup() {\\ | + | // Set the ESP32 Board MAC Address |
- | Serial.begin(115200); | + | esp_wifi_set_mac(WIFI_IF_STA, |
+ | Serial.print("[NEW] ESP32 Board MAC Address: "); | ||
+ | Serial.println(WiFi.macAddress()); | ||
- | WiFi.mode(WIFI_STA); | + | if (esp_now_init() != ESP_OK) { |
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
- | //Set the ESP32 Board MAC Address.\\ | + | esp_now_register_send_cb(OnDataSent); |
- | esp_wifi_set_mac(WIFI_IF_STA, | + | |
- | Serial.print(" | + | |
- | Serial.println(WiFi.macAddress()); | + | |
- | if (esp_now_init() != ESP_OK) { | + | // Register first peer |
+ | peerInfo.channel = 0; | ||
+ | peerInfo.encrypt = false; | ||
+ | memcpy(peerInfo.peer_addr, | ||
+ | | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
- | < | + | // Register second peer |
- | Serial.println(" | + | |
- | ESP.restart();\\ | + | if (esp_now_add_peer(& |
+ | | ||
+ | | ||
+ | } | ||
- | </code> | + | |
+ | pinMode(triggerPin, | ||
+ | pinMode(testPin, | ||
+ | attachInterrupt(digitalPinToInterrupt(triggerPin), | ||
+ | } | ||
+ | // Minimal Interrupt-Service-Routine | ||
+ | void triggerbell() { | ||
+ | bellTriggered = true; // Setzt die Flag-Variable | ||
} | } | ||
- | esp_now_register_send_cb(OnDataSent); | + | void testbell() { |
+ | bell.trigger = 4042190430; | ||
- | //register peer\\ | + | esp_err_t result |
- | peerInfo.channel | + | |
- | peerInfo.encrypt = false;// \\ | + | |
- | register first peer\\ | + | |
- | memcpy(peerInfo.peer_addr, broadcastAddress1, | + | |
- | if (esp_now_add_peer(& | + | |
- | < | + | if (result == ESP_OK) { |
- | Serial.println(" | + | Serial.println(" |
- | return;\\ | + | } else { |
- | + | | |
- | </ | + | } |
+ | Serial.print(" | ||
+ | Serial.println(WiFi.macAddress()); | ||
} | } | ||
- | //register second peer\\ | + | void loop() { |
- | memcpy(peerInfo.peer_addr, | + | |
- | if (esp_now_add_peer(& | + | |
- | Serial.println(" | + | |
- | return;\\ | + | |
- | } //Set pin 4 as an interrupt\\ | + | |
- | pinMode(4, INPUT_PULLUP); | + | |
- | attachInterrupt(digitalPinToInterrupt(4), | + | |
- | } | + | |
- | void triggerbell() {\\ | + | testmodeState = digitalRead(testPin); |
- | bell.trigger | + | |
- | esp_err_t result = esp_now_send(0, (uint8_t *) &bell, sizeof(bell_struct)); | + | // Verarbeitung, wenn Interrupt ausgelöst wurde |
+ | if (bellTriggered) { | ||
+ | bellTriggered = false; // Zurücksetzen der Flag-Variable | ||
- | if (result | + | // Senden des Klingelsignals |
+ | bell.trigger | ||
- | < | + | esp_err_t result = esp_now_send(0, |
- | Serial.println(" | + | |
+ | if (result == ESP_OK) { | ||
+ | | ||
+ | } 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(" | ||
+ | } | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | } else { | + | Empfänger1 |
< | < | ||
- | Serial.println(" | + | #include <WiFi.h> |
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
- | </code> | + | // 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; | ||
+ | unsigned long lastRebootTime = 0; | ||
+ | unsigned long lastDebugTime = 0; | ||
+ | const unsigned long DebugIntervall = 1000; | ||
+ | const unsigned long REBOOT_INTERVAL = 60000; // Periodischer Neustart nach 60 Sekunden | ||
- | } | + | bool isTriggered = false; |
+ | unsigned long lastTriggeredTime = 0; | ||
- | Serial.print(" | + | int selftest = 0; |
- | Serial.println(WiFi.macAddress()); | + | |
+ | typedef struct bell_struct { | ||
+ | uint64_t trigger; | ||
+ | } bell_struct; | ||
+ | |||
+ | // Create a struct_message called myData | ||
+ | bell_struct myData; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | //got this watchdog code from Andreas Spiess "The Guy with the Swiss Accent" | ||
+ | |||
+ | Ticker secondTick; | ||
+ | volatile int watchdogCount = 0; | ||
+ | |||
+ | void ISRwatchdog() { | ||
+ | watchdogCount ++; | ||
+ | if (watchdogCount> | ||
+ | Serial.println(" | ||
+ | ESP.restart(); | ||
+ | } | ||
} | } | ||
+ | //END WATCHDOG | ||
- | void loop() { | + | 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 OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, | ||
+ | memcpy(& | ||
+ | Serial.print(" | ||
+ | Serial.println(len); | ||
+ | Serial.print(" | ||
+ | Serial.println(myData.trigger); | ||
+ | // Prüfen, ob die MAC-Adresse übereinstimmt | ||
+ | if (memcmp(info-> | ||
+ | Serial.println(" | ||
+ | if (myData.trigger == 8562190430) { | ||
+ | Serial.println(" | ||
+ | triggerbell(); | ||
+ | } | ||
+ | } | ||
} | } | ||
- | Empfänger1 | + | void setup() { |
+ | Serial.begin(115200); | ||
+ | Serial.println(); | ||
+ | secondTick.attach(1, | ||
+ | printRestartReason(); | ||
- | #include <WiFi.h>\\ | + | |
- | #include < | + | |
- | #include <esp_now.h> | + | |
- | //Set MAC Address this device | + | esp_wifi_set_mac(WIFI_IF_STA, |
- | uint8_t | + | Serial.print(" |
- | bool isTriggered = false;\\ | + | |
- | unsigned long lastTriggeredTime = 0; typedef struct bell_struct {\\ | + | |
- | uint64_t trigger; | + | |
- | } bell_struct; | + | |
- | bell_struct myData; | + | |
- | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, | + | pinMode(LED_BUILTIN, OUTPUT); |
- | memcpy(& | + | |
- | Serial.print(" | + | |
- | Serial.println(len); | + | |
- | Serial.print(" | + | |
- | Serial.println(myData.trigger); | + | |
- | if (memcmp(mac, | + | |
- | Serial.println(" | + | |
- | if (myData.trigger == 8562190430) {\\ | + | |
- | Serial.println(" | + | |
- | triggerbell(); | + | |
- | }\\ | + | |
- | }\\ | + | |
- | } void setup() { Serial.begin(115200); | + | |
- | Serial.println(WiFi.macAddress()); | + | |
- | // | + | |
- | esp_wifi_set_mac(WIFI_IF_STA, & | + | |
- | Serial.print("[NEW] ESP32 Board MAC Address: | + | if (selftest == 1) { |
- | Serial.println(WiFi.macAddress()); | + | |
+ | | ||
+ | digitalWrite(4, | ||
+ | delay(100); | ||
+ | digitalWrite(4, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(100); | ||
+ | } else { | ||
+ | | ||
+ | } | ||
- | pinMode(LED_BUILTIN, | + | WiFi.mode(WIFI_STA); |
- | pinMode(4, OUTPUT); | + | |
- | digitalWrite(LED_BUILTIN, | + | |
- | digitalWrite(4, | + | |
- | delay(100);\\ | + | |
- | digitalWrite(4, LOW);\\ | + | ESP.restart(); |
- | digitalWrite(LED_BUILTIN, | + | } |
- | delay(100); //Set device as a Wi-Fi Station\\ | + | |
- | WiFi.mode(WIFI_STA); | + | |
- | //Init ESP-NOW\\ | + | |
- | if (esp_now_init() != ESP_OK) {\\ | + | |
- | Serial.println(" | + | |
- | 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 = true;\\ | + | |
- | lastTriggeredTime = millis(); digitalWrite(LED_BUILTIN, | + | |
- | digitalWrite(4, | + | |
- | < | + | |
- | delay(100);\\ | + | lastRebootTime = millis(); // Zeit des letzten Neustarts speichern |
- | digitalWrite(4, | + | } |
- | digitalWrite(LED_BUILTIN, | + | |
- | Serial.println(" | + | |
- | </code> | + | void triggerbell() { |
+ | if (!isTriggered || (millis() - lastTriggeredTime> 10000)) { | ||
+ | isTriggered = true; | ||
+ | lastTriggeredTime = millis(); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(4, | ||
- | } | + | delay(100); |
+ | digitalWrite(4, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | Serial.println(" | ||
+ | | ||
} | } | ||
- | void loop() {\\ | + | void loop() { |
- | //Print out the `isTriggered` variable every second\\ | + | |
- | if (millis() - lastPrintoutTime > 1000) {\\ | + | |
- | Serial.print(" | + | |
- | Serial.println(isTriggered); | + | |
- | lastPrintoutTime = millis(); | + | |
- | }// \\ | + | |
- | \\ | + | |
- | Reset the `isTriggered` variable after 5 seconds\\ | + | |
- | if (millis() - lastTriggeredTime > 5000) { | + | |
- | <code> | + | // Reset der `isTriggered`-Variable nach 5 Sekunden |
- | isTriggered = false;\\ | + | if (millis() - lastTriggeredTime> 5000) { |
+ | isTriggered = false; | ||
+ | } | ||
- | </code> | + | |
+ | if (millis() - lastRebootTime> REBOOT_INTERVAL) { | ||
+ | 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 |
- | 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, | + | |
- | <code> | + | |
- | delay(100);\\ | + | Ticker secondTick; |
- | digitalWrite(4, | + | volatile int watchdogCount = 0; |
- | digitalWrite(LED_BUILTIN, | + | |
- | Serial.println(" | + | |
- | </code> | + | void ISRwatchdog() { |
+ | watchdogCount ++; | ||
+ | if (watchdogCount>= 180) { | ||
+ | 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 OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, | ||
+ | memcpy(& | ||
+ | Serial.print(" | ||
+ | Serial.println(len); | ||
+ | Serial.print(" | ||
+ | Serial.println(myData.trigger); | ||
+ | |||
+ | // Prüfen, ob die MAC-Adresse übereinstimmt | ||
+ | if (memcmp(info-> | ||
+ | Serial.println(" | ||
+ | if (myData.trigger == 8562190430) { | ||
+ | Serial.println(" | ||
+ | triggerbell(); | ||
+ | } | ||
+ | } | ||
} | } | ||
- | void loop() {\\ | + | void setup() { |
- | //Print out the `isTriggered` variable every second\\ | + | Serial.begin(115200); |
- | if (millis() - lastPrintoutTime > 1000) {\\ | + | Serial.println(); |
- | Serial.print(" | + | |
- | Serial.println(isTriggered);\\ | + | |
- | lastPrintoutTime = millis();\\ | + | |
- | }// \\ | + | |
- | \\ | + | |
- | Reset the `isTriggered` variable after 5 seconds\\ | + | |
- | if (millis() - lastTriggeredTime > 5000) { | + | |
- | < | + | WiFi.mode(WIFI_STA); |
- | isTriggered = false;\\ | + | Serial.print(" |
+ | | ||
- | </ | + | 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.1696018506.txt.gz · Zuletzt geändert: 2023-09-29 22:15 von schuballaa