I'm soon to release v2.0 of my "mqtt-firmware-in-a-box" Arduino library that lets you create e.g. your own MQTT-controlled Sonoff firmware in less than 20 lines of code. Basically it does pretty much everything for you and exposes a load of callbacks which are all run in a single serial queue, to avoid 90% of the common problems we see so often. And all with a nice real-time GPIO flashing LED view on a web page...