Benutzer-Werkzeuge

Webseiten-Werkzeuge


sonstiges:tuerklingel

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
sonstiges:tuerklingel [2023-09-29 22:15] schuballaasonstiges: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 ({{:sonstiges:einstellungen_sp333_version_2.pdf|Doku}} ), welches im Hauskeller im Sicherungsschrank neben dem Netzteil NH 333 installiert ist.+Das Steuergerät ist ein SP 333 ({{:sonstiges:einstellungen_sp333_version_2.pdf|Doku}}  ), welches im Hauskeller im Sicherungsschrank neben dem Netzteil NH 333 installiert ist.
  
 ===== 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://www.amazon.de/dp/B00ISMW1DG|Funk-Türklingel]] mit zwei Empfängern zurückgreifen. Der Sender sowie die 2 Empfänger werden mit einem Standard 5 Volt USB Netzteil versorgt. Da uns keine Leitung zwischen den Räumen Bornstr. 14-15 sowie 16-17 zur Verfügung steht, mussten wir auf eine [[http://www.amazon.de/dp/B00ISMW1DG|Funk-Türklingel]] mit zwei Empfängern zurückgreifen. Der Sender sowie die 2 Empfänger werden mit einem Standard 5 Volt USB Netzteil versorgt.
  
-Wenn geklingelt wird, zieht ein n channel mosfet den Pin 4 des [[https://www.amazon.de/AZDelivery-Lolin-ESP32-Parent/dp/B086V1P4BL?th=1|esp32]] auf groundWenn dieses > 1000 ms auf Ground bleibt, wurde geklingelt und ein ESPNOW signal zu den Empfängern geschickt.+Änderungen am 04.02.2025: 
 + 
 +Der Mosfet (siehe Bild) hat nicht mehr das Klingel Signal zum ESPNOW Sender weitergeleitetDaher 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 ,,Klingeln" schickt. 
 + 
 +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, dass das Klingelsignal mindestens 1800 ms anliegen muss (In meinen Tests war das Signal nie kürzer als 2000 ms). 
  
 ===== Sender in Haustelefon einbauen ===== ===== Sender in Haustelefon einbauen =====
  
-Der Sender ist ein ESP32 Lolin Lite welcher auf ein Trigger auf Pin 4 wartet (als sensor wird ein n chanel mosfet benutzt(Bild: Patine mitte links)+Der Sender ist ein ESP32 Lolin Lite welcher auf ein Trigger auf Pin 4 wartet.
  
 {{https://wiki.hackerspace-bremen.de/_media/sonstiges/klingel_sender.jpg?nolink&600x800|klingel_sender.jpg}} {{https://wiki.hackerspace-bremen.de/_media/sonstiges/klingel_sender.jpg?nolink&600x800|klingel_sender.jpg}}
 +
  
 ===== Sourcecode ===== ===== Sourcecode =====
  
 Sender: Sender:
 +<code>
  
-#include <WiFi.h>\\ +#include <WiFi.h> 
-#include <esp_wifi.h>\\+#include <esp_wifi.h>
 #include <esp_now.h> #include <esp_now.h>
  
-//Set your new MAC Address\\ +// Set your new MAC Address 
-uint8_t newMACAddress[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; //REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS\\ +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\\ +// Variabledie von der ISR gesetzt wird 
-void OnDataSent(const uint8_t *mac_addresp_now_send_status_t status) {\\ +volatile bool bellTriggered = false;
-char macStr[18];\\ +
-Serial.print("Packet to: ");// \\ +
-Copies the sender mac address to a string\\ +
-snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", +
-<code>+
  
-       mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);\\+// Callback when data is sent 
 +void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { 
 +  char macStr[18]; 
 +  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", 
 +           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); 
 +  Serial.print("Packet to: "); 
 +  Serial.print(macStr); 
 +  Serial.print(" send status:\t"); 
 +  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); 
 +}
  
-</code>+void setup() { 
 +  Serial.begin(115200);
  
-Serial.print(macStr);\\ +  WiFi.mode(WIFI_STA);
-Serial.print(" send status:\t");\\ +
-Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");\\ +
-}+
  
-void setup() {\\ +  // Set the ESP32 Board MAC Address 
-Serial.begin(115200);+  esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]); 
 +  Serial.print("[NEW] ESP32 Board MAC Address: "); 
 +  Serial.println(WiFi.macAddress());
  
-WiFi.mode(WIFI_STA);+  if (esp_now_init() != ESP_OK) { 
 +    Serial.println("Error initializing ESP-NOW"); 
 +    ESP.restart(); 
 +  }
  
-//Set the ESP32 Board MAC Address.\\ +  esp_now_register_send_cb(OnDataSent);
-esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]); //Print the new MAC Address.\\ +
-Serial.print("[NEW] ESP32 Board MAC Address: ");\\ +
-Serial.println(WiFi.macAddress());+
  
-if (esp_now_init() != ESP_OK) {+  // Register first peer 
 +  peerInfo.channel = 0; 
 +  peerInfo.encrypt = false; 
 +  memcpy(peerInfo.peer_addr, broadcastAddress1, 6); 
 +  if (esp_now_add_peer(&peerInfo) != ESP_OK) { 
 +    Serial.println("Failed to add peer 1"); 
 +    return; 
 +  }
  
-<code> +  // Register second peer 
-Serial.println("Error initializing ESP-NOW");\\ +  memcpy(peerInfo.peer_addr, broadcastAddress2, 6); 
-ESP.restart();\\+  if (esp_now_add_peer(&peerInfo) != ESP_OK) { 
 +    Serial.println("Failed to add peer 2"); 
 +    return; 
 +  }
  
-</code>+  // Set pin 4 as an interrupt 
 +  pinMode(triggerPin, INPUT); 
 +  pinMode(testPin, INPUT_PULLUP); 
 +  attachInterrupt(digitalPinToInterrupt(triggerPin), triggerbell, FALLING); 
 +}
  
 +// 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 esp_now_send(0(uint8_t *)&bellsizeof(bell_struct));
-peerInfo.channel = 0;\\ +
-peerInfo.encrypt = false;// \\ +
-register first peer\\ +
-memcpy(peerInfo.peer_addrbroadcastAddress1, 6);\\ +
-if (esp_now_add_peer(&peerInfo!= ESP_OK{+
  
-<code> +  if (result == ESP_OK) { 
-Serial.println("Failed to add peer");\\ +    Serial.println("Sent with success"); 
-return;\\ +  } else { 
- +    Serial.println("Error sending the data"); 
-</code>+  }
  
 +  Serial.print("[NEW] ESP32 Board MAC Address: ");
 +  Serial.println(WiFi.macAddress());
 } }
  
-//register second peer\\ +void loop() { 
-memcpy(peerInfo.peer_addr, broadcastAddress2, 6);\\ +  unsigned long currentMillis millis();
-if (esp_now_add_peer(&peerInfo) !ESP_OK) {\\ +
-Serial.println("Failed to add peer");\\ +
-return;\\ +
-} //Set pin 4 as an interrupt\\ +
-pinMode(4, INPUT_PULLUP);\\ +
-attachInterrupt(digitalPinToInterrupt(4), triggerbell, FALLING);\\ +
-}+
  
-void triggerbell() {\\ +  testmodeState = digitalRead(testPin); 
-bell.trigger 8562190430;+  triggerState digitalRead(triggerPin);
  
-esp_err_t result = esp_now_send(0, (uint8_t *) &bell, sizeof(bell_struct));+  // Verarbeitungwenn Interrupt ausgelöst wurde 
 +  if (bellTriggered
 +    bellTriggered = false// Zurücksetzen der Flag-Variable
  
-if (result == ESP_OK) {+    // Senden des Klingelsignals 
 +    bell.trigger 8562190430;
  
-<code> +    esp_err_t result = esp_now_send(0, (uint8_t *)&bell, sizeof(bell_struct)); 
-Serial.println("Sent with success");\\+ 
 +    if (result == ESP_OK) { 
 +      Serial.println("Sent with success"); 
 +    } else { 
 +      Serial.println("Error sending the data"); 
 +    } 
 + 
 +    Serial.print("[NEW] ESP32 Board MAC Address: "); 
 +    Serial.println(WiFi.macAddress()); 
 +  } 
 + 
 +  // Testmodus umschalten 
 +  if (testmodeState == 0 && testmode == 0) { 
 +    Serial.println("Klingelsendertestmodus ist aktiviert!"); 
 +    testmode = 1; 
 +    TestpreviousMillis = Testinterval + currentMillis; 
 +  } 
 + 
 +  if (testmodeState == 1 && testmode == 1) { 
 +    Serial.println("Klingelsendertestmodus wird deaktiviert!"); 
 +    testmode = 0; 
 +    TestpreviousMillis = Testinterval + currentMillis; 
 +  } 
 + 
 +  // Debugging-Ausgabe 
 +  if (currentMillis - DebugpreviousMillis>= Debuginterval) { 
 +    DebugpreviousMillis = currentMillis; 
 +    Serial.print("testmodeState: "); 
 +    Serial.print(testmodeState); 
 +    Serial.print(" - triggerState: "); 
 +    Serial.println(triggerState); 
 +  } 
 + 
 +  // Testklingelsignal im Testmodus senden 
 +  if (currentMillis - TestpreviousMillis>= Testinterval) { 
 +    TestpreviousMillis = currentMillis; 
 +    if (testmode == 1) { 
 +      Serial.println("sende Testklingel signal (payload: 4042190430)"); 
 +      testbell(); 
 +    } else { 
 +      Serial.println("warte auf klingeln, testmodus deaktiviert!"); 
 +    } 
 +  } 
 +}
  
 </code> </code>
  
-} else {+Empfänger1
  
 <code> <code>
-Serial.println("Error sending the data");\\+#include <WiFi.h> 
 +#include <esp_wifi.h> 
 +#include <esp_now.h> 
 +#include <Ticker.h>
  
-</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("[NEW] ESP32 Board MAC Address: ");\\ +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;
 +
 +//INITIALIZE WATCHDOG//////////
 +//watchdogCount==30 means it will wait 30 seconds before it will automatically reset on a hang
 +//got this watchdog code from Andreas Spiess "The Guy with the Swiss Accent"
 +
 +Ticker secondTick;
 +volatile int watchdogCount = 0;
 +
 +void ISRwatchdog() {
 +  watchdogCount ++;
 +  if (watchdogCount>= 180) {
 +    Serial.println("crashed");
 +    ESP.restart();
 +  }
 } }
 +//END WATCHDOG
  
-void loop() {+void printRestartReason() { 
 +  esp_reset_reason_t reason = esp_reset_reason(); 
 +  Serial.print("Restart reason: "); 
 +  switch (reason) { 
 +    case ESP_RST_POWERON: Serial.println("Power on"); selftest = 1; break; 
 +    case ESP_RST_EXT: Serial.println("External reset"); break; 
 +    case ESP_RST_SW: Serial.println("Software reset"); break; 
 +    case ESP_RST_PANIC: Serial.println("Exception/panic"); break; 
 +    case ESP_RST_INT_WDT: Serial.println("Interrupt watchdog"); break; 
 +    case ESP_RST_TASK_WDT: Serial.println("Task watchdog"); break; 
 +    case ESP_RST_WDT: Serial.println("Other watchdog"); break; 
 +    case ESP_RST_DEEPSLEEP: Serial.println("Deep sleep"); break; 
 +    case ESP_RST_BROWNOUT: Serial.println("Brownout"); break; 
 +    case ESP_RST_SDIO: Serial.println("SDIO"); break; 
 +    default: Serial.println("Unknown"); break; 
 +  } 
 +
 + 
 +void OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, int len) { 
 +  memcpy(&myData, incomingData, sizeof(myData)); 
 +  Serial.print("Bytes received: "); 
 +  Serial.println(len); 
 +  Serial.print("received command: "); 
 +  Serial.println(myData.trigger);
  
 +  // Prüfen, ob die MAC-Adresse übereinstimmt
 +  if (memcmp(info->src_addr, addr, 6) == 0) {
 +    Serial.println("klingel device received!");
 +    if (myData.trigger == 8562190430) {
 +      Serial.println("valid Trigger code received!");
 +      triggerbell();
 +    }
 +  }
 } }
  
-Empfänger1+void setup() { 
 +  Serial.begin(115200); 
 +  Serial.println(); 
 +  secondTick.attach(1, ISRwatchdog); 
 +  printRestartReason();
  
-#include <WiFi.h>\\ +  WiFi.mode(WIFI_STA); 
-#include <esp_wifi.h>\\ +  Serial.print("[OLD] ESP32 Board MAC Address: "); 
-#include <esp_now.h>+  Serial.println(WiFi.macAddress());
  
-//Set MAC Address this device (bell receiver 1)\\ +  esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]); 
-uint8_t newMACAddress[] = {0x30, 0xAF, 0xA1, 0x05, 0x1D, 0x63}uint8_t addr[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}unsigned long lastPrintoutTime = 0;\\ +  Serial.print("[NEWESP32 Board MAC Address: ")
-bool isTriggered = false;\\ +  Serial.println(WiFi.macAddress());
-unsigned long lastTriggeredTime = 0; typedef struct bell_struct {\\ +
-uint64_t trigger;\\ +
-} bell_struct; //Create a struct_message called myData\\ +
-bell_struct myData;+
  
-void OnDataRecv(const uint8_t * macconst uint8_t *incomingData, int len) {\\ +  pinMode(LED_BUILTINOUTPUT); 
-memcpy(&myData, incomingData, sizeof(myData));\\ +  pinMode(4OUTPUT);
-Serial.print("Bytes received: ");\\ +
-Serial.println(len);\\ +
-Serial.print("received command:");\\ +
-Serial.println(myData.trigger);\\ +
-if (memcmp(mac, addr, 6) == 0) { // Check if expected Mac Addr\\ +
-Serial.println("klingel device received!");\\ +
-if (myData.trigger == 8562190430) {\\ +
-Serial.println("valid Trigger code received!");\\ +
-triggerbell();\\ +
-}\\ +
-}\\ +
-} void setup() { Serial.begin(115200); Serial.println(); WiFi.mode(WIFI_STA); Serial.print("[OLD] ESP32 Board MAC Address: ");\\ +
-Serial.println(WiFi.macAddress()); //ESP32 Board add-on before version < 1.0.5\\ +
-//esp_wifi_set_mac(ESP_IF_WIFI_STA, &newMACAddress[0]); // ESP32 Board add-on after version > 1.0.5\\ +
-esp_wifi_set_mac(WIFI_IF_STA&newMACAddress[0]);+
  
-Serial.print("[NEW] ESP32 Board MAC Address: ");\\ +  if (selftest == 1) { 
-Serial.println(WiFi.macAddress());+    Serial.println("selbsttest!"); 
 +    digitalWrite(LED_BUILTIN, LOW); 
 +    digitalWrite(4, HIGH); // Trigger bell 
 +    delay(100); 
 +    digitalWrite(4, LOW); 
 +    digitalWrite(LED_BUILTIN, HIGH); 
 +    delay(100); 
 +  } else { 
 +    Serial.println("kein selbsttest!"); 
 +  }
  
-pinMode(LED_BUILTIN, OUTPUT);\\ +  WiFi.mode(WIFI_STA);
-pinMode(4, OUTPUT);+
  
-digitalWrite(LED_BUILTIN, LOW);\\ +  // ESP-NOW initialisieren 
-digitalWrite(4, HIGH); // trigger bell\\ +  if (esp_now_init() != ESP_OK{ 
-delay(100);\\ +    Serial.println("Error initializing ESP-NOW"); 
-digitalWrite(4, LOW);\\ +    ESP.restart(); 
-digitalWrite(LED_BUILTIN, HIGH);\\ +  }
-delay(100); //Set device as a Wi-Fi Station\\ +
-WiFi.mode(WIFI_STA);+
  
-//Init ESP-NOW\\ +  esp_now_register_recv_cb(OnDataRecv);
-if (esp_now_init() != ESP_OK) {\\ +
-Serial.println("Error initializing ESP-NOW");\\ +
-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, LOW);\\ +
-digitalWrite(4, HIGH); //trigger bell +
-<code>+
  
-delay(100);\\ +  lastRebootTime = millis(); // Zeit des letzten Neustarts speichern 
-digitalWrite(4, LOW);\\ +}
-digitalWrite(LED_BUILTIN, HIGH);\\ +
-Serial.println("bell triggered");\\+
  
-</code>+void triggerbell() { 
 +  if (!isTriggered || (millis() - lastTriggeredTime10000)) { 
 +    isTriggered = true; 
 +    lastTriggeredTime = millis(); 
 +    digitalWrite(LED_BUILTIN, LOW); 
 +    digitalWrite(4, HIGH); // Trigger bell
  
-}+    delay(100); 
 +    digitalWrite(4, LOW); 
 +    digitalWrite(LED_BUILTIN, HIGH); 
 +    Serial.println("bell triggered"); 
 +  }
 } }
  
-void loop() {\\ +void loop() {
-//Print out the `isTriggered` variable every second\\ +
-if (millis() - lastPrintoutTime > 1000) {\\ +
-Serial.print("isTriggered: ");\\ +
-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() - lastTriggeredTime5000) { 
 +    isTriggered = false; 
 +  }
  
-</code>+  // Periodischer Neustart alle 60 Sekunden 
 +  if (millis() - lastRebootTimeREBOOT_INTERVAL) { 
 +    Serial.println("Performing periodic reboot..."); 
 +    ESP.restart(); 
 +  }
  
-}+  if (millis() - lastDebugTime> DebugIntervall) { 
 +    lastDebugTime = millis(); 
 +    Serial.print("isTriggered: "); 
 +    Serial.println(isTriggered); 
 +  }
  
 +  watchdogCount = 0;
 } }
 +
 +</code>
  
 Empfänger2 Empfänger2
 +<code>
  
-#include <WiFi.h>\\ +#include <WiFi.h> 
-#include <esp_wifi.h>\\+#include <esp_wifi.h>
 #include <esp_now.h> #include <esp_now.h>
 +#include <Ticker.h>
  
-//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 false;\\ +uint8_t addr[] = {0x30, 0xAF, 0xA0, 0x05, 0x1D, 0x63}; 
-unsigned long lastTriggeredTime = 0; typedef struct bell_struct {\\ +unsigned long lastPrintoutTime = 0; 
-uint64_t trigger;\\ +unsigned long lastRebootTime 0
-} bell_struct; //Create a struct_message called myData\\ +unsigned long lastDebugTime = 0; 
-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, int len) {\\ +bool isTriggered false
-memcpy(&myData, incomingData, sizeof(myData));\\ +unsigned long lastTriggeredTime = 0;
-Serial.print("Bytes received: ");\\ +
-Serial.println(len);\\ +
-Serial.print("received command:");\\ +
-Serial.println(myData.trigger);\\ +
-if (memcmp(mac, addr, 6) == 0) { // Check if expected Mac Addr\\ +
-Serial.println("klingel device received!");\\ +
-if (myData.trigger == 8562190430) {\\ +
-Serial.println("valid Trigger code received!");\\ +
-triggerbell();\\ +
-}\\ +
-}\\ +
-} void setup() { Serial.begin(115200); Serial.println(); WiFi.mode(WIFI_STA); Serial.print("[OLD] ESP32 Board MAC Address: ");\\ +
-Serial.println(WiFi.macAddress()); //ESP32 Board add-on before version < 1.0.5\\ +
-//esp_wifi_set_mac(ESP_IF_WIFI_STA, &newMACAddress[0]); // ESP32 Board add-on after version > 1.0.5\\ +
-esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]);+
  
-Serial.print("[NEW] ESP32 Board MAC Address: ");\\ +int selftest = 0;
-Serial.println(WiFi.macAddress());+
  
-pinMode(LED_BUILTIN, OUTPUT);\\ +typedef struct bell_struct { 
-pinMode(4, OUTPUT);+  uint64_t trigger
 +} bell_struct;
  
-digitalWrite(LED_BUILTIN, LOW);\\ +// Create struct_message called myData 
-digitalWrite(4, HIGH); // trigger bell\\ +bell_struct myData;
-delay(100);\\ +
-digitalWrite(4, LOW);\\ +
-digitalWrite(LED_BUILTIN, HIGH);\\ +
-delay(100); //Set device as Wi-Fi Station\\ +
-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("Error initializing ESP-NOW");\\ +//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 true;\\ +
-lastTriggeredTime millis(); digitalWrite(LED_BUILTIN, LOW);\\ +
-digitalWrite(4, HIGH); //trigger bell +
-<code>+
  
-delay(100);\\ +Ticker secondTick
-digitalWrite(4, LOW);\\ +volatile int watchdogCount = 0;
-digitalWrite(LED_BUILTIN, HIGH);\\ +
-Serial.println("bell triggered");\\+
  
-</code>+void ISRwatchdog() { 
 +  watchdogCount ++; 
 +  if (watchdogCount>= 180) { 
 +    Serial.println("crashed"); 
 +    ESP.restart(); 
 +  } 
 +
 +//END WATCHDOG
  
 +void printRestartReason() {
 +  esp_reset_reason_t reason = esp_reset_reason();
 +  Serial.print("Restart reason: ");
 +  switch (reason) {
 +    case ESP_RST_POWERON: Serial.println("Power on"); selftest = 1; break;
 +    case ESP_RST_EXT: Serial.println("External reset"); break;
 +    case ESP_RST_SW: Serial.println("Software reset"); break;
 +    case ESP_RST_PANIC: Serial.println("Exception/panic"); break;
 +    case ESP_RST_INT_WDT: Serial.println("Interrupt watchdog"); break;
 +    case ESP_RST_TASK_WDT: Serial.println("Task watchdog"); break;
 +    case ESP_RST_WDT: Serial.println("Other watchdog"); break;
 +    case ESP_RST_DEEPSLEEP: Serial.println("Deep sleep"); break;
 +    case ESP_RST_BROWNOUT: Serial.println("Brownout"); break;
 +    case ESP_RST_SDIO: Serial.println("SDIO"); break;
 +    default: Serial.println("Unknown"); break;
 +  }
 } }
 +
 +void OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, int len) {
 +  memcpy(&myData, incomingData, sizeof(myData));
 +  Serial.print("Bytes received: ");
 +  Serial.println(len);
 +  Serial.print("received command: ");
 +  Serial.println(myData.trigger);
 +
 +  // Prüfen, ob die MAC-Adresse übereinstimmt
 +  if (memcmp(info->src_addr, addr, 6) == 0) {
 +    Serial.println("klingel device received!");
 +    if (myData.trigger == 8562190430) {
 +      Serial.println("valid Trigger code received!");
 +      triggerbell();
 +    }
 +  }
 } }
  
-void loop() {\\ +void setup() { 
-//Print out the `isTriggered` variable every second\\ +  Serial.begin(115200); 
-if (millis() - lastPrintoutTime > 1000) {\\ +  Serial.println(); 
-Serial.print("isTriggered: ");\\ +  secondTick.attach(1, ISRwatchdog); 
-Serial.println(isTriggered);\\ +  printRestartReason();
-lastPrintoutTime = millis();\\ +
-}// \\ +
-\\ +
-Reset the `isTriggered` variable after 5 seconds\\ +
-if (millis() - lastTriggeredTime > 5000) {+
  
-<code> +  WiFi.mode(WIFI_STA); 
-isTriggered = false;\\+  Serial.print("[OLD] ESP32 Board MAC Address: "); 
 +  Serial.println(WiFi.macAddress());
  
-</code>+  esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]); 
 +  Serial.print("[NEW] ESP32 Board MAC Address: "); 
 +  Serial.println(WiFi.macAddress());
  
 +  pinMode(LED_BUILTIN, OUTPUT);
 +  pinMode(4, OUTPUT);
 +
 +  if (selftest == 1) {
 +    Serial.println("selbsttest!");
 +    digitalWrite(LED_BUILTIN, LOW);
 +    digitalWrite(4, HIGH); // Trigger bell
 +    delay(100);
 +    digitalWrite(4, LOW);
 +    digitalWrite(LED_BUILTIN, HIGH);
 +    delay(100);
 +  } else {
 +    Serial.println("kein selbsttest!");
 +  }
 +
 +  WiFi.mode(WIFI_STA);
 +
 +  // ESP-NOW initialisieren
 +  if (esp_now_init() != ESP_OK) {
 +    Serial.println("Error initializing ESP-NOW");
 +    ESP.restart();
 +  }
 +
 +  esp_now_register_recv_cb(OnDataRecv);
 +
 +  lastRebootTime = millis(); // Zeit des letzten Neustarts speichern
 } }
  
 +void triggerbell() {
 +  if (!isTriggered || (millis() - lastTriggeredTime> 10000)) {
 +    isTriggered = true;
 +    lastTriggeredTime = millis();
 +    digitalWrite(LED_BUILTIN, LOW);
 +    digitalWrite(4, HIGH); // Trigger bell
 +
 +    delay(100);
 +    digitalWrite(4, LOW);
 +    digitalWrite(LED_BUILTIN, HIGH);
 +    Serial.println("bell triggered");
 +  }
 } }
 +
 +void loop() {
 +
 +  // Reset der `isTriggered`-Variable nach 5 Sekunden
 +  if (millis() - lastTriggeredTime> 5000) {
 +    isTriggered = false;
 +  }
 +
 +  // Periodischer Neustart alle 60 Sekunden
 +  if (millis() - lastRebootTime> REBOOT_INTERVAL) {
 +    Serial.println("Performing periodic reboot...");
 +    ESP.restart();
 +  }
 +
 +  if (millis() - lastDebugTime> DebugIntervall) {
 +    lastDebugTime = millis();
 +    Serial.print("isTriggered: ");
 +    Serial.println(isTriggered);
 +  }
 +
 +  watchdogCount = 0;
 +}
 +
 +</code>
  
  
sonstiges/tuerklingel.1696018506.txt.gz · Zuletzt geändert: 2023-09-29 22:15 von schuballaa