mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-10-19 20:35:15 +08:00
feat(mqtt): modify example and cmake file for building
This commit is contained in:
@@ -4,4 +4,4 @@ idf_component_register(SRCS "esp-mqtt/mqtt_client.c"
|
|||||||
"esp-mqtt/lib/platform_esp32_idf.c"
|
"esp-mqtt/lib/platform_esp32_idf.c"
|
||||||
INCLUDE_DIRS esp-mqtt/include
|
INCLUDE_DIRS esp-mqtt/include
|
||||||
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include"
|
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include"
|
||||||
REQUIRES lwip nghttp mbedtls tcp_transport)
|
REQUIRES lwip http_parser mbedtls tcp_transport)
|
||||||
|
@@ -32,20 +32,6 @@ extern const uint8_t mqtt_eclipse_org_pem_start[] asm("_binary_mqtt_eclipse_or
|
|||||||
#endif
|
#endif
|
||||||
extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end");
|
extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end");
|
||||||
|
|
||||||
//
|
|
||||||
// Note: this function is for testing purposes only publishing the entire active partition
|
|
||||||
// (to be checked against the original binary)
|
|
||||||
//
|
|
||||||
static void send_binary(esp_mqtt_client_handle_t client)
|
|
||||||
{
|
|
||||||
spi_flash_mmap_handle_t out_handle;
|
|
||||||
const void *binary_address;
|
|
||||||
const esp_partition_t* partition = esp_ota_get_running_partition();
|
|
||||||
esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle);
|
|
||||||
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, partition->size, 0, 0);
|
|
||||||
ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
||||||
{
|
{
|
||||||
esp_mqtt_client_handle_t client = event->client;
|
esp_mqtt_client_handle_t client = event->client;
|
||||||
@@ -82,10 +68,6 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
|
|||||||
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
|
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
|
||||||
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
|
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
|
||||||
printf("DATA=%.*s\r\n", event->data_len, event->data);
|
printf("DATA=%.*s\r\n", event->data_len, event->data);
|
||||||
if (strncmp(event->data, "send binary please", event->data_len) == 0) {
|
|
||||||
ESP_LOGI(TAG, "Sending the binary");
|
|
||||||
send_binary(client);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MQTT_EVENT_ERROR:
|
case MQTT_EVENT_ERROR:
|
||||||
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
|
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
|
||||||
|
@@ -6,6 +6,20 @@ This example connects to a local broker configured to PSK authentication
|
|||||||
|
|
||||||
## How to use example
|
## How to use example
|
||||||
|
|
||||||
|
### Code prepare
|
||||||
|
|
||||||
|
If want to use psk function, maybe need change IDF version beyond v4.1 in `esp_idf_version.h`. Like this :
|
||||||
|
```
|
||||||
|
/** Major version number (X.x.x) */
|
||||||
|
#define ESP_IDF_VERSION_MAJOR 4
|
||||||
|
/** Minor version number (x.X.x) */
|
||||||
|
#define ESP_IDF_VERSION_MINOR 2
|
||||||
|
/** Patch version number (x.x.X) */
|
||||||
|
#define ESP_IDF_VERSION_PATCH 0
|
||||||
|
```
|
||||||
|
|
||||||
|
This feature is controled by macro `MQTT_SUPPORTED_FEATURE_PSK_AUTHENTICATION`, defined in `mqtt_supported_features.h`.
|
||||||
|
|
||||||
### Hardware Required
|
### Hardware Required
|
||||||
|
|
||||||
This example can be executed on any ESP32 board, the only required interface is WiFi (or ethernet) to connect to a MQTT
|
This example can be executed on any ESP32 board, the only required interface is WiFi (or ethernet) to connect to a MQTT
|
||||||
|
Reference in New Issue
Block a user