Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lettcco opened this issue Nov 19, 2024 · 0 comments
Open

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

lettcco opened this issue Nov 19, 2024 · 0 comments

Comments

@lettcco
Copy link

lettcco commented Nov 19, 2024

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant