// Panik Web Form Demo
+#define SERIAL_DEBUG
+#define ENABLE_UDP
// define network constants
#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
+#ifdef ENABLE_UDP
#include <EthernetUdp.h>
+#endif
// include third party libraries
#include "WebServer.h"
// instanciate web server
WebServer webserver(PREFIX, 80);
+#ifdef ENABLE_UDP
// and EthernetUDP instance to send notifications
EthernetUDP Udp;
IPAddress udp_remote_ip(192, 168, 17, 224);
+#endif
#define NAMELEN 4
Serial.println(Ethernet.localIP());
else
{
+ #ifdef SERIAL_DEBUG
Serial.println(F("Network Error"));
+ #endif
while (1) ;
}
+ #ifdef ENABLE_UDP
if (! Udp.begin(1312)) {
+ #ifdef SERIAL_DEBUG
Serial.println(F("Failed to initiate UDP"));
+ #endif
}
+ #endif
// set mode for used pins
pinMode(RELAY_RED_LEDS, OUTPUT);
case nochange:
break;
case pressed:
- //Serial.println(F("Button 1 pressed"));
+ #ifdef SERIAL_DEBUG
+ Serial.println(F("Button 1 pressed"));
+ #endif
digitalWrite(ledsArray[blinkingSelection], RELAY_STATE_CLOSED);
blinkingSelection++;
blinkingStartTime = millis(),
blinkingLedState = RELAY_STATE_OPEN;
break;
case released:
- //Serial.println(F("Button 1 released"));
+ #ifdef SERIAL_DEBUG
+ Serial.println(F("Button 1 released"));
+ #endif
break;
}
case nochange:
break;
case pressed:
- //Serial.println(F("Button 2 pressed"));
+ #ifdef SERIAL_DEBUG
+ Serial.println(F("Button 2 pressed"));
+ #endif
blinkingAbortTime = 0; // disable blinking auto abort
break;
case released:
- //Serial.println(F("Button 2 released"));
+ #ifdef SERIAL_DEBUG
+ Serial.println(F("Button 2 released"));
+ #endif
if (activeSelection != blinkingSelection)
{
char str_selection[20];
digitalWrite(ledsArray[activeSelection], RELAY_STATE_CLOSED);
activeSelection = blinkingSelection; // relay states must be changed now
+ #ifdef SERIAL_DEBUG
Serial.print(F("Active Selection: "));
Serial.println(activeSelection);
+ #endif
+ #ifdef ENABLE_UDP
// notify over UDP
snprintf(str_selection, 19, "{\"active\": %d}", activeSelection);
Udp.beginPacket(udp_remote_ip, 1312);
Udp.write(str_selection);
Udp.endPacket();
+ #endif
break;
}
}
}
return nochange;
}
-