diff --git a/src/OpcServer.cpp b/src/OpcServer.cpp index c9a1403..7889e53 100644 --- a/src/OpcServer.cpp +++ b/src/OpcServer.cpp @@ -1,6 +1,10 @@ #include "OpcServer.h" #include "Definitions.h" +#if defined(ESP32) +#include "ESPmDNS.h" +#endif + OpcServer::OpcServer(WiFiServer& server, uint8_t opcChannel, OpcClient opcClients[], @@ -163,6 +167,7 @@ void OpcServer::opcRead(OpcClient& opcClient) { if (opcClient.bufferLength < OPC_HEADER_BYTES) { // Still waiting for a header debug_sprint(F("Waiting for Header\n")); + return; } } @@ -182,6 +187,7 @@ void OpcServer::opcRead(OpcClient& opcClient) { if (opcClient.bufferLength < adjMsgLength) { // Waiting for more data debug_sprint("Waiting for more data\n"); + return; } // Full OPC Message Read @@ -193,3 +199,11 @@ void OpcServer::opcRead(OpcClient& opcClient) { // Set to discard remaining bytes on next call opcClient.bufferBytesToDiscard = msgLength - adjMsgLength; } + +#if defined(ESP32) +void OpcServer::mDNSBegin(String hostname) { + // This may fail if MDNS.begin() has already been called + MDNS.begin(hostname.c_str()); + MDNS.addService("_openpixelctrl", "_tcp", 7890); +} +#endif diff --git a/src/OpcServer.h b/src/OpcServer.h index 1052993..4e84a85 100644 --- a/src/OpcServer.h +++ b/src/OpcServer.h @@ -30,6 +30,10 @@ class OpcServer { void setClientDisconnectedCallback(OpcClientDisconnectedCallback opcClientDisconnectedCallback); void setMsgReceivedCallback(OpcMsgReceivedCallback opcMsgReceivedCallback); +#if defined(ESP32) + void mDNSBegin(String hostname); +#endif + private: bool processClient(OpcClient& opcClient); void opcRead(OpcClient& opcClient); diff --git a/src/Platforms.h b/src/Platforms.h index aa00894..f3a49b9 100644 --- a/src/Platforms.h +++ b/src/Platforms.h @@ -10,6 +10,15 @@ #define SERVER_BEGIN_BOOL 0 //------------------------------------------------------------------------------ +#elif defined(ESP32) +//============================================================================== +// ESP32 +//============================================================================== +#include +#define HAS_REMOTE_IP 1 +#define SERVER_BEGIN_BOOL 0 +//------------------------------------------------------------------------------ + #elif defined(PARTICLE) //============================================================================== // Particle