Arduino custom library and pubsubclient call back

Months back when I tried to make my own library consisting of all necessary code (“ESPMetRED” with it’s user friendly API) which included few other libraries such as PubSubClient MQTT Library, I experienced callback issue with PubSubClient MQTT library written by former IBM guy Nick O’Leary. I had raised an issue over github and few guys tried to help me but I failed to understand. After much effort I have resolved the issue and I think it’s worth to share my solution.

pubsubclient_callback

 

I am using Nick’s PubSubClient library which can be download from here. Let’s explain it bit more.

pubsubclient_library_function

In your library instantiate function, set MQTT callback as shown above and make a function in your library which should be called in your sketch loop at every cycle. In this specific function add following code.

pubsubclient_arduino_ide_sketch

Where MQTTClient the instantiation of PubSubClient library in our custom library. Now We’ll be able to interact with MQTT messages received in the same way as We do while using PubSubClient library in our Arduino IDE sketch. Good Luck Hobbyists  ;-).

Leave a Reply

avatar
  Subscribe  
Notify of