minor formatting with command show mqtt

This commit is contained in:
proddy
2020-08-13 10:30:02 +02:00
parent 1c5d5d2dde
commit 2c3bf1cb3b

View File

@@ -64,15 +64,7 @@ void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_
// adds a command and callback function for a specific device // adds a command and callback function for a specific device
void Mqtt::add_command(const uint8_t device_type, const uint8_t device_id, const __FlashStringHelper * cmd, mqtt_cmdfunction_p cb) { void Mqtt::add_command(const uint8_t device_type, const uint8_t device_id, const __FlashStringHelper * cmd, mqtt_cmdfunction_p cb) {
// subscribe to the command topic if it doesn't exist yet // subscribe to the command topic if it doesn't exist yet
// create the cmd topic for a device like "<device_type>_cmd" e.g. "boiler_cmd" std::string cmd_topic = EMSdevice::device_type_topic_name(device_type); // cmd topic for a device like "<device_type>_cmd" e.g. "boiler_cmd"
// unless its a system MQTT command, then its system_cmd
std::string cmd_topic(40, '\0');
if (device_type == EMSdevice::DeviceType::SERVICEKEY) {
cmd_topic = MQTT_SYSTEM_CMD; // hard-coded system
} else {
snprintf_P(&cmd_topic[0], 41, PSTR("%s_cmd"), EMSdevice::device_type_topic_name(device_type).c_str());
}
bool exists = false; bool exists = false;
if (!mqtt_subfunctions_.empty()) { if (!mqtt_subfunctions_.empty()) {
@@ -143,20 +135,14 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) {
// show subscriptions // show subscriptions
shell.printfln(F("MQTT subscriptions:")); shell.printfln(F("MQTT subscriptions:"));
for (const auto & mqtt_subfunction : mqtt_subfunctions_) { for (const auto & mqtt_subfunction : mqtt_subfunctions_) {
shell.printfln(F(" %s"), mqtt_subfunction.full_topic_.c_str()); shell.printf(F(" topic: %s, [cmd]:"), mqtt_subfunction.full_topic_.c_str());
// show the commands associated with this subscription
for (const auto & mqtt_cmdfunction : mqtt_cmdfunctions_) {
if (EMSdevice::device_type_topic_name(mqtt_cmdfunction.device_type_) == mqtt_subfunction.topic_) {
shell.printf(F(" %s"), uuid::read_flash_string(mqtt_cmdfunction.cmd_).c_str());
}
} }
shell.println(); shell.println();
// show command handlers
shell.printfln(F("MQTT commands:"));
for (const auto & mqtt_cmdfunction : mqtt_cmdfunctions_) {
if (mqtt_cmdfunction.device_type_ == EMSdevice::DeviceType::SERVICEKEY) {
shell.printfln(F(" on topic: system, cmd: %s"), uuid::read_flash_string(mqtt_cmdfunction.cmd_).c_str()); // hardcoded topic is system
} else {
shell.printfln(F(" on topic: %s_cmd, cmd: %s"),
EMSdevice::device_type_topic_name(mqtt_cmdfunction.device_type_).c_str(),
uuid::read_flash_string(mqtt_cmdfunction.cmd_).c_str());
}
} }
shell.println(); shell.println();
@@ -197,7 +183,7 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) {
} }
} }
shell.println(); shell.println();
} } // namespace emsesp
// simulate receiving a MQTT message, used only for testing // simulate receiving a MQTT message, used only for testing
void Mqtt::incoming(char * topic, char * payload) { void Mqtt::incoming(char * topic, char * payload) {
@@ -379,6 +365,11 @@ void Mqtt::start() {
on_publish(packetId); on_publish(packetId);
}); });
#if defined(EMSESP_STANDALONE)
// simulate an MQTT connection
on_connect();
#endif
// create space for command buffer, to avoid heap memory fragmentation // create space for command buffer, to avoid heap memory fragmentation
mqtt_cmdfunctions_.reserve(40); // current count with boiler+thermostat is 37 mqtt_cmdfunctions_.reserve(40); // current count with boiler+thermostat is 37
mqtt_subfunctions_.reserve(10); mqtt_subfunctions_.reserve(10);