diff --git a/README.md b/README.md index 7d05203..8f91923 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +[![](https://travis-ci.org/tuanpmt/espmqtt.png?branch=master)](https://travis-ci.org/tuanpmt/espmqtt) +[![](http://hits.dwyl.io/tuanpmt/espmqtt.svg)](http://hits.dwyl.io/tuanpmt/espmqtt) +![](https://img.shields.io/github/downloads/tuanpmt/espmqtt/total.svg) +[![Twitter Follow](https://img.shields.io/twitter/follow/tuanpmt.svg?style=social&label=Follow)](https://twitter.com/tuanpmt) + +![GitHub contributors](https://img.shields.io/github/contributors/tuanpmt/espmqtt.svg) +[![Paypal donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/tuanpm) + + # ESP32 MQTT Library ## Features @@ -15,6 +24,15 @@ Clone this component to [ESP-IDF](https://github.com/espressif/esp-idf) project git submodule add https://github.com/tuanpmt/espmqtt.git components/espmqtt ``` +Or run a sample (make sure you have `IDF_PATH` env): + +``` +git clonehttps://github.com/tuanpmt/espmqtt.git +cd espmqtt/examples/mqtt_tcp +make menuconfig +make flash monitor +``` + ## Documentation ### URI @@ -128,4 +146,5 @@ esp_mqtt_client_start(client); ## License +[@tuanpmt](https://twitter.com/tuanpmt) Apache License diff --git a/examples/mqtt_ws/main/app_main.c b/examples/mqtt_ws/main/app_main.c index 3e2a265..c9c65a5 100755 --- a/examples/mqtt_ws/main/app_main.c +++ b/examples/mqtt_ws/main/app_main.c @@ -115,7 +115,7 @@ static void wifi_init(void) static void mqtt_app_start(void) { const esp_mqtt_client_config_t mqtt_cfg = { - .uri = "ws://iot.eclipse.org:80/mqtt", + .uri = "ws://iot.eclipse.org:80/ws", .event_handle = mqtt_event_handler, // .user_context = (void *)your_context }; diff --git a/include/mqtt_client.h b/include/mqtt_client.h index 67f9e69..32cee2d 100755 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -1,3 +1,9 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ + #ifndef _MQTT_CLIENT_H_ #define _MQTT_CLIENT_H_ @@ -7,10 +13,8 @@ #include "mqtt_config.h" - typedef struct esp_mqtt_client* esp_mqtt_client_handle_t; - typedef enum { MQTT_EVENT_ERROR = 0, MQTT_EVENT_CONNECTED, diff --git a/include/mqtt_config.h b/include/mqtt_config.h index 7ce6bda..7daec77 100644 --- a/include/mqtt_config.h +++ b/include/mqtt_config.h @@ -1,3 +1,8 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _MQTT_CONFIG_H_ #define _MQTT_CONFIG_H_ #define MQTT_PROTOCOL_311 1 diff --git a/lib/include/mqtt_outbox.h b/lib/include/mqtt_outbox.h index 7933b7b..b94bd80 100644 --- a/lib/include/mqtt_outbox.h +++ b/lib/include/mqtt_outbox.h @@ -1,3 +1,8 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _MQTT_OUTOBX_H_ #define _MQTT_OUTOBX_H_ #include "platform.h" diff --git a/lib/include/platform.h b/lib/include/platform.h index e311503..b3358b9 100644 --- a/lib/include/platform.h +++ b/lib/include/platform.h @@ -1,3 +1,8 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _PLATFORM_H__ #define _PLATFORM_H__ diff --git a/lib/include/platform_esp32_idf.h b/lib/include/platform_esp32_idf.h index 069d240..f8585f3 100644 --- a/lib/include/platform_esp32_idf.h +++ b/lib/include/platform_esp32_idf.h @@ -1,4 +1,8 @@ - +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _ESP_PLATFORM_H__ #define _ESP_PLATFORM_H__ diff --git a/lib/include/transport.h b/lib/include/transport.h index c1b5395..7ef50d3 100644 --- a/lib/include/transport.h +++ b/lib/include/transport.h @@ -1,3 +1,8 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _TRANSPORT_H_ #define _TRANSPORT_H_ diff --git a/lib/include/transport_ssl.h b/lib/include/transport_ssl.h index 2f6fd9f..d73d4d3 100644 --- a/lib/include/transport_ssl.h +++ b/lib/include/transport_ssl.h @@ -1,4 +1,8 @@ - +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _TRANSPORT_SSL_H_ #define _TRANSPORT_SSL_H_ diff --git a/lib/include/transport_tcp.h b/lib/include/transport_tcp.h index dc8a86f..4a94e49 100644 --- a/lib/include/transport_tcp.h +++ b/lib/include/transport_tcp.h @@ -1,3 +1,8 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ #ifndef _TRANSPORT_TCP_H_ #define _TRANSPORT_TCP_H_ diff --git a/lib/include/transport_ws.h b/lib/include/transport_ws.h index 24cf518..7393088 100644 --- a/lib/include/transport_ws.h +++ b/lib/include/transport_ws.h @@ -1,3 +1,9 @@ +/* + * This file is subject to the terms and conditions defined in + * file 'LICENSE', which is part of this source code package. + * Tuan PM + */ + #ifndef _TRANSPORT_WS_H_ #define _TRANSPORT_WS_H_ diff --git a/lib/transport_ws.c b/lib/transport_ws.c index 9f10e52..9bb4e5c 100644 --- a/lib/transport_ws.c +++ b/lib/transport_ws.c @@ -191,7 +191,7 @@ static int ws_read(transport_handle_t t, char *buffer, int len, int timeout_ms) buffer[i] = (data_ptr[i] ^ mask_key[i % 4]); } } else { - memcpy(buffer, data_ptr, payload_len); + memmove(buffer, data_ptr, payload_len); } return payload_len; } diff --git a/mqtt_client.c b/mqtt_client.c index 9c0e970..85e0da0 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -437,11 +437,16 @@ static void deliver_publish(esp_mqtt_client_handle_t client, uint8_t *message, i mqtt_data_length = length; mqtt_data = mqtt_get_publish_data(message, &mqtt_data_length); - if (total_mqtt_len == 0) { + if(total_mqtt_len == 0){ + mqtt_topic_length = length; + mqtt_topic = mqtt_get_publish_topic(message, &mqtt_topic_length); + mqtt_data_length = length; + mqtt_data = mqtt_get_publish_data(message, &mqtt_data_length); total_mqtt_len = client->mqtt_state.message_length - client->mqtt_state.message_length_read + mqtt_data_length; mqtt_len = mqtt_data_length; } else { mqtt_len = len_read; + mqtt_data = (const char*)client->mqtt_state.in_buffer; } ESP_LOGD(TAG, "Get data len= %d, topic len=%d", mqtt_data_length, mqtt_topic_length);