Compare commits
3 Commits
3746d1a4d6
...
18ed46d2db
Author | SHA1 | Date | |
---|---|---|---|
18ed46d2db | |||
281aab33b8 | |||
7f7959778c |
23
src/util.h
23
src/util.h
@ -246,6 +246,19 @@ enum class ExtendedChar {
|
|||||||
GreekSmallLetterPhi = 0xed,
|
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:
|
* Message syntax:
|
||||||
* separator: ~
|
* separator: ~
|
||||||
@ -299,13 +312,5 @@ void sendTextToSign(
|
|||||||
Serial1.print(toSend);
|
Serial1.print(toSend);
|
||||||
|
|
||||||
Serial.println("Text sent to device: " + toSend);
|
Serial.println("Text sent to device: " + toSend);
|
||||||
Serial.print("Hex dump: ");
|
Serial.println("Hex dump: " + hexDump(toSend));
|
||||||
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,6 +66,21 @@ namespace {
|
|||||||
sendTextToSign(text);
|
sendTextToSign(text);
|
||||||
webServer.send(200, "text/plain", "ok");
|
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() {
|
void configureWebServer() {
|
||||||
@ -74,4 +89,5 @@ void configureWebServer() {
|
|||||||
webServer.on("/", HTTPMethod::HTTP_GET, handleIndex);
|
webServer.on("/", HTTPMethod::HTTP_GET, handleIndex);
|
||||||
webServer.on("/", HTTPMethod::HTTP_POST, handleFormSend);
|
webServer.on("/", HTTPMethod::HTTP_POST, handleFormSend);
|
||||||
webServer.on("/send", HTTPMethod::HTTP_POST, handleApiSend);
|
webServer.on("/send", HTTPMethod::HTTP_POST, handleApiSend);
|
||||||
|
webServer.on("/raw", HTTPMethod::HTTP_POST, handleRawApiSend);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user