1.1 KiB
1.1 KiB
tag | type | title |
---|---|---|
docs | other | Subscription Callback |
If the client is used to subscribe to topics, a callback function must be provided in the constructor. This function is called when new messages arrive at the client.
The callback function has the following signature:
void callback(const char[] topic, byte* payload, unsigned int length)
Parameters
- topic const char[] - the topic the message arrived on
- payload byte[] - the message payload
- length unsigned int - the length of the message payload
Internally, the client uses the same buffer for both inbound and outbound
messages. After the callback function returns, or if a call to either publish
or subscribe is made from within the callback function, the topic
and payload
values passed to the function will be overwritten. The application
should create its own copy of the values if they are required after the callback returns.