Skip to content

Example missing lines on how to retreive payload once subscribed #315

@lettcco

Description

@lettcco

Credit goes to Luis:
https://www.luisllamas.es/en/how-to-use-async-mqtt-on-esp8266-esp32-with-asyncmqttclient/

//if Subscribe, setup payload content catching
String GetPayloadContent(char* data, size_t len)
{
String content = "";
for(size_t i = 0; i < len; i++)
{
content.concat(data[i]);
}
return content;
}

void onMqttReceived(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
{
Serial.print("Received on ");
Serial.print(topic);
Serial.print(": ");

String content = GetPayloadContent(payload, len);
Serial.print(content);
Serial.println();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions