Skip to content

Commit

Permalink
updated method signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Oct 29, 2022
1 parent e05c361 commit ceb5c75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions esp_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ static void esp_mqtt_dispatch_events() {
while (xQueueReceive(esp_mqtt_event_queue, &evt, 0) == pdTRUE) {
// call callback if existing
if (esp_mqtt_message_callback) {
esp_mqtt_message_callback(evt->topic.data, evt->message.payload, evt->message.payload_len);
esp_mqtt_message_callback(evt->topic.data, evt->message.payload, evt->message.payload_len, (int)evt->message.qos,
evt->message.retained);
}

// free event
Expand Down Expand Up @@ -621,7 +622,7 @@ bool esp_mqtt_unsubscribe(const char *topic) {
return true;
}

bool esp_mqtt_publish(const char *topic, uint8_t *payload, size_t len, int qos, bool retained) {
bool esp_mqtt_publish(const char *topic, const uint8_t *payload, size_t len, int qos, bool retained) {
// acquire mutex
ESP_MQTT_LOCK_MAIN();

Expand All @@ -636,7 +637,7 @@ bool esp_mqtt_publish(const char *topic, uint8_t *payload, size_t len, int qos,
lwmqtt_message_t message;
message.qos = (lwmqtt_qos_t)qos;
message.retained = retained;
message.payload = payload;
message.payload = (uint8_t*)payload;
message.payload_len = len;

// publish message
Expand Down
7 changes: 3 additions & 4 deletions esp_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ typedef void (*esp_mqtt_status_callback_t)(esp_mqtt_status_t);
/**
* The message callback.
*/
typedef void (*esp_mqtt_message_callback_t)(const char *topic, uint8_t *payload, size_t len);
typedef void (*esp_mqtt_message_callback_t)(const char *topic, const uint8_t *payload, size_t len, int qos,
bool retained);

/**
* Initialize the MQTT management system.
Expand All @@ -36,7 +37,6 @@ typedef void (*esp_mqtt_message_callback_t)(const char *topic, uint8_t *payload,
void esp_mqtt_init(esp_mqtt_status_callback_t scb, esp_mqtt_message_callback_t mcb, size_t buffer_size,
int command_timeout);

#if defined(CONFIG_ESP_MQTT_TLS_ENABLE)
/**
* Configure TLS connection.
*
Expand All @@ -51,7 +51,6 @@ void esp_mqtt_init(esp_mqtt_status_callback_t scb, esp_mqtt_message_callback_t m
* @return Whether TLS configuration was successful.
*/
bool esp_mqtt_tls(bool enable, bool verify, const uint8_t *ca_buf, size_t ca_len);
#endif

/**
* Configure Last Will and Testament.
Expand Down Expand Up @@ -121,7 +120,7 @@ bool esp_mqtt_unsubscribe(const char *topic);
* @param retained - The retained flag.
* @return Whether the operation was successful.
*/
bool esp_mqtt_publish(const char *topic, uint8_t *payload, size_t len, int qos, bool retained);
bool esp_mqtt_publish(const char *topic, const uint8_t *payload, size_t len, int qos, bool retained);

/**
* Stop the MQTT process.
Expand Down
6 changes: 3 additions & 3 deletions test/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void connect() {
use_tls = !use_tls;

// start mqtt
ESP_LOGI("test", "starting mqtt with tls=%d", use_tls);
ESP_LOGI("test", "starting mqtt (tls=%d)", use_tls);
esp_mqtt_tls(use_tls, true, server_root_cert_pem_start, server_root_cert_pem_end - server_root_cert_pem_start);
esp_mqtt_start(MQTT_HOST, use_tls ? MQTTS_PORT : MQTT_PORT, "esp-mqtt", MQTT_USER, MQTT_PASS);
}
Expand Down Expand Up @@ -93,8 +93,8 @@ static void status_callback(esp_mqtt_status_t status) {
}
}

static void message_callback(const char *topic, uint8_t *payload, size_t len) {
ESP_LOGI("test", "incoming: %s => %s (%d)", topic, payload, (int)len);
static void message_callback(const char *topic, const uint8_t *payload, size_t len, int qos, bool retained) {
ESP_LOGI("test", "incoming: %s => %s (len=%d qos=%d ret=%d)", topic, payload, (int)len, qos, retained);
}

void app_main() {
Expand Down

0 comments on commit ceb5c75

Please sign in to comment.