I use adafruit mqtt library. After a few fixes, it is running very stable.
Tips:
- Make sure you put subscribe line BEFORE connecting to mqtt (you can put it in setup and connect to mqtt in loop)
likeLike:
setupSetup: mqtt.subscribe(&motor);mqtt.subscribe(&motor);
Loop: MQTT_connect();MQTT_connect();
Yes, you can both publish and subscribe at the same time.
- IN THE LINE: Adafruit_MQTT_Client(server,port,user,pass)
Adafruit_MQTT_Client(server,port,user,pass)
CHANGE TO THIS:
Adafruit_MQTT(server,port,clientid,user,pass) 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.
- Convert value.lastread from char to int :*
int val = atoi((char *)sensor.lastread);
int val = atoi((char *)sensor.lastread);
More about ESP8266 & ESP32 : http://github.com/ajaybnl