ItKindaWorks / ESPHelper

A library to make using WiFi & MQTT on the ESP8266 easy.
GNU General Public License v3.0
327 stars 67 forks source link

MQTT Connection #11

Closed diasrobson closed 7 years ago

diasrobson commented 7 years ago

What command do I use to check if I'm connected to mqtt server as I'm trying to set up error indicates and i need a different one for wifi and MQTT

brndmg commented 7 years ago

If you take a look in the header file you can find the enumeration here: https://github.com/ItKindaWorks/ESPHelper/blob/master/src/ESPHelper.h#L64

enum connStatus {NO_CONNECTION, BROADCAST, WIFI_ONLY, FULL_CONNECTION};

When you make a call to getStatus or loop you can check the response using the values of the enumeration to verify your connection type.

...
if(myESP.loop() == FULL_CONNECTION){
...

https://github.com/ItKindaWorks/ESPHelper/blob/master/examples/buttonDemo/buttonDemo.ino#L82

You could use the WIFI_ONLY to check and see if you have a wifi connection but not a MQTT connection (as long as you expect there to be one).