mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 11:02:12 +01:00
Chunk single group response #316
This commit is contained in:
parent
610773c6b7
commit
6ba354c7ff
4 changed files with 35 additions and 19 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
#ifndef configsettings_h
|
#ifndef configsettings_h
|
||||||
#define configsettings_h
|
#define configsettings_h
|
||||||
|
|
||||||
#define FW_VERSION "v2.4.1"
|
#define FW_VERSION "v2.4.2"
|
||||||
enum DeviceStatus {
|
enum DeviceStatus {
|
||||||
DS_OK = 0,
|
DS_OK = 0,
|
||||||
DS_ERROR = 1,
|
DS_ERROR = 1,
|
||||||
|
|
|
||||||
Binary file not shown.
50
Web.cpp
50
Web.cpp
|
|
@ -5,10 +5,10 @@
|
||||||
#include "mbedtls/md.h"
|
#include "mbedtls/md.h"
|
||||||
#include "ConfigSettings.h"
|
#include "ConfigSettings.h"
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
#include "Web.h"
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "SSDP.h"
|
#include "SSDP.h"
|
||||||
#include "Somfy.h"
|
#include "Somfy.h"
|
||||||
|
#include "Web.h"
|
||||||
#include "MQTT.h"
|
#include "MQTT.h"
|
||||||
#include "GitOTA.h"
|
#include "GitOTA.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
|
|
@ -262,20 +262,36 @@ void Web::chunkShadesResponse(WebServer &server, const char * elem) {
|
||||||
}
|
}
|
||||||
server.sendContent(ndx == 0 ? "[]" : "]");
|
server.sendContent(ndx == 0 ? "[]" : "]");
|
||||||
}
|
}
|
||||||
|
void Web::chunkGroupResponse(WebServer &server, SomfyGroup * grp, const char *prefix) {
|
||||||
|
grp->updateFlags();
|
||||||
|
snprintf(g_content, sizeof(g_content), "%s{\"groupId\":%d,\"roomId\":%d,\"name\":\"%s\",\"remoteAddress\":%d,\"lastRollingCode\":%d,\"bitLength\":%d,\"proto\":%d,\"sunSensor\":%s,\"flipCommands\":%s,\"flags\":%d,\"repeats\":%d,\"sortOrder\":%d,\"linkedShades\":[ ",
|
||||||
|
prefix ? prefix : "", grp->getGroupId(), grp->roomId, grp->name, grp->getRemoteAddress(), grp->lastRollingCode, grp->bitLength, static_cast<uint8_t>(grp->proto), grp->hasSunSensor() ? "true" : "false", grp->flipCommands ? "true" : "false", grp->flags, grp->repeats, grp->sortOrder);
|
||||||
|
server.sendContent(g_content);
|
||||||
|
uint8_t n = 0;
|
||||||
|
for(uint8_t i = 0; i < SOMFY_MAX_GROUPED_SHADES; i++) {
|
||||||
|
uint8_t shadeId = grp->linkedShades[i];
|
||||||
|
if(shadeId > 0 && shadeId < 255) {
|
||||||
|
SomfyShade *shade = somfy.getShadeById(shadeId);
|
||||||
|
if(shade) {
|
||||||
|
snprintf(g_content, sizeof(g_content), "%s{\"shadeId\":%d,\"roomId\":%d,\"name\":\"%s\",\"remoteAddress\":%d,\"paired\":%s,\"shadeType\":%d,\"bitLength\":%d,\"proto\":%d,\"flags\":%d,\"sunSensor\":%s,\"hasLight\":%s,\"repeats\":%d}",
|
||||||
|
n == 0 ? "" : ",", shade->getShadeId(), shade->roomId, shade->name, shade->getRemoteAddress(), shade->paired ? "true" : "false", static_cast<uint8_t>(shade->shadeType), shade->bitLength, static_cast<uint8_t>(shade->proto), shade->flags,
|
||||||
|
shade->hasSunSensor() ? "true" : "false", shade->hasLight() ? "true" : "false", shade->repeats);
|
||||||
|
server.sendContent(g_content);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
server.sendContent("]}");
|
||||||
|
}
|
||||||
void Web::chunkGroupsResponse(WebServer &server, const char * elem) {
|
void Web::chunkGroupsResponse(WebServer &server, const char * elem) {
|
||||||
uint8_t ndx = 0;
|
uint8_t ndx = 0;
|
||||||
if(elem && strlen(elem) > 0) {
|
if(elem && strlen(elem) > 0) {
|
||||||
sprintf(g_content, "\"%s\"", elem);
|
sprintf(g_content, "\"%s\":", elem);
|
||||||
server.sendContent(g_content);
|
server.sendContent(g_content);
|
||||||
}
|
}
|
||||||
for(uint8_t i = 0; i < SOMFY_MAX_GROUPS; i++) {
|
for(uint8_t i = 0; i < SOMFY_MAX_GROUPS; i++) {
|
||||||
if(somfy.groups[i].getGroupId() != 255) {
|
if(somfy.groups[i].getGroupId() != 255) {
|
||||||
DynamicJsonDocument doc(8192);
|
this->chunkGroupResponse(server, &somfy.groups[i], ndx++ != 0 ? "," : "[");
|
||||||
JsonObject obj = doc.to<JsonObject>();
|
|
||||||
somfy.groups[i].toJSON(obj);
|
|
||||||
strcpy(g_content, ndx++ != 0 ? "," : "[");
|
|
||||||
serializeJson(doc, &g_content[strlen(g_content)], sizeof(g_content) - strlen(g_content));
|
|
||||||
server.sendContent(g_content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server.sendContent(ndx == 0 ? "[]" : "]");
|
server.sendContent(ndx == 0 ? "[]" : "]");
|
||||||
|
|
@ -562,11 +578,10 @@ void Web::handleGroupCommand(WebServer &server) {
|
||||||
// Send the command to the group.
|
// Send the command to the group.
|
||||||
if(repeat > 0) group->sendCommand(command, repeat);
|
if(repeat > 0) group->sendCommand(command, repeat);
|
||||||
else group->sendCommand(command);
|
else group->sendCommand(command);
|
||||||
DynamicJsonDocument sdoc(512);
|
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
JsonObject sobj = sdoc.to<JsonObject>();
|
server.send_P(200, _encoding_json, " ");
|
||||||
group->toJSON(sobj);
|
this->chunkGroupResponse(server, group);
|
||||||
serializeJson(sdoc, g_content);
|
server.sendContent("", 0);
|
||||||
server.send(200, _encoding_json, g_content);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group with the specified id not found.\"}"));
|
server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group with the specified id not found.\"}"));
|
||||||
|
|
@ -761,11 +776,10 @@ void Web::handleGroup(WebServer &server) {
|
||||||
int groupId = atoi(server.arg("groupId").c_str());
|
int groupId = atoi(server.arg("groupId").c_str());
|
||||||
SomfyGroup* group = somfy.getGroupById(groupId);
|
SomfyGroup* group = somfy.getGroupById(groupId);
|
||||||
if (group) {
|
if (group) {
|
||||||
DynamicJsonDocument doc(2048);
|
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
JsonObject obj = doc.to<JsonObject>();
|
server.send_P(200, _encoding_json, " ");
|
||||||
group->toJSON(obj);
|
this->chunkGroupResponse(server, group);
|
||||||
serializeJson(doc, g_content);
|
server.sendContent("", 0);
|
||||||
server.send(200, _encoding_json, g_content);
|
|
||||||
}
|
}
|
||||||
else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group Id not found.\"}"));
|
else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group Id not found.\"}"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
Web.h
2
Web.h
|
|
@ -1,4 +1,5 @@
|
||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
|
#include "Somfy.h"
|
||||||
#ifndef webserver_h
|
#ifndef webserver_h
|
||||||
#define webserver_h
|
#define webserver_h
|
||||||
class Web {
|
class Web {
|
||||||
|
|
@ -44,6 +45,7 @@ class Web {
|
||||||
void chunkRoomsResponse(WebServer &server, const char *elem = nullptr);
|
void chunkRoomsResponse(WebServer &server, const char *elem = nullptr);
|
||||||
void chunkShadesResponse(WebServer &server, const char *elem = nullptr);
|
void chunkShadesResponse(WebServer &server, const char *elem = nullptr);
|
||||||
void chunkGroupsResponse(WebServer &server, const char *elem = nullptr);
|
void chunkGroupsResponse(WebServer &server, const char *elem = nullptr);
|
||||||
|
void chunkGroupResponse(WebServer &server, SomfyGroup *, const char *prefix = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue