terrorsl/sMQTTBroker

onPublish doesn't seem to work

V-A-S opened this issue · 0 comments

V-A-S commented

Hi @terrorsl!
Faced some problem in the "advancebroker" example. I added one line to each of the event handlers:

class MyBroker: public sMQTTBroker
{
  public:
    bool onConnect (sMQTTClient * client, const std :: string & username, const std :: string & password)
    {
      // check username and password, if ok return true
      Serial.println ("Somebody connected");
      return true;
    };
    void onRemove (sMQTTClient *)
    {
      Serial.println ("Somebody disconnected");
    };
    void onPublish (const std :: string & topic, const std :: string & payload)
    {
      // client publish a message to the topic
      // you can parse the message, save it to a database, or whatever, based on your goals
      Serial.println ("Somebody posted");
    }
};

I tried to write something to topics using mqtt-explorer, everything is fine, but the output contains 2 of 3 added lines:

05: 39: 40.848 -> RAM: 270876
05: 39: 41.048 -> Somebody connected
05: 39: 41.845 -> RAM: 268700
05: 40: 17.880 -> RAM: 267124
05: 40: 18.876 -> RAM: 268700
05: 40: 33.172 -> Somebody disconnected
05: 40: 33.903 -> RAM: 271060