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:
@@ -96,7 +96,7 @@ bool System::command_send(const char * value, const int8_t id) {
|
||||
}
|
||||
|
||||
bool System::command_response(const char * value, const int8_t id, JsonObject & output) {
|
||||
DynamicJsonDocument doc(EMSESP_JSON_SIZE_LARGE);
|
||||
JsonDocument doc;
|
||||
if (DeserializationError::Ok == deserializeJson(doc, Mqtt::get_response())) {
|
||||
for (JsonPair p : doc.as<JsonObject>()) {
|
||||
output[p.key()] = p.value();
|
||||
@@ -110,23 +110,23 @@ bool System::command_response(const char * value, const int8_t id, JsonObject &
|
||||
// output all the EMS devices and their values, plus the sensors and any custom entities
|
||||
// not scheduler as these are records with no output data
|
||||
bool System::command_allvalues(const char * value, const int8_t id, JsonObject & output) {
|
||||
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXXLARGE);
|
||||
JsonObject device_output;
|
||||
JsonDocument doc;
|
||||
JsonObject device_output;
|
||||
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
|
||||
device_output = output.createNestedObject(title);
|
||||
device_output = output[title].add<JsonObject>();
|
||||
emsdevice->generate_values(device_output, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::API_VERBOSE); // use nested for id -1 and 0
|
||||
}
|
||||
|
||||
// Custom entities
|
||||
device_output = output.createNestedObject("Custom Entities");
|
||||
device_output = output["Custom Entities"].add<JsonObject>();
|
||||
EMSESP::webCustomEntityService.get_value_info(device_output, "");
|
||||
|
||||
// Sensors
|
||||
device_output = output.createNestedObject("Analog Sensors");
|
||||
device_output = output["Analog Sensors"].add<JsonObject>();
|
||||
EMSESP::analogsensor_.command_info(nullptr, 0, device_output);
|
||||
device_output = output.createNestedObject("Temperature Sensors");
|
||||
device_output = output["Temperature Sensors"].add<JsonObject>();
|
||||
EMSESP::temperaturesensor_.command_info(nullptr, 0, device_output);
|
||||
|
||||
return true;
|
||||
@@ -583,7 +583,7 @@ void System::send_info_mqtt() {
|
||||
return;
|
||||
}
|
||||
_connection = connection;
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> doc;
|
||||
JsonDocument doc;
|
||||
doc["event"] = "connected";
|
||||
doc["version"] = EMSESP_APP_VERSION;
|
||||
|
||||
@@ -694,8 +694,8 @@ void System::send_heartbeat() {
|
||||
|
||||
refreshHeapMem(); // refresh free heap and max alloc heap
|
||||
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> doc;
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
JsonDocument doc;
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
|
||||
if (heartbeat_json(json)) {
|
||||
Mqtt::queue_publish(F_(heartbeat), json); // send to MQTT with retain off. This will add to MQTT queue.
|
||||
@@ -1048,8 +1048,8 @@ bool System::check_restore() {
|
||||
// see if we have a temp file, if so try and read it
|
||||
File new_file = LittleFS.open(TEMP_FILENAME_PATH);
|
||||
if (new_file) {
|
||||
DynamicJsonDocument jsonDocument = DynamicJsonDocument(FS_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(jsonDocument, new_file);
|
||||
JsonDocument jsonDocument;
|
||||
DeserializationError error = deserializeJson(jsonDocument, new_file);
|
||||
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||
JsonObject input = jsonDocument.as<JsonObject>();
|
||||
// see what type of file it is, either settings or customization. anything else is ignored
|
||||
@@ -1174,11 +1174,11 @@ void System::extractSettings(const char * filename, const char * section, JsonOb
|
||||
#ifndef EMSESP_STANDALONE
|
||||
File settingsFile = LittleFS.open(filename);
|
||||
if (settingsFile) {
|
||||
DynamicJsonDocument jsonDocument = DynamicJsonDocument(FS_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||
JsonDocument jsonDocument;
|
||||
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
||||
JsonObject node = output.createNestedObject(section);
|
||||
JsonObject node = output[section].add<JsonObject>();
|
||||
for (JsonPair kvp : jsonObject) {
|
||||
node[kvp.key()] = kvp.value();
|
||||
}
|
||||
@@ -1211,7 +1211,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
JsonObject node;
|
||||
|
||||
// System
|
||||
node = output.createNestedObject("System Info");
|
||||
node = output["System Info"].add<JsonObject>();
|
||||
node["version"] = EMSESP_APP_VERSION;
|
||||
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
||||
node["uptime (seconds)"] = uuid::get_uptime_sec();
|
||||
@@ -1228,7 +1228,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
// Network Status
|
||||
node = output.createNestedObject("Network Info");
|
||||
node = output["Network Info"].add<JsonObject>();
|
||||
if (EMSESP::system_.ethernet_connected()) {
|
||||
node["network"] = "Ethernet";
|
||||
node["hostname"] = ETH.getHostname();
|
||||
@@ -1276,7 +1276,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
#endif
|
||||
|
||||
// NTP status
|
||||
node = output.createNestedObject("NTP Info");
|
||||
node = output["NTP Info"].add<JsonObject>();
|
||||
#ifndef EMSESP_STANDALONE
|
||||
node["NTP status"] = EMSESP::system_.ntp_connected() ? "connected" : "disconnected";
|
||||
EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) {
|
||||
@@ -1287,7 +1287,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
});
|
||||
|
||||
// OTA status
|
||||
node = output.createNestedObject("OTA Info");
|
||||
node = output["OTA Info"].add<JsonObject>();
|
||||
EMSESP::esp8266React.getOTASettingsService()->read([&](OTASettings & settings) {
|
||||
node["enabled"] = settings.enabled;
|
||||
node["port"] = settings.port;
|
||||
@@ -1295,7 +1295,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
#endif
|
||||
|
||||
// MQTT Status
|
||||
node = output.createNestedObject("MQTT Info");
|
||||
node = output["MQTT Info"].add<JsonObject>();
|
||||
node["MQTT status"] = Mqtt::connected() ? F_(connected) : F_(disconnected);
|
||||
if (Mqtt::enabled()) {
|
||||
node["MQTT publishes"] = Mqtt::publish_count();
|
||||
@@ -1329,7 +1329,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
});
|
||||
|
||||
// Syslog Status
|
||||
node = output.createNestedObject("Syslog Info");
|
||||
node = output["Syslog Info"].add<JsonObject>();
|
||||
node["enabled"] = EMSESP::system_.syslog_enabled_;
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (EMSESP::system_.syslog_enabled_) {
|
||||
@@ -1341,7 +1341,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
#endif
|
||||
|
||||
// Sensor Status
|
||||
node = output.createNestedObject("Sensor Info");
|
||||
node = output["Sensor Info"].add<JsonObject>();
|
||||
if (EMSESP::sensor_enabled()) {
|
||||
node["temperature sensors"] = EMSESP::temperaturesensor_.no_sensors();
|
||||
node["temperature sensor reads"] = EMSESP::temperaturesensor_.reads();
|
||||
@@ -1354,12 +1354,12 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
}
|
||||
|
||||
// API Status
|
||||
node = output.createNestedObject("API Info");
|
||||
node = output["API Info"].add<JsonObject>();
|
||||
node["API calls"] = WebAPIService::api_count();
|
||||
node["API fails"] = WebAPIService::api_fails();
|
||||
|
||||
// EMS Bus Status
|
||||
node = output.createNestedObject("Bus Info");
|
||||
node = output["Bus Info"].add<JsonObject>();
|
||||
switch (EMSESP::bus_status()) {
|
||||
case EMSESP::BUS_STATUS_OFFLINE:
|
||||
node["bus status"] = "disconnected";
|
||||
@@ -1387,7 +1387,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
}
|
||||
|
||||
// Settings
|
||||
node = output.createNestedObject("Settings");
|
||||
node = output["Settings"].add<JsonObject>();
|
||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||
node["board profile"] = settings.board_profile;
|
||||
node["locale"] = settings.locale;
|
||||
@@ -1428,11 +1428,11 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
|
||||
// Devices - show EMS devices if we have any
|
||||
if (!EMSESP::emsdevices.empty()) {
|
||||
JsonArray devices = output.createNestedArray("Devices");
|
||||
JsonArray devices = output["Devices"].to<JsonArray>();
|
||||
for (const auto & device_class : EMSFactory::device_handlers()) {
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_class.first)) {
|
||||
JsonObject obj = devices.createNestedObject();
|
||||
JsonObject obj = devices.add<JsonObject>();
|
||||
obj["type"] = emsdevice->device_type_name(); // non translated name
|
||||
obj["name"] = emsdevice->name();
|
||||
obj["device id"] = Helpers::hextoa(emsdevice->device_id());
|
||||
|
||||
Reference in New Issue
Block a user