forked from fmueller/esp8266-led-marquee-sign-controller
Add socket server compatible with original software
This commit is contained in:
parent
4b13827803
commit
71facb7d18
@ -4,9 +4,11 @@
|
|||||||
|
|
||||||
#include "credentials.h"
|
#include "credentials.h"
|
||||||
#include "webserver.h"
|
#include "webserver.h"
|
||||||
|
#include "socketserver.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static ESP8266WiFiMulti wifiMulti;
|
static ESP8266WiFiMulti wifiMulti;
|
||||||
|
static SocketServer socketServer;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// serial console, for use via USB (also exposed to TXD0/RXD0 GPIOs)
|
// serial console, for use via USB (also exposed to TXD0/RXD0 GPIOs)
|
||||||
@ -43,10 +45,12 @@ void setup() {
|
|||||||
// configure HTTP endpoints
|
// configure HTTP endpoints
|
||||||
configureWebServer();
|
configureWebServer();
|
||||||
|
|
||||||
// don't forget to start the webserver!
|
// don't forget to start all the services
|
||||||
webServer.begin();
|
webServer.begin();
|
||||||
|
socketServer.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
webServer.handleClient();
|
webServer.handleClient();
|
||||||
|
socketServer.handleClient();
|
||||||
}
|
}
|
||||||
|
34
src/socketserver.h
Normal file
34
src/socketserver.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class SocketServer {
|
||||||
|
public:
|
||||||
|
static constexpr int Port = 3000;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
_server.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleClient() {
|
||||||
|
auto client = _server.available();
|
||||||
|
|
||||||
|
if (client) {
|
||||||
|
Serial.println("Client connected to socket server: " + client.remoteIP().toString() + ":" + client.remotePort());
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (client.connected()) {
|
||||||
|
while (client.available() > 0) {
|
||||||
|
auto chr = client.read();
|
||||||
|
Serial.write(chr);
|
||||||
|
Serial1.write(chr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.stop();
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("Client disconnected");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
WiFiServer _server{Port};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user