diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp index 2b9c877..b11e46b 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.cpp @@ -66,6 +66,10 @@ void ESPMegaIoT::mqttCallback(char *topic, byte *payload, unsigned int length) } } } + // Check for global summary request + if (!strcmp(topic_without_base,"requestinfo")) { + this->publishSystemSummary(); + } // Call the respective card's mqtt callback // Note that after the base topic, there should be the card id // /base_topic/card_id/... @@ -844,3 +848,35 @@ String ESPMegaIoT::getMac() else return this->getETHMac(); } + +/** + * @brief Publish a json object containing the system summary + */ +void ESPMegaIoT::publishSystemSummary() { + char payload[1024]; + StaticJsonDocument<1024> doc; + JsonObject root = doc.to(); + root["ip"] = this->getIp().toString(); + root["mac"] = this->getMac(); + root["mqtt_connected"] = this->mqttConnected(); + root["network_connected"] = this->networkConnected(); + root["mqtt_server"] = this->mqtt_config.mqtt_server; + root["mqtt_port"] = this->mqtt_config.mqtt_port; + root["hostname"] = this->network_config.hostname; + root["firmware"] = SW_VERSION; + root["idf_version"] = esp_get_idf_version(); + root["sdk_version"] = SDK_VESRION; + root["board_model"] = BOARD_MODEL; + JsonArray cards = root.createNestedArray("cards"); + for (int i = 0; i < 255; i++) + { + if (components[i] != NULL) + { + JsonObject card = cards.createNestedObject(); + card["id"] = i; + card["type"] = components[i]->getType(); + } + } + serializeJson(doc, payload); + this->publishRelative("info", payload); +} \ No newline at end of file diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp index c5467b2..d47f723 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaIoT.hpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include // MQTT Connection Parameters #define TCP_TIMEOUT_SEC 5 @@ -115,6 +117,7 @@ public: void bindEthernetInterface(ETHClass *ethernetIface); bool networkConnected(); void bindFRAM(FRAM *fram); + void publishSystemSummary(); IoTComponent* getComponent(uint8_t card_id); IPAddress getETHIp();