mqtt summary request
This commit is contained in:
parent
ea49576b20
commit
3e7d3041f2
|
@ -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
|
// Call the respective card's mqtt callback
|
||||||
// Note that after the base topic, there should be the card id
|
// Note that after the base topic, there should be the card id
|
||||||
// /base_topic/card_id/...
|
// /base_topic/card_id/...
|
||||||
|
@ -844,3 +848,35 @@ String ESPMegaIoT::getMac()
|
||||||
else
|
else
|
||||||
return this->getETHMac();
|
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<JsonObject>();
|
||||||
|
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);
|
||||||
|
}
|
|
@ -16,6 +16,8 @@
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <FRAM.h>
|
#include <FRAM.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <ESPMegaCommon.hpp>
|
||||||
|
|
||||||
// MQTT Connection Parameters
|
// MQTT Connection Parameters
|
||||||
#define TCP_TIMEOUT_SEC 5
|
#define TCP_TIMEOUT_SEC 5
|
||||||
|
@ -115,6 +117,7 @@ public:
|
||||||
void bindEthernetInterface(ETHClass *ethernetIface);
|
void bindEthernetInterface(ETHClass *ethernetIface);
|
||||||
bool networkConnected();
|
bool networkConnected();
|
||||||
void bindFRAM(FRAM *fram);
|
void bindFRAM(FRAM *fram);
|
||||||
|
void publishSystemSummary();
|
||||||
|
|
||||||
IoTComponent* getComponent(uint8_t card_id);
|
IoTComponent* getComponent(uint8_t card_id);
|
||||||
IPAddress getETHIp();
|
IPAddress getETHIp();
|
||||||
|
|
Loading…
Reference in New Issue