Skip to content

How I can call funtions callback into a Class  #4

Open

Description

@GiovaniSchreiber

I am trying to call the function "callback" into a Class, but it not work.

PubSubClientTools *clientMQTT;

......
clientMQTT->subscribe(TOPICO_SUBSCRIBE_CM_LAMP, MQTTClass::subscriber);//the problem is here
//clientMQTT->subscribe(TOPICO_SUBSCRIBE_CM_LAMP, std::bind(&MQTTClass::subscriber, this);//not work too
..........
void MQTTClass::subscriber(String topic, String message) {
MQTT_Call_buttonPress(bool(message), MQTT_S);
}
Does anyone know how I do it?

Activity

  1. dersimn commented on Feb 26, 2020

    @dersimn
    Owner

    This library already does it in the .h file, just implement something similar in your own code:

    std::function<void(PUBSUBCLIENT_CALLBACK_PARAMETERS)> mqtt_callback = std::bind(&PubSubClientTools::callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);

    Afaik the std::* things are only available on ESP8266, not AVR platform.

  2. GiovaniSchreiber commented on Feb 28, 2020

    @GiovaniSchreiber
    Author

    thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions