typedef enum responseStatus { NO_POST, POST_OK, POST_ERROR };
+inline void notify_udp() // notify over UDP
+{
+#ifdef ENABLE_UDP
+ char str_selection[20];
+ snprintf(str_selection, 19, "{\"active\": %d}", activeSelection);
+ #ifdef SERIAL_DEBUG
+ Serial.println(F("Sending UDP... "));
+ Serial.println(str_selection);
+ #endif
+ Udp.beginPacket(udp_remote_ip, 1312);
+ Udp.write(str_selection);
+ Udp.endPacket();
+#endif
+}
+
// web resource
void webCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
while (server.readPOSTparam(name, NAMELEN, value, VALUELEN))
{
if (strcmp(name, "s") == 0) {
- char str_selection[20];
-
digitalWrite(ledsArray[activeSelection], RELAY_STATE_CLOSED);
blinkingSelection = static_cast<switchSelection_t>(atoi(value));
activeSelection = static_cast<switchSelection_t>(atoi(value));
response_status = POST_OK;
- #ifdef ENABLE_UDP
- // notify over UDP
- snprintf(str_selection, 19, "{\"active\": %d}", activeSelection);
- #ifdef SERIAL_DEBUG
- Serial.println(F("Sending UDP... "));
- Serial.println(str_selection);
- #endif
- Udp.beginPacket(udp_remote_ip, 1312);
- Udp.write(str_selection);
- Udp.endPacket();
- #endif
-
+ notify_udp();
}
}
}
#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);
- #ifdef SERIAL_DEBUG
- Serial.println(F("Sending UDP... "));
- Serial.println(str_selection);
- #endif
- Udp.beginPacket(udp_remote_ip, 1312);
- Udp.write(str_selection);
- Udp.endPacket();
- #endif
+ notify_udp();
break;
}
}