Websocket Json Server
by Erik Palsbo
This library for ESP8266 and ESP32 provides a webserver and a websocket connection where JSON is used to communicate messages via websocket.
The library provides automatic reconnect for websocket.
Download: WebsocJsonServer.zip
Typedefs
typedef void (*onreceivedef)(String &data, JsonObject& root);
typedef void (*onsenddef)(JsonObject& root);
typedef bool (*onconnectdef)(uint8_t num, IPAddress ip, String data);
typedef void (*ondisconnectdef) (uint8_t num);
typedef std::function THandlerFunction;
Methodes
void broadcast();
Broadcast websocket message.
void httpsend(int code, char* content_type, const String& content);
Send http message.
void httpsend(int code, const String& content_type, const String& content);
Send http message.
void begin(bool debug);
Initiate webserver and websocket.
- begin must always be placed in begin().
void begin(bool debug, String defhtml);
Initiate webserver and websocket with default webserver page.
- begin must always be placed in begin().
void loop();
Always place ein loop()
Functions
none.
Events
bool onConnect(onconnectdef cb);
Function called on connect;
void onDisconnect(ondisconnectdef cb);
Function called on disconnect
void on(const String &uri, THandlerFunction handler);
Function called on http msg received;
If not used, http messages is assumed placed in SPI.
void on(const String &uri, HTTPMethod method, THandlerFunction fn);
Function called on http msg received;
If not used, http messages is assumed placed in SPIFS void on(const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
Function called on http msg received;
If not used, http messages is assumed placed in SPIFS
void onReceive(onreceivedef cb);
Called on JSON received from websocket.
void beforeSend(onsenddef cb);
Called before send (or broadcast) JSON on websocket.