Notoriously unstable ESP8266 MQTT-client
I use adafruit mqtt library. After a few fixes, it is running very stable.

Tips: 

1) Make sure you put subscribe line BEFORE connecting to mqtt (you can put it in setup and connect to mqtt in loop)

Like: 

Setup: mqtt.subscribe(&amp;motor);

Loop: MQTT_connect();

Yes, you can both publish and subscribe at the same time.

2) IN THE LINE: Adafruit_MQTT_Client(server,port,user,pass)

CHANGE TO THIS: Adafruit_MQTT(server,port,clientid,user,pass)

Use this with client id (MUST BE UNIQUE (EG: Different for all clients))
or your client will be kicked off when other client with same id connects.

3) Convert value.lastread from char* to int : int val = atoi((char *)sensor.lastread);

More about ESP8266 &amp; ESP32 : http://github.com/ajaybnl