mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 11:02:12 +01:00
Stream all responses. Fix missing ETH IP address #310
This commit is contained in:
parent
6ba354c7ff
commit
026f9315b1
19 changed files with 1361 additions and 456 deletions
68
WResp.h
Normal file
68
WResp.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#include <WebServer.h>
|
||||
#include <WebSocketsServer.h>
|
||||
#include "Somfy.h"
|
||||
#ifndef wresp_h
|
||||
#define wresp_h
|
||||
|
||||
class JsonFormatter {
|
||||
protected:
|
||||
char *buff;
|
||||
size_t buffSize;
|
||||
bool _headersSent = false;
|
||||
uint8_t _objects = 0;
|
||||
uint8_t _arrays = 0;
|
||||
bool _nocomma = true;
|
||||
char _numbuff[25] = {0};
|
||||
virtual void _safecat(const char *val, bool escape = false);
|
||||
void _appendNumber(const char *name);
|
||||
public:
|
||||
void beginObject(const char *name = nullptr);
|
||||
void endObject();
|
||||
void beginArray(const char *name = nullptr);
|
||||
void endArray();
|
||||
void appendElem(const char *name = nullptr);
|
||||
|
||||
void addElem(const char* val);
|
||||
void addElem(float fval);
|
||||
void addElem(int8_t nval);
|
||||
void addElem(uint8_t nval);
|
||||
void addElem(int16_t nval);
|
||||
void addElem(uint16_t nval);
|
||||
void addElem(int32_t nval);
|
||||
void addElem(uint32_t nval);
|
||||
void addElem(int64_t lval);
|
||||
void addElem(uint64_t lval);
|
||||
void addElem(bool bval);
|
||||
|
||||
void addElem(const char* name, float fval);
|
||||
void addElem(const char* name, int8_t nval);
|
||||
void addElem(const char* name, uint8_t nval);
|
||||
void addElem(const char* name, int16_t nval);
|
||||
void addElem(const char* name, uint16_t nval);
|
||||
void addElem(const char* name, int32_t nval);
|
||||
void addElem(const char* name, uint32_t nval);
|
||||
void addElem(const char* name, int64_t lval);
|
||||
void addElem(const char* name, uint64_t lval);
|
||||
void addElem(const char* name, bool bval);
|
||||
void addElem(const char *name, const char *val);
|
||||
};
|
||||
class JsonResponse : public JsonFormatter {
|
||||
protected:
|
||||
void _safecat(const char *val, bool escape = false) override;
|
||||
public:
|
||||
WebServer *server;
|
||||
void beginResponse(WebServer *server, char *buff, size_t buffSize);
|
||||
void endResponse();
|
||||
void send();
|
||||
};
|
||||
class JsonSockEvent : public JsonFormatter {
|
||||
protected:
|
||||
bool _closed = false;
|
||||
void _safecat(const char *val, bool escape = false) override;
|
||||
public:
|
||||
WebSocketsServer *server = nullptr;
|
||||
void beginEvent(WebSocketsServer *server, const char *evt, char *buff, size_t buffSize);
|
||||
void endEvent(uint8_t clientNum = 255);
|
||||
void closeEvent();
|
||||
};
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue