mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Arduino v7
This commit is contained in:
@@ -71,15 +71,15 @@ void WebDataService::scan_devices(AsyncWebServerRequest * request) {
|
||||
// this is used in the dashboard and contains all ems device information
|
||||
// /coreData endpoint
|
||||
void WebDataService::core_data(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
// list is already sorted by device type
|
||||
JsonArray devices = root.createNestedArray("devices");
|
||||
JsonArray devices = root["devices"].to<JsonArray>();
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
// ignore controller
|
||||
if (emsdevice && (emsdevice->device_type() != EMSdevice::DeviceType::CONTROLLER || emsdevice->count_entities() > 0)) {
|
||||
JsonObject obj = devices.createNestedObject();
|
||||
JsonObject obj = devices.add<JsonObject>();
|
||||
obj["id"] = emsdevice->unique_id(); // a unique id
|
||||
obj["tn"] = emsdevice->device_type_2_device_name_translated(); // translated device type name
|
||||
obj["t"] = emsdevice->device_type(); // device type number
|
||||
@@ -95,7 +95,7 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
|
||||
// add any custom entities
|
||||
uint8_t customEntities = EMSESP::webCustomEntityService.count_entities();
|
||||
if (customEntities) {
|
||||
JsonObject obj = devices.createNestedObject();
|
||||
JsonObject obj = devices.add<JsonObject>();
|
||||
obj["id"] = 99; // the last unique id
|
||||
obj["tn"] = Helpers::translated_word(FL_(custom_device)); // translated device type name
|
||||
obj["t"] = EMSdevice::DeviceType::CUSTOM; // device type number
|
||||
@@ -116,14 +116,14 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
|
||||
// sensor data - sends back to web
|
||||
// /sensorData endpoint
|
||||
void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
// temperature sensors
|
||||
JsonArray sensors = root.createNestedArray("ts");
|
||||
JsonArray sensors = root["ts"].to<JsonArray>();
|
||||
if (EMSESP::temperaturesensor_.have_sensors()) {
|
||||
for (const auto & sensor : EMSESP::temperaturesensor_.sensors()) {
|
||||
JsonObject obj = sensors.createNestedObject();
|
||||
JsonObject obj = sensors.add<JsonObject>();
|
||||
obj["id"] = sensor.id(); // id as string
|
||||
obj["n"] = sensor.name(); // name
|
||||
if (EMSESP::system_.fahrenheit()) {
|
||||
@@ -143,11 +143,11 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
// analog sensors
|
||||
JsonArray analogs = root.createNestedArray("as");
|
||||
JsonArray analogs = root["as"].to<JsonArray>();
|
||||
if (EMSESP::analog_enabled() && EMSESP::analogsensor_.have_sensors()) {
|
||||
uint8_t count = 0;
|
||||
for (const auto & sensor : EMSESP::analogsensor_.sensors()) {
|
||||
JsonObject obj = analogs.createNestedObject();
|
||||
JsonObject obj = analogs.add<JsonObject>();
|
||||
obj["id"] = ++count; // needed for sorting table
|
||||
obj["g"] = sensor.gpio();
|
||||
obj["n"] = sensor.name();
|
||||
@@ -178,15 +178,14 @@ void WebDataService::device_data(AsyncWebServerRequest * request) {
|
||||
if (request->hasParam(F_(id))) {
|
||||
id = Helpers::atoint(request->getParam(F_(id))->value().c_str()); // get id from url
|
||||
|
||||
size_t buffer = EMSESP_JSON_SIZE_XXXXLARGE;
|
||||
auto * response = new MsgpackAsyncJsonResponse(false, buffer);
|
||||
auto * response = new MsgpackAsyncJsonResponse(false);
|
||||
|
||||
// check size
|
||||
while (!response) {
|
||||
delete response;
|
||||
buffer -= 1024;
|
||||
response = new MsgpackAsyncJsonResponse(false, buffer);
|
||||
}
|
||||
// while (!response) {
|
||||
// delete response;
|
||||
// buffer -= 1024;
|
||||
// response = new MsgpackAsyncJsonResponse(false, buffer);
|
||||
// }
|
||||
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice->unique_id() == id) {
|
||||
@@ -249,7 +248,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
||||
cmd = Command::parse_command_string(cmd, id); // extract hc or wwc
|
||||
|
||||
// create JSON for output
|
||||
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_SMALL);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject output = response->getRoot();
|
||||
|
||||
// the data could be in any format, but we need string
|
||||
@@ -289,7 +288,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
||||
// parse the command as it could have a hc or wwc prefixed, e.g. hc2/seltemp
|
||||
int8_t id = -1;
|
||||
cmd = Command::parse_command_string(cmd, id);
|
||||
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_SMALL);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject output = response->getRoot();
|
||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
||||
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;
|
||||
|
||||
Reference in New Issue
Block a user