From 26babc5543094b846d01afc91794b4b0c4c63ecb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 21 Mar 2021 14:44:07 +0100 Subject: [PATCH] notify selection change over udp --- FINAL2013V2.ino | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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; } } -- 2.39.2