]> git.0d.be Git - PanikSwitch.git/commitdiff
notify selection change over udp
authorFrédéric Péters <fpeters@0d.be>
Sun, 21 Mar 2021 13:44:07 +0000 (14:44 +0100)
committerFrédéric Péters <fpeters@0d.be>
Thu, 25 Mar 2021 07:13:36 +0000 (08:13 +0100)
FINAL2013V2.ino

index 5135d55cb9071e388641b182875adeb222d9593c..f07bd1e74a4d5bc44be4949c6f5eac401669b532 100644 (file)
@@ -8,12 +8,12 @@
 #define MAC_PANIK2 { 0x90, 0xA2, 0xDA, 0x0E, 0xF3, 0x77 }
 #define MAC_ADDRESS MAC_PANIK2
 
-
 // include Arduino libraries
 #include <Wire.h>
 #include <SPI.h>
 #include <SD.h>
 #include <Ethernet.h>
+#include <EthernetUdp.h>
 
 // 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;
       }
   }