I am using my own firmware ESPMetRED (ESP8266, MQTT, Nodered Setup) which is based on Arduino IDE and I am using it since three years and it is working flawlessly on many of my ESP8266 devices including Nodemcu, Wemos D1 mini Itead Slampher.
Recently, I have installed it on Sonoff S20 and facing strange behaviour. When I connect the Sonoff S20 with my PC using serial adapter (S20 gets power from serial), it communicate with Nodered and works without any problem.
But When I plug Sonoff S20 on to AC Power 220V, It connects to WiFi as I can see it in my router connections but it does not connects to my MQTT broker (Mosquitto). Here is the log of MQTT broker;
1511547101: Socket error on client ESPMetRED, disconnecting.
1511548502: New connection from 192.168.50.228 on port 1883.
1511548502: New client connected from 192.168.50.228 as ESPMetRED (c1, k15, u'pi').
1511548533: Client ESPMetRED has exceeded timeout, disconnecting.
Message shown above repeats in Mosquitto log. When I remove it from AC Power and connect to my PC, everything starts working again as expected.
I have even tried erasing flash memory
esptool.py --port COM3 erase_flash
But no success. May someone help me to sort down the issue? Moreover, I am using PubSubClient MQTT library.