发送MQTT消息死机重启问题

学学ESP32
Posts: 6
Joined: Wed Jan 05, 2022 9:40 am

发送MQTT消息死机重启问题

Postby 学学ESP32 » Sun Mar 13, 2022 4:14 pm

想实现一个按键发送MQTT消息功能,MQTT收发测试已经没有问题,按键按下后中断函数也可以正常打印,但是无法再按键按下后任务函数中发送MQTT消息,一直报错

IO中断部分代码
/**
* GPIO中断部分
*/
static xQueueHandle gpio_evt_queue = NULL;
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}


/**
* 按键处理函数
*/
int last_time = 0;
static void key_task(void* arg)
{
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
// printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));

int now = xTaskGetTickCountFromISR();
if(gpio_get_level(io_num) == 1){ //高电平 判断短按还是长按
//获取系统当前运行的时钟节拍数,此函数用于在中断服务程序里面调用, 如果在任务里面调用的话,需要使用函数 xTaskGetTickCount,这两个函数切不可混用
if (now - last_time > MIN_DELAY) { //长按
printf("long %d %d\n", now, last_time);
gpio_set_level(3, 0);
//长按业务逻辑
}else if (now - last_time < 5){ //消抖 无操作

}else{ //短按
printf("short %d %d\n", now, last_time);
gpio_set_level(3, 1);
//短按业务逻辑 上报
// char topic_init[64];
// sprintf(topic_init, "/c/%s/send", mqtt_user);
if(client){
esp_mqtt_client_publish(client, '/test', "find", 0, 1, 0); //这行有问题,执行后重启
printf("send ok\n");
}else{
printf("no client");
}
// ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
}
}else{ //低电平 按下按键

}
last_time = now;
}
}
}


错误信息
assert failed: xQueueTakeMutexRecursive queue.c:673 (pxMutex)
Stack dump detected
Core 0 register dump:
MEPC : 0x4038061e RA : 0x403879ec SP : 0x3fcbe1d0 GP : 0x3fc904f8
0x4038061e: panic_abort at C:/Users/micro/Desktop/esp-idf/components/esp_system/panic.c:404

0x403879ec: rtos_int_enter at C:/Users/micro/Desktop/esp-idf/components/freertos/port/riscv/portasm.S:35

TP : 0x3fc7f014 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
S0/FP : 0x0000008a S1 : 0x00000001 A0 : 0x3fcbe20c A1 : 0x3fc91ed1
A2 : 0x00000001 A3 : 0x00000029 A4 : 0x00000001 A5 : 0x3fc9c000
A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x00000009 S3 : 0x3fcbe31d
S4 : 0x3fc91ed0 S5 : 0x74657374 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000007 MTVAL : 0x00000000
0x40380001: _vector_table at ??:?

MHARTID : 0x00000000

Failed to run gdb_panic_server.py script: Command '['riscv32-esp-elf-gdb', '--batch', '-n', 'c:\\code\\esp\\template-app\\build\\template-app.elf', '-ex', 'target remote | "C:\\Users\\micro\\.espressif\\python_env\\idf4.3_py3.8_env\\Scripts\\python.exe" "C:/Users/micro/Desktop/esp-idf/tools\\..\\tools\\gdb_panic_server.py" --target esp32c3 "C:\\Users\\micro\\AppData\\Local\\Temp\\tmp8kn1j2ve"', '-ex', 'bt']' returned non-zero exit status 1.
b'C:\\Users\\micro\\.espressif\\tools\\riscv32-esp-elf\\esp-2021r2-8.4.0\\riscv32-esp-elf\\bin\\riscv32-esp-elf-gdb.exe: warning: Couldn\'t determine a path for the index cache directory.\r\nerror starting child process \'"C:\\Users\\micro\\.espressif\\python_env\\idf4.3_py3.8_env\\Scripts\\python.exe" "C:/Users/micro/Desktop/esp-idf/tools\\..\\tools\\gdb_panic_server.py" --target esp32c3 "C:\\Users\\micro\\AppData\\Local\\Temp\\tmp8kn1j2ve"\': CreateProcess: No such file or directory\r\nNo stack.\r\n'


Core 0 register dump:
MEPC : 0x4038061e RA : 0x403879ec SP : 0x3fcbe1d0 GP : 0x3fc904f8
TP : 0x3fc7f014 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
S0/FP : 0x0000008a S1 : 0x00000001 A0 : 0x3fcbe20c A1 : 0x3fc91ed1
A2 : 0x00000001 A3 : 0x00000029 A4 : 0x00000001 A5 : 0x3fc9c000
A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x00000009 S3 : 0x3fcbe31d
S4 : 0x3fc91ed0 S5 : 0x74657374 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000007 MTVAL : 0x00000000
MHARTID : 0x00000000

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: 发送MQTT消息死机重启问题

Postby ESP_YJM » Tue Mar 15, 2022 8:21 am

试一下使用 esp_mqtt_client_enqueue 代替 esp_mqtt_client_publish

学学ESP32
Posts: 6
Joined: Wed Jan 05, 2022 9:40 am

Re: 发送MQTT消息死机重启问题

Postby 学学ESP32 » Wed Mar 16, 2022 12:11 pm

测试了下也还是重启,想问下这个函数可以在任务中调用吗

学学ESP32
Posts: 6
Joined: Wed Jan 05, 2022 9:40 am

Re: 发送MQTT消息死机重启问题

Postby 学学ESP32 » Wed Mar 16, 2022 12:16 pm

ESP_YJM wrote:
Tue Mar 15, 2022 8:21 am
试一下使用 esp_mqtt_client_enqueue 代替 esp_mqtt_client_publish
测试了下还是重启
msg_id = esp_mqtt_client_enqueue(client, topic_send, "start", 0, 1, 0, false);
报错:
assert failed: xQueueTakeMutexRecursive queue.c:673 (pxMutex)
有时候也有
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
或者
assert failed: xQueueSemaphoreTake queue.c:1451 (pxQueue->uxItemSize == 0)

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: 发送MQTT消息死机重启问题

Postby ESP_YJM » Mon Mar 21, 2022 2:31 am

你能否试一下创建一个 task 来调用 mqtt publish。

Who is online

Users browsing this forum: Baidu [Spider] and 22 guests