-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SysModWeb: - ws-> to ws. - server-> to server. - ws.onEvent, server.addHandler and server.on using lambda functions
- Loading branch information
Showing
5 changed files
with
73 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,18 +37,25 @@ | |
class SysModWeb:public SysModule { | ||
|
||
public: | ||
static WebSocket *ws;// = nullptr; | ||
static SemaphoreHandle_t wsMutex;// = xSemaphoreCreateMutex(); | ||
|
||
static unsigned8 sendWsCounter;// = 0; | ||
static unsigned16 sendWsTBytes;// = 0; | ||
static unsigned16 sendWsBBytes;// = 0; | ||
static unsigned8 recvWsCounter;// = 0; | ||
static unsigned16 recvWsBytes;// = 0; | ||
static unsigned8 sendUDPCounter;// = 0; | ||
static unsigned16 sendUDPBytes;// = 0; | ||
static unsigned8 recvUDPCounter;// = 0; | ||
static unsigned16 recvUDPBytes;// = 0; | ||
#ifdef STARMOD_USE_Psychic | ||
WebSocket ws = WebSocket(); | ||
WebServer server = WebServer(); | ||
#else | ||
WebSocket ws = WebSocket("/ws"); | ||
WebServer server = WebServer(80); | ||
#endif | ||
|
||
SemaphoreHandle_t wsMutex = xSemaphoreCreateMutex(); | ||
|
||
unsigned8 sendWsCounter = 0; | ||
unsigned16 sendWsTBytes = 0; | ||
unsigned16 sendWsBBytes = 0; | ||
unsigned8 recvWsCounter = 0; | ||
unsigned16 recvWsBytes = 0; | ||
unsigned8 sendUDPCounter = 0; | ||
unsigned16 sendUDPBytes = 0; | ||
unsigned8 recvUDPCounter = 0; | ||
unsigned16 recvUDPBytes = 0; | ||
|
||
SysModWeb(); | ||
|
||
|
@@ -60,23 +67,23 @@ class SysModWeb:public SysModule { | |
|
||
void connectedChanged(); | ||
|
||
static void wsEvent(WebSocket * ws, WebClient * client, AwsEventType type, void * arg, byte *data, size_t len); | ||
void wsEvent(WebSocket * ws, WebClient * client, AwsEventType type, void * arg, byte *data, size_t len); | ||
|
||
//send json to client or all clients | ||
static void sendDataWs(JsonVariant json = JsonVariant(), WebClient * client = nullptr); | ||
static void sendDataWs(std::function<void(AsyncWebSocketMessageBuffer *)> fill, size_t len, bool isBinary, WebClient * client = nullptr); | ||
void sendDataWs(JsonVariant json = JsonVariant(), WebClient * client = nullptr); | ||
void sendDataWs(std::function<void(AsyncWebSocketMessageBuffer *)> fill, size_t len, bool isBinary, WebClient * client = nullptr); | ||
|
||
//add an url to the webserver to listen to | ||
static void serveIndex(WebRequest *request); | ||
void serveIndex(WebRequest *request); | ||
//mdl and WLED style state and info | ||
static void serveJson(WebRequest *request); | ||
void serveJson(WebRequest *request); | ||
|
||
|
||
// curl -F '[email protected]' 192.168.8.213/upload | ||
static void serveUpload(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final); | ||
void serveUpload(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final); | ||
// curl -s -F "update=@/Users/ewoudwijma/Developer/GitHub/ewowi/StarMod/.pio/build/esp32dev/firmware.bin" 192.168.8.102/update /dev/null & | ||
static void serveUpdate(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final); | ||
static void serveFiles(WebRequest *request); | ||
void serveUpdate(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final); | ||
void serveFiles(WebRequest *request); | ||
|
||
//processJsonUrl handles requests send in javascript using fetch and from a browser or curl | ||
//try this !!!: curl -X POST "http://192.168.121.196/json" -d '{"pin2":false}' -H "Content-Type: application/json" | ||
|
@@ -86,7 +93,7 @@ class SysModWeb:public SysModule { | |
//curl -X POST "http://192.168.8.152/json" -d '{"nrOfLeds":2000}' -H "Content-Type: application/json" | ||
|
||
//handle "v" and processJson (on /json) | ||
static void jsonHandler(WebRequest *request, JsonVariant json); | ||
void jsonHandler(WebRequest *request, JsonVariant json); | ||
|
||
//Is this an IP? | ||
bool isIp(String str) { | ||
|
@@ -158,17 +165,15 @@ class SysModWeb:public SysModule { | |
JsonObject getResponseObject(); | ||
void sendResponseObject(WebClient * client = nullptr); | ||
|
||
static void printClient(const char * text, WebClient * client) { | ||
void printClient(const char * text, WebClient * client) { | ||
USER_PRINTF("%s client: %d ...%d q:%d l:%d s:%d (#:%d)\n", text, client?client->id():-1, client?client->remoteIP()[3]:-1, client->queueIsFull(), client->queueLength(), client->status(), client->server()->count()); | ||
//status: { WS_DISCONNECTED, WS_CONNECTED, WS_DISCONNECTING } | ||
} | ||
|
||
private: | ||
bool modelUpdated = false; | ||
|
||
static bool clientsChanged;// = false;; | ||
|
||
static WebServer *server;// = nullptr; | ||
bool clientsChanged = false; | ||
|
||
JsonDocument *responseDocLoopTask = nullptr; | ||
JsonDocument *responseDocAsyncTCP = nullptr; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters