Skip to main content

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)

likeLike:

setupSetup: mqtt.subscribe(&motor);mqtt.subscribe(&motor);

Loop: MQTT_connect();MQTT_connect();

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

  1. 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.

  1. 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

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(&motor);

Loop: MQTT_connect();

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

  1. 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.

  1. Convert value.lastread from char to int :*

int val = atoi((char *)sensor.lastread);

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

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(&motor);

Loop: MQTT_connect();

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

  1. 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.

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

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

Source Link
Ajay
  • 21
  • 2

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(&motor);

Loop: MQTT_connect();

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

  1. 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.

  1. Convert value.lastread from char to int :*

int val = atoi((char *)sensor.lastread);

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