espressif / esp-mdf

Espressif Mesh Development Framework, limited maintain, recommend to use https://github.com/espressif/esp-mesh-lite
Other
779 stars 253 forks source link

Getting error {esp-tls: mbedtls_ssl_handshake returned -0x10} when router gets off #125

Open haider00727 opened 4 years ago

haider00727 commented 4 years ago

Im using esp-mdf 3.3, was testing with a scenario that what is router turn off and after a time it power up again..

So while ESP running I turned off the wifi and ESP crashed. Here are the logs:

`heap_size: 18340, min_free_heap : 16228 D (50774) Brain: Dispatching Energy State as Mesh Frame I (50780) Brain: Encoded Message, bytes written: 70, encode_status: 1 I (50810) wifi: ap_probe_send over, resett wifi status to disassoc I (50810) wifi: state: run -> init (c800) I (50810) wifi: pm stop, total sleep time: lu us / lu us

I (50810) wifi: n:3 0, o:3 1, ap:3 1, sta:3 0, prof:3 D (50816) [mwifi, 131]: esp_mesh_event_cb event.id: 8 D (50822) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:dc, ssid_len:2, bssid:3e:cd:5d:7c:02:e8, reason:200 I (50822) [mwifi, 172]: Parent is disconnected, reason: 200 D (50834) tcpip_adapter: if0 start ip lost tmr: enter D (50840) tcpip_adapter: if0 start ip lost tmr: interval=120 E (50846) esp-tls: read error :-76: I (50852) [mqtt_tasks, 425]: event_loop_cb, event: 8 I (50852) mesh: [wifi]disconnected reason:200(beacon timeout), continuous:0/max:12, root, vote(,stopped)<><> I (50858) [mqtt_tasks, 438]: Parent is disconnected on station interface E (50852) TRANS_SSL: esp_tls_conn_read error, errno=Software caused connection abort E (50882) MQTT_CLIENT: Read error or end of stream D (50888) MQTT_CLIENT: Reconnect after 10000 ms I (50888) [mesh_mqtt, 175]: MQTT_EVENT_DISCONNECTED W (50894) MQTT_CLIENT: Client asked to stop, but was not started I (50906) [mqtt_tasks, 425]: event_loop_cb, event: 24578 I (50906) [mqtt_tasks, 566]: MQTT disconnected I (50912) mesh: toDS:0 D (50918) [mwifi, 131]: esp_mesh_event_cb event.id: 11 I (50924) [mwifi, 231]: State represents: 0 I (50930) [mqtt_tasks, 425]: event_loop_cb, event: 11 D (51074) Brain: Serial Transmission Queue Empty! D (51092) Brain: Transaction Queue Empty! assertion "res == coreID || res == portMUX_FREE_VAL" failed: file "../esp-mdf/esp-idf/components/freertos/portmux_impl.inc.h", line 105, function: vPortCPUAcquireMutexIntsDisabledInternal abort() was called at PC 0x400d2e57 on core 0 0x400d2e57: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

D (26472) esp_apptrace: Get 0 bytes from TRAX buffer D (26478) esp_apptrace: Try to flush 2 bytes. Wait until block switch for 4294967295 us

Backtrace: 0x4008b752:0x3fff3fc0 0x4008b9c1:0x3fff3fe0 0x400d2e57:0x3fff4000 0x40088d37:0x3fff4030 0x4008852b:0x3fff4050 0x400db9eb:0x3fff4090 0x400da018:0x3fff40d0 0x40087931:0x3fff4120 0x4008b752: invoke_abort at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/esp32/panic.c:707

0x4008b9c1: abort at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/esp32/panic.c:707

0x400d2e57: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

0x40088d37: vPortCPUAcquireMutexIntsDisabledInternal at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/freertos/tasks.c:4537 (inlined by) vPortCPUAcquireMutexIntsDisabled at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/freertos/portmux_impl.h:98 (inlined by) vTaskEnterCritical at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/freertos/tasks.c:4201

0x4008852b: xQueueGenericReceive at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/freertos/queue.c:2038

0x400db9eb: mesh_mqtt_read at /node/kibbutz-node/build/../components/mesh_mqtt/src/mesh_mqtt_handle.c:152

0x400da018: root_read_task at /node/kibbutz-node/build/../components/mesh_mqtt/src/sntp_task.c:77 (discriminator 9)

0x40087931: vPortTaskWrapper at /node/kibbutz-node/build/../esp-mdf/esp-idf/components/freertos/port.c:355 (discriminator 1) `

So I read an issue here and put a delay in static mdf_err_t event_loop_cb inside mesh_exp.c

`case MDF_EVENT_MWIFI_PARENT_DISCONNECTED: MDF_LOGI("Parent is disconnected on station interface");

        vTaskDelay(pdMS_TO_TICKS(3000)) //added for TLS issue

        if (esp_mesh_is_root()) {
            mesh_mqtt_stop();
        }
        break;

`

Now it is not crashing but throwing this error:

heap_size: 10912, min_free_heap : 540 D (379304) Brain: Dispatching Energy State as Mesh Frame I (379304) Brain: Encoded Message, bytes written: 70, encode_status: 1 E (379436) **esp-tls: mbedtls_ssl_handshake returned -0x10** I (379436) esp-tls: Certificate verified. E (379436) esp-tls: Failed to open new connection E (379442) TRANS_SSL: Failed to open a new connection E (379442) MQTT_CLIENT: Error transport connect D (379448) MQTT_CLIENT: Reconnect after 10000 ms I (379454) [mesh_mqtt, 175]: MQTT_EVENT_DISCONNECTED

Now when I power up the router this shows up.. Although I have alot of heap available. I also checkout mbedtls/port/net_socket.c to master (updated). Still having this issue.

EspHuifeng commented 4 years ago

It hard for us to find out the problem relying on the information that you put. If you can reproduce these issue in our example or tell us how to reproduce this issue, it could be better. When wifi connection is lost, the mqtt_client then detect it and print error information, so it is normal.