Skip to content

Commit

Permalink
refactor(MQTT): create a publish overload
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Mar 12, 2024
1 parent 46c308b commit 2a1b853
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace ESPAdmin
static void connect();
static void disconnect();
static void publish(const String &topic, const String &message, unsigned qos, bool retain);
static void publish(const String &topic, const char *message, int len, unsigned qos, bool retain);
static void subscribe(const String &topic, unsigned qos);
~MQTT();

Expand Down
9 changes: 9 additions & 0 deletions src/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ namespace ESPAdmin
}
}

void MQTT::publish(const String &topic, const char *message, int len, unsigned qos, bool retain)
{
if (Store::mqttConnected)
{
String fullTopic = "device/" + String(Store::deviceId) + topic;
esp_mqtt_client_publish(_client, fullTopic.c_str(), message, len, qos, retain);
}
}

void MQTT::subscribe(const String &topic, unsigned qos)
{
if (Store::mqttConnected)
Expand Down

0 comments on commit 2a1b853

Please sign in to comment.