Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/OpcServer.cpp
Original file line number Diff line number Diff line change
@@ -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[],
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions src/OpcServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#define SERVER_BEGIN_BOOL 0
//------------------------------------------------------------------------------

#elif defined(ESP32)
//==============================================================================
// ESP32
//==============================================================================
#include <WiFi.h>
#define HAS_REMOTE_IP 1
#define SERVER_BEGIN_BOOL 0
//------------------------------------------------------------------------------

#elif defined(PARTICLE)
//==============================================================================
// Particle
Expand Down