Compare commits
No commits in common. "18ed46d2db62a57c4945d0b776d5dd31646eb950" and "4b13827803a38f024ddf79b5da91533c1715019d" have entirely different histories.
18ed46d2db
...
4b13827803
@ -4,11 +4,9 @@
|
||||
|
||||
#include "credentials.h"
|
||||
#include "webserver.h"
|
||||
#include "socketserver.h"
|
||||
#include "util.h"
|
||||
|
||||
static ESP8266WiFiMulti wifiMulti;
|
||||
static SocketServer socketServer;
|
||||
|
||||
void setup() {
|
||||
// serial console, for use via USB (also exposed to TXD0/RXD0 GPIOs)
|
||||
@ -45,12 +43,10 @@ void setup() {
|
||||
// configure HTTP endpoints
|
||||
configureWebServer();
|
||||
|
||||
// don't forget to start all the services
|
||||
// don't forget to start the webserver!
|
||||
webServer.begin();
|
||||
socketServer.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
webServer.handleClient();
|
||||
socketServer.handleClient();
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
#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};
|
||||
};
|
25
src/util.h
25
src/util.h
@ -122,7 +122,7 @@ enum class ExtendedChar {
|
||||
LatinSmallLetterAWithCircumflex = 0x83,
|
||||
// ä
|
||||
LatinSmallLetterAWithDiaeresis = 0x84,
|
||||
// à
|
||||
// á
|
||||
LatinSmallLetterAWithGrave = 0x85,
|
||||
// å
|
||||
LatinSmallLetterAWithRingAbove = 0x86,
|
||||
@ -246,19 +246,6 @@ enum class ExtendedChar {
|
||||
GreekSmallLetterPhi = 0xed,
|
||||
};
|
||||
|
||||
String hexDump(String in) {
|
||||
String out;
|
||||
for (size_t i = 0; i < in.length(); ++i) {
|
||||
auto hexChar = String(in[i], HEX);
|
||||
if (hexChar.length() == 1) {
|
||||
out.concat('0');
|
||||
}
|
||||
out.concat(hexChar);
|
||||
out.concat(' ');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Message syntax:
|
||||
* separator: ~
|
||||
@ -312,5 +299,13 @@ void sendTextToSign(
|
||||
Serial1.print(toSend);
|
||||
|
||||
Serial.println("Text sent to device: " + toSend);
|
||||
Serial.println("Hex dump: " + hexDump(toSend));
|
||||
Serial.print("Hex dump: ");
|
||||
for (size_t i = 0; i < toSend.length(); ++i) {
|
||||
auto hexChar = String(toSend[i], HEX);
|
||||
if (hexChar.length() == 1) {
|
||||
hexChar = '0' + hexChar;
|
||||
}
|
||||
Serial.print(hexChar + ' ');
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
@ -66,21 +66,6 @@ namespace {
|
||||
sendTextToSign(text);
|
||||
webServer.send(200, "text/plain", "ok");
|
||||
}
|
||||
|
||||
// RESTful API endpoint -- returns a proper status code rather than a redirect
|
||||
void handleRawApiSend() {
|
||||
String toSend = webServer.arg("plain");
|
||||
|
||||
if (toSend.isEmpty()) {
|
||||
webServer.send(404, "text/plain", "empty body");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("Raw message sent to device: " + toSend);
|
||||
Serial.println("Hex dump: " + hexDump(toSend));
|
||||
Serial1.print(toSend);
|
||||
webServer.send(200, "text/plain", "ok");
|
||||
}
|
||||
}
|
||||
|
||||
void configureWebServer() {
|
||||
@ -89,5 +74,4 @@ void configureWebServer() {
|
||||
webServer.on("/", HTTPMethod::HTTP_GET, handleIndex);
|
||||
webServer.on("/", HTTPMethod::HTTP_POST, handleFormSend);
|
||||
webServer.on("/send", HTTPMethod::HTTP_POST, handleApiSend);
|
||||
webServer.on("/raw", HTTPMethod::HTTP_POST, handleRawApiSend);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user