From: Frédéric Péters Date: Sun, 21 Mar 2021 13:44:07 +0000 (+0100) Subject: notify selection change over udp X-Git-Url: https://git.0d.be/?p=PanikSwitch.git;a=commitdiff_plain;h=26babc5543094b846d01afc91794b4b0c4c63ecb notify selection change over udp --- diff --git a/FINAL2013V2.ino b/FINAL2013V2.ino index 5135d55..f07bd1e 100644 --- a/FINAL2013V2.ino +++ b/FINAL2013V2.ino @@ -8,12 +8,12 @@ #define MAC_PANIK2 { 0x90, 0xA2, 0xDA, 0x0E, 0xF3, 0x77 } #define MAC_ADDRESS MAC_PANIK2 - // include Arduino libraries #include #include #include #include +#include // include third party libraries #include "WebServer.h" @@ -90,6 +90,11 @@ static uint8_t mac[] = MAC_ADDRESS; // instanciate web server WebServer webserver(PREFIX, 80); +// and EthernetUDP instance to send notifications +EthernetUDP Udp; +IPAddress udp_remote_ip(192, 168, 17, 224); + + #define NAMELEN 4 #define VALUELEN 4 @@ -173,6 +178,9 @@ void setup() Serial.println(F("Network Error")); while (1) ; } + if (! Udp.begin(1312)) { + Serial.println(F("Failed to initiate UDP")); + } // set mode for used pins pinMode(RELAY_RED_LEDS, OUTPUT); @@ -251,10 +259,16 @@ void loop() //Serial.println(F("Button 2 released")); if (activeSelection != blinkingSelection) { + char str_selection[20]; digitalWrite(ledsArray[activeSelection], RELAY_STATE_CLOSED); activeSelection = blinkingSelection; // relay states must be changed now Serial.print(F("Active Selection: ")); Serial.println(activeSelection); + // notify over UDP + snprintf(str_selection, 19, "{\"active\": %d}", activeSelection); + Udp.beginPacket(udp_remote_ip, 1312); + Udp.write(str_selection); + Udp.endPacket(); break; } }