odelot / aws-mqtt-websockets

Implementation of a middleware to use AWS MQTT service through websockets, aiming the ESP8266 plataform
GNU Lesser General Public License v3.0
231 stars 67 forks source link

Connection failed because of inproper initialization #16

Closed healthineer closed 6 years ago

healthineer commented 7 years ago

There seems to be an initialization issue with the WSclient_t struct of the base class (WebSocketsClient) I found using AWSWebSocketClient as global member (also static) worked with my sketch but When allocating the AWSWebSocketClient on the heap it crahes.

The problem is that the WSclient_t struct of the base class is only initialized from the begin() function. But when calling the AWSWebSocketClient::connect for the first time it calls stop() and leads to WebSocketsClient::disconnect() / WebSocketsClient::clientIsConnected. And here it crashes because the access of client->tcp which was is not initialized yet.

As a solution you could offer a initialization (e.g. begin) routine or do some initialization in the constructor. Putting begin("",0); at the end of the AWSWebSocketClient::AWSWebSocketClient` solved for me the problem