Skip to content

Commit 4162164

Browse files
committed
Added back Websocket support
Also includes Basic Auth as a byproduct of latest Arduino mongoose library. Fixes #27 Fixes #28
1 parent 1868575 commit 4162164

File tree

2 files changed

+7
-37
lines changed

2 files changed

+7
-37
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ version = -DBUILD_TAG=3.0.2
3434
monitor_speed = 115200
3535
lib_deps =
3636
37-
37+
3838
extra_scripts = scripts/extra_script.py
3939
debug_flags =
4040
-DENABLE_DEBUG

src/web_server.cpp

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -967,49 +967,17 @@ void handleNotFound(MongooseHttpServerRequest *request)
967967
}
968968
}
969969

970-
/*
971-
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
972-
if(type == WS_EVT_CONNECT) {
973-
DBUGF("ws[%s][%u] connect", server->url(), client->id());
974-
client->ping();
975-
} else if(type == WS_EVT_DISCONNECT) {
976-
DBUGF("ws[%s][%u] disconnect: %u", server->url(), client->id());
977-
} else if(type == WS_EVT_ERROR) {
978-
DBUGF("ws[%s][%u] error(%u): %s", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
979-
} else if(type == WS_EVT_PONG) {
980-
DBUGF("ws[%s][%u] pong[%u]: %s", server->url(), client->id(), len, (len)?(char*)data:"");
981-
} else if(type == WS_EVT_DATA) {
982-
AwsFrameInfo * info = (AwsFrameInfo*)arg;
983-
String msg = "";
984-
if(info->final && info->index == 0 && info->len == len)
985-
{
986-
//the whole message is in a single frame and we got all of it's data
987-
DBUGF("ws[%s][%u] %s-message[%u]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", len);
988-
} else {
989-
// TODO: handle messages that are comprised of multiple frames or the frame is split into multiple packets
990-
}
991-
}
970+
void onWsFrame(MongooseHttpWebSocketConnection *connection, int flags, uint8_t *data, size_t len)
971+
{
972+
DBUGF("Got message %.*s", len, (const char *)data);
992973
}
993-
*/
994974

995975
void
996976
web_server_setup() {
997977
// SPIFFS.begin(); // mount the fs
998978

999979
server.begin(80);
1000980

1001-
// Setup the static files
1002-
// server.serveStatic("/", SPIFFS, "/")
1003-
// .setDefaultFile("index.html");
1004-
1005-
// Add the Web Socket server
1006-
// ws.onEvent(onWsEvent);
1007-
// server.addHandler(&ws);
1008-
// server.addHandler(&staticFile);
1009-
1010-
// Start server & server root html /
1011-
//server.on("/", handleHome);
1012-
1013981
// Handle status updates
1014982
server.on("/status$", handleStatus);
1015983
server.on("/config$", handleConfig);
@@ -1042,6 +1010,8 @@ web_server_setup() {
10421010
onUpload(handleUpdateUpload)->
10431011
onClose(handleUpdateClose);
10441012

1013+
server.on("/ws$")->onFrame(onWsFrame);
1014+
10451015
server.onNotFound(handleNotFound);
10461016

10471017
DEBUG.println("Server started");
@@ -1081,5 +1051,5 @@ web_server_loop() {
10811051

10821052
void web_server_event(String &event)
10831053
{
1084-
//ws.textAll(event);
1054+
server.sendAll(event);
10851055
}

0 commit comments

Comments
 (0)