You could try registering for the connected event before you call connect. It might help - it's definitely what gets done in the examples on http://www.espruino.com/MQTT
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
You could try registering for the
connected
event before you call connect. It might help - it's definitely what gets done in the examples on http://www.espruino.com/MQTT