callback
Closed this issue · 1 comments
openstep commented
Could you show an example callback?
I have like this but not working.
Also could you please explain the difference between this (MQTTPubSubClient.h) and the PubSubClient.h ?
Thx
part of code in setup()
// subscribe callback which is called when every packet has come
mqtt.subscribe([](const String& topic, const String& payload, const size_t size) {
Serial.println("mqtt received: " + topic + " - " + payload);
});
void callback(char *topic, byte *payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
String message; //csaba
for (int i = 0; i < length; i++) {
message += (char) payload[i];
Serial.print((char) payload[i]);
}
}
hideakitai commented
A Callback for every packet should be this form:
void my_callback(const String& topic, const String& payload, const size_t size);
// or
void my_callback(const char* topic, const char* payload, const size_t size);