From ca82ccb9dbf2e800c118d7f327ecc5df5c688135 Mon Sep 17 00:00:00 2001 From: Grant Patterson Date: Mon, 20 Nov 2017 18:09:15 -0800 Subject: [PATCH 1/3] Add ESP32 platform Very similar to ESP8266. --- src/Platforms.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From 0d58aee574d344108e86dcdf68fbd536db5bf11f Mon Sep 17 00:00:00 2001 From: Grant Patterson Date: Mon, 20 Nov 2017 18:12:02 -0800 Subject: [PATCH 2/3] Actually wait for header / data when needed Things were behaving strangely and I was getting tons of DISCARDING DATA messages; I think it's because opcRead() should return when it needs to wait for stuff instead of calling the opcMsgReceivedCallback_ regardless. --- src/OpcServer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpcServer.cpp b/src/OpcServer.cpp index c9a1403..446988f 100644 --- a/src/OpcServer.cpp +++ b/src/OpcServer.cpp @@ -163,6 +163,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 +183,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 From e987010a277fc6cd3eb9b8bc2c5ba35be09e6e76 Mon Sep 17 00:00:00 2001 From: Grant Patterson Date: Wed, 27 Dec 2017 18:05:50 -0800 Subject: [PATCH 3/3] Add mDNSBegin() to broadcast OPC availability Clients can call mDNSBegin() to start broadcasting the service "_openpixelctrl", which has been approved by OPC creator Ping as a suitable mDNS service name. Only ESP32 support --- src/OpcServer.cpp | 12 ++++++++++++ src/OpcServer.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/OpcServer.cpp b/src/OpcServer.cpp index 446988f..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[], @@ -195,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);