Page 1 of 1

MQTT和HTTP OTA同时使用

Posted: Thu Feb 09, 2023 8:46 am
by z45217
我是用的IDF版本是4.4.2
MQTT是拷贝"F:\ESP32-S3\idf\esp-idf\examples\protocols\mqtt\tcp"这个例程
OTA是拷贝"F:\ESP32-S3\idf\esp-idf\examples\system\ota"这个例程

Code: Select all

    char *mqtt_username = "RF1_23020901";
    memcpy(&mqtt_username[4], serial_number, 8); 

    esp_mqtt_client_config_t mqtt_cfg = {                  
        .port=1883,                                             
        .keepalive=60,                                          
        .buffer_size=1314,                                      
        .username = mqtt_username,                              
        .client_id= "RF1_23020901",                             
        .password = "10902032",                                 
        .reconnect_timeout_ms = 5000,                             
    };
本来一直正常使用能OTA,但是我现在想根据设备编号去设置MQTT帐号和密码,加了下面这条指令后就不能OTA了
memcpy(&mqtt_username[4], serial_number, 8);

测试发现只要注释掉这条指令就正常,不注释OTA更新一半就重启,下面是重启打印
I (79987) HTTP_CLIENT: Body received in fetch header state, 0x3fceaafd, 31
I (79987) esp_https_ota: Starting OTA...
I (79987) esp_https_ota: Writing to partition subtype 17 at offset 0x190000
I (110107) esp_image: segment 0: paddr=00190020 vaddr=3c100020 size=3a900h (239872) map
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)
Saved PC:0x42003a01
0x42003a01: panic_handler at F:/ESP32-S3/idf/esp-idf/components/esp_system/port/panic_handler.c:148 (discriminator 3)


并且重启后还会提示
I (37) boot.esp32s3: Boot SPI Speed : 80MHz
I (41) boot.esp32s3: SPI Mode : QIO
I (46) boot.esp32s3: SPI Flash Size : 8MB
W (51) boot.esp32s3: PRO CPU has been reset by WDT.
W (56) boot.esp32s3: APP CPU has been reset by WDT.
I (62) boot: Enabling RNG early entropy source...

请问下这是什么原因

Re: MQTT和HTTP OTA同时使用

Posted: Thu Feb 09, 2023 10:51 am
by ESP_YJM
你加的代码有问题,改为

char mqtt_username[] = "RF1_23020901";
memcpy(&mqtt_username[4], serial_number, 8);

Re: MQTT和HTTP OTA同时使用

Posted: Fri Feb 10, 2023 12:39 am
by z45217
谢谢你