Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

烧录protocols/mqtt/tcp的demo后报错 (GIT8266O-858) #1281

Open
vangao-gg opened this issue Jun 7, 2024 · 0 comments
Open

烧录protocols/mqtt/tcp的demo后报错 (GIT8266O-858) #1281

vangao-gg opened this issue Jun 7, 2024 · 0 comments

Comments

@vangao-gg
Copy link

Environment

  • Development Kit:

  • IDF version
    image
    Commit: a96bc5c

  • Development Env:
    make
    image

  • Operating System:
    Windows

  • Power Supply:
    USB

  • hardware
    image
    image

Problem Description

烧录protocols/mqtt/tcp的demo后报错
image

Expected Behavior

成功连接,发布mqtt数据到指定地址,完成测试;

Actual Behavior

出现上图的连接报错

Steps to repropduce

  1. 安装工具链到windows;

image

  1. clone主线版本,如上图所示commit号;

  2. make menuconfig ,设置wifi的账户和密码,

  3. 设置example demo config:
    mqtts://mq.tongxinmao.com:18830
    image
    image

  4. make 编译后烧录
    image

  5. 连接串口 发现报错

image

Code to reproduce this issue

// the code should be wrapped in the ```cpp tag so that it will be displayed better.
#include "esp_log.h"

/* MQTT (over TCP) Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "protocol_examples_common.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"

#include "lwip/sockets.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"

#include "esp_log.h"
#include "mqtt_client.h"

static const char *TAG = "MQTT_EXAMPLE";


static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
{
    esp_mqtt_client_handle_t client = event->client;
    int msg_id;
    // your_context_t *context = event->context;
    switch (event->event_id) {
        case MQTT_EVENT_CONNECTED:
            ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
            msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "data_3", 0, 1, 0);
            ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);

            msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
            ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);

            msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
            ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);

            msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
            ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
            break;
        case MQTT_EVENT_DISCONNECTED:
            ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
            break;

        case MQTT_EVENT_SUBSCRIBED:
            ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
            msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
            ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
            break;
        case MQTT_EVENT_UNSUBSCRIBED:
            ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
            break;
        case MQTT_EVENT_PUBLISHED:
            ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
            break;
        case MQTT_EVENT_DATA:
            ESP_LOGI(TAG, "MQTT_EVENT_DATA");
            printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
            printf("DATA=%.*s\r\n", event->data_len, event->data);
            break;
        case MQTT_EVENT_ERROR:
            ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
            break;
        default:
            ESP_LOGI(TAG, "Other event id:%d", event->event_id);
            break;
    }
    return ESP_OK;
}

static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
    ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
    mqtt_event_handler_cb(event_data);
}

static void mqtt_app_start(void)
{
    esp_mqtt_client_config_t mqtt_cfg = {
        .uri = CONFIG_BROKER_URL,
    };
#if CONFIG_BROKER_URL_FROM_STDIN
    char line[128];

    if (strcmp(mqtt_cfg.uri, "FROM_STDIN") == 0) {
        int count = 0;
        printf("Please enter url of mqtt broker\n");
        while (count < 128) {
            int c = fgetc(stdin);
            if (c == '\n') {
                line[count] = '\0';
                break;
            } else if (c > 0 && c < 127) {
                line[count] = c;
                ++count;
            }
            vTaskDelay(10 / portTICK_PERIOD_MS);
        }
        mqtt_cfg.uri = line;
        printf("Broker url: %s\n", line);
    } else {
        ESP_LOGE(TAG, "Configuration mismatch: wrong broker url");
        abort();
    }
#endif /* CONFIG_BROKER_URL_FROM_STDIN */

    esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
    mqtt_cfg.host = "120.76.100.197";
    mqtt_cfg.uri = "mqtts://mq.tongxinmao.com";
    mqtt_cfg.port = 18830;
    esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
    esp_mqtt_client_start(client);
}

void app_main(void)
{
    ESP_LOGI(TAG, "[APP] Startup..");
    ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
    ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());

    esp_log_level_set("*", ESP_LOG_INFO);
    esp_log_level_set("MQTT_CLIENT", ESP_LOG_VERBOSE);
    esp_log_level_set("MQTT_EXAMPLE", ESP_LOG_VERBOSE);
    esp_log_level_set("TRANSPORT_TCP", ESP_LOG_VERBOSE);
    esp_log_level_set("TRANSPORT_SSL", ESP_LOG_VERBOSE);
    esp_log_level_set("TRANSPORT", ESP_LOG_VERBOSE);
    esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE);

    ESP_ERROR_CHECK(nvs_flash_init());
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
     * Read "Establishing Wi-Fi or Ethernet Connection" section in
     * examples/protocols/README.md for more information about this function.
     */
    ESP_ERROR_CHECK(example_connect());

    mqtt_app_start();
}

// If your code is longer than 30 lines, GIST is preferred.

Debug Logs

 ets Jan  8 2013,rst cause:2, boot mode:(3,0)

load 0x40100000, len 7544, room 16
tail 8
chksum 0x2d
load 0x3ffe8408, len 24, room 0
tail 8
chksum 0xa4
load 0x3ffe8420, len 3472, room 0
tail 0
chksum 0xd6
csum 0xd6
I (45) boot: ESP-IDF v3.4-98-ga96bc5cb-dirty 2nd stage bootloader
I (45) boot: compile time 18:52:46
I (46) qio_mode: Enabling default flash chip QIO
I (54) boot: SPI Speed      : 40MHz
I (60) boot: SPI Mode       : QIO
I (66) boot: SPI Flash Size : 4MB
I (73) boot: Partition Table:
I (78) boot: ## Label            Usage          Type ST Offset   Length
I (89) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (101) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (112) boot:  2 factory          factory app      00 00 00010000 000f0000
I (124) boot: End of partition table
I (131) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x74038 (475192) map
I (306) esp_image: segment 1: paddr=0x00084050 vaddr=0x40284048 size=0x15f48 ( 89928) map
I (337) esp_image: segment 2: paddr=0x00099fa0 vaddr=0x3ffe8000 size=0x0067c (  1660) load
I (338) esp_image: segment 3: paddr=0x0009a624 vaddr=0x40100000 size=0x00080 (   128) load
I (349) esp_image: segment 4: paddr=0x0009a6ac vaddr=0x40100080 size=0x055f4 ( 22004) load
I (369) boot: Loaded app from partition at offset 0x10000
I (389) MQTT_EXAMPLE: [APP] Startup..
I (390) MQTT_EXAMPLE: [APP] Free memory: 100264 bytes
I (392) MQTT_EXAMPLE: [APP] IDF version: v3.4-98-ga96bc5cb-dirty
I (400) system_api: Base MAC address is not set, read default base MAC address from EFUSE
I (413) system_api: Base MAC address is not set, read default base MAC address from EFUSE
phy_version: 1167.0, 14a6402, Feb 17 2022, 11:32:25, RTOS new
I (482) phy_init: phy ver: 1167_0
I (489) example_connect: Connecting to zerozero...
I (2602) wifi:state: 0 -> 2 (b0)
I (2605) wifi:state: 2 -> 3 (0)
I (2622) wifi:state: 3 -> 5 (10)
I (2648) wifi:connected with zerozero, aid = 2, channel 9, HT20, bssid = 4c:fa:ca:08:d8:c0
I (4095) tcpip_adapter: sta ip: 10.10.30.254, mask: 255.255.255.0, gw: 10.10.30.1
I (4098) example_connect: Connected to zerozero
I (4101) example_connect: IPv4 address: 10.10.30.254
I (4110) system_api: Base MAC address is not set, read default base MAC address from EFUSE
I (4126) MQTT_EXAMPLE: Other event id:7
E (4366) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x50 ggchange
E (4368) esp-tls: Failed to open new connection
E (4370) TRANS_SSL: Failed to open a new connection
E (4380) MQTT_CLIENT: Error transport connect
I (4386) MQTT_EXAMPLE: MQTT_EVENT_ERROR
I (4393) MQTT_EXAMPLE: MQTT_EVENT_DISCONNECTED
I (14396) MQTT_EXAMPLE: Other event id:7
E (14483) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x50 ggchange
E (14485) esp-tls: Failed to open new connection
E (14487) TRANS_SSL: Failed to open a new connection
E (14497) MQTT_CLIENT: Error transport connect
I (14504) MQTT_EXAMPLE: MQTT_EVENT_ERROR
I (14511) MQTT_EXAMPLE: MQTT_EVENT_DISCONNECTED
I (24517) MQTT_EXAMPLE: Other event id:7
E (24740) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x50 ggchange
E (24742) esp-tls: Failed to open new connection
E (24744) TRANS_SSL: Failed to open a new connection
E (24754) MQTT_CLIENT: Error transport connect
I (24761) MQTT_EXAMPLE: MQTT_EVENT_ERROR
I (24768) MQTT_EXAMPLE: MQTT_EVENT_DISCONNECTED
I (39768) MQTT_EXAMPLE: Other event id:7

@github-actions github-actions bot changed the title 烧录protocols/mqtt/tcp的demo后报错 烧录protocols/mqtt/tcp的demo后报错 (GIT8266O-858) Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant