Azure ESP8266 IoT Client Library not working with ESP8266 Web Server

0

We are implementing an IoT telemetry solution using Azure IoT Hub. By using the project here we were able to implement a successful basic solution on an ESP8266. However we would like the ESP to work also as a Web server on the local WiFi network, mainly for initial configuration purposes.

If we add to the aforementioned project this line:

#include <ESP8266WebServer.h>    
ESP8266WebServer server(80);

the project compile but we keep getting "core dumps" on the ESP and the device stops working.

Fatal exception 29(StoreProhibitedCause): epc1=0x4000e1b2, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000004, depc=0x00000000

Exception (29): epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: cont sp: 3fff4700 Soft WDT reset

ctx: cont sp: 3fff4460 end: 3fff4ce0 offset: 01b0

stack>>> 3fff4610: 40001da0 00000078 00000000 00000010 3fff4620: 40001f46 0000000d 66089700 263a390c 3fff4630: 66666633 30303734 88fd4100 5da4cdaf 3fff4640: 2395829e 2c6ea747 4f2f4c52 72696e6d
3fff4650: 00000000 2e353230 306c7263 5503061d 3fff4660: 00000000 3fff4740 3fff4740 3fffa878 3fff4670: 00000000 3fff46e0 3fff46e0 3ffec9ba 3fff4680: 40002514 3fffdd3c 3fff4ce0 3fff4700 3fff4690: 00000000 00000008 00000008 00000001 3fff46a0: 00000000 3fff4700 00000000 3fff4638

¿ Does anyone experienced this problem and found a way to fix it ?

azure
iot
azure-iot-hub
arduino-esp8266
asked on Stack Overflow Feb 7, 2017 by faturita • edited Feb 9, 2017 by faturita

2 Answers

2

I had almost an identical setup (using ESP8266 to host a WiFiServer and also periodically sending messages over the Azure IoT Hub), and what solved the problem for me was very careful memory management. Your stack trace even matches mine (epc1 and excvaddr are identical).

I minimized calls to malloc/free to try to keep my heap from fragmenting, and that solved it for my purposes. I think this is just a heavily load for the chip memory to handle.

answered on Stack Overflow Jul 21, 2017 by jameslouie
1

I think this and this issues are worth looking at. Both authors are using ESP8266WebServer with WiFiClientSecure and are experiencing the same problem. @Jeroen88 pointed out a possible solution here.

Let me quote:

Memory is leaking (some 24 bytes, depending on hostName size) every time I use ESP8266HTTPClient to GET data from a secure site.

Drilled down the problem to SSLContext::connect(ClientContext* ctx, const char* hostName, uint32_t timeout_ms). In this function memory is allocated using the function ssl_ext_set_host_name(ext, hostName); this memory is, however in my opinion, never freed.

Added just before the end of the connect function: ssl_ext_set_host_name(ext, nullptr); Now no more memory is leaking.

Complete function:

void connect(ClientContext* ctx, const char* hostName, uint32_t timeout_ms)
{
    SSL_EXTENSIONS* ext = ssl_ext_new();
    ssl_ext_set_host_name(ext, hostName);
    ssl_ext_set_max_fragment_size(ext, 4096);
    if (_ssl) {
        /* Creating a new TLS session on top of a new TCP connection.
           ssl_free will want to send a close notify alert, but the old TCP connection
           is already gone at this point, so reset s_io_ctx. */
        s_io_ctx = nullptr;
        ssl_free(_ssl);
        _available = 0;
        _read_ptr = nullptr;
    }
    s_io_ctx = ctx;
    _ssl = ssl_client_new(_ssl_ctx, 0, nullptr, 0, ext);
    uint32_t t = millis();

    while (millis() - t < timeout_ms && ssl_handshake_status(_ssl) != SSL_OK) {
        uint8_t* data;
        int rc = ssl_read(_ssl, &data);
        if (rc < SSL_OK) {
            break;
        }
    }
    ssl_ext_set_host_name(ext, nullptr); // THIS FUNCTION FREEs the host_name
}
answered on Stack Overflow Jul 25, 2017 by Defozo

User contributions licensed under CC BY-SA 3.0