minor changes

This commit is contained in:
proddy
2020-08-13 17:50:48 +02:00
parent e71e17bed1
commit 0d18e84141
4 changed files with 16 additions and 22 deletions

View File

@@ -78,6 +78,8 @@ void Mqtt::add_command(const uint8_t device_type, const uint8_t device_id, const
Mqtt::subscribe(device_type, cmd_topic, nullptr); // use an empty function handler to signal this is a command function Mqtt::subscribe(device_type, cmd_topic, nullptr); // use an empty function handler to signal this is a command function
} }
LOG_DEBUG(F("Registering MQTT cmd %s with topic %s"), uuid::read_flash_string(cmd).c_str(), EMSdevice::device_type_topic_name(device_type).c_str());
mqtt_cmdfunctions_.emplace_back(device_type, device_id, cmd, cb); mqtt_cmdfunctions_.emplace_back(device_type, device_id, cmd, cb);
} }
@@ -135,11 +137,16 @@ 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.printf(F(" topic: %s, [cmd]:"), mqtt_subfunction.full_topic_.c_str()); // don't show commands if its homeassistant
// show the commands associated with this subscription if ((strncmp(mqtt_subfunction.full_topic_.c_str(), "homeassistant/", 13) == 0)) {
for (const auto & mqtt_cmdfunction : mqtt_cmdfunctions_) { shell.printf(F(" topic: %s"), mqtt_subfunction.full_topic_.c_str());
if (EMSdevice::device_type_topic_name(mqtt_cmdfunction.device_type_) == mqtt_subfunction.topic_) { } else {
shell.printf(F(" %s"), uuid::read_flash_string(mqtt_cmdfunction.cmd_).c_str()); // show the commands associated with this subscription
shell.printf(F(" topic: %s, [cmd]:"), mqtt_subfunction.full_topic_.c_str());
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();
@@ -365,11 +372,6 @@ 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);
@@ -400,12 +402,9 @@ void Mqtt::on_connect() {
resubscribe(); // in case this is a reconnect, re-subscribe again to all MQTT topics resubscribe(); // in case this is a reconnect, re-subscribe again to all MQTT topics
// add the system MQTT subscriptions, only if its a fresh start with no previous subscriptions
// these commands respond to the topic "system_cmd" and take a payload like {cmd:"", data:"", id:""} // these commands respond to the topic "system_cmd" and take a payload like {cmd:"", data:"", id:""}
if (mqtt_subfunctions_.empty()) { add_command(EMSdevice::DeviceType::SERVICEKEY, bus_id_, F("pin"), System::mqtt_command_pin);
add_command(EMSdevice::DeviceType::SERVICEKEY, bus_id_, F("pin"), System::mqtt_command_pin); add_command(EMSdevice::DeviceType::SERVICEKEY, bus_id_, F("send"), System::mqtt_command_send);
add_command(EMSdevice::DeviceType::SERVICEKEY, bus_id_, F("send"), System::mqtt_command_send);
}
LOG_INFO(F("MQTT connected")); LOG_INFO(F("MQTT connected"));
} }

View File

@@ -171,8 +171,8 @@ class Mqtt {
// function handlers for MQTT subscriptions // function handlers for MQTT subscriptions
struct MQTTSubFunction { struct MQTTSubFunction {
uint8_t device_type_; // which device type, from DeviceType:: uint8_t device_type_; // which device type, from DeviceType::
const std::string topic_; const std::string topic_; // short topic name
const std::string full_topic_; // the fully qualified topic name, usually with the hostname prefixed const std::string full_topic_; // the fully qualified topic name, usually with the hostname prefixed
mqtt_subfunction_p mqtt_subfunction_; // can be empty mqtt_subfunction_p mqtt_subfunction_; // can be empty

View File

@@ -35,8 +35,6 @@
using uuid::console::Shell; using uuid::console::Shell;
#define MQTT_SYSTEM_CMD "system_cmd"
namespace emsesp { namespace emsesp {
class System { class System {

View File

@@ -537,9 +537,6 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
if (command == "mqtt") { if (command == "mqtt") {
shell.printfln(F("Testing MQTT...")); shell.printfln(F("Testing MQTT..."));
// simulate an on connect
Mqtt::on_connect();
// add a boiler // add a boiler
// question: do we need to set the mask? // question: do we need to set the mask?
std::string version("1.2.3"); std::string version("1.2.3");