Add Adafruit_MQTT_Subscribe::datalen

This stores the number of valid bytes in lastread. Having access to this
information allows transmitting binary data as well, containing embedded
nul bytes.
This commit is contained in:
Matthijs Kooijman 2015-07-02 18:07:33 +02:00
parent 22c3533745
commit 22b77ecb68
2 changed files with 4 additions and 0 deletions

View File

@ -234,6 +234,7 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
}
// extract out just the data, into the subscription object itself
memcpy(subscriptions[i]->lastread, buffer+4+topiclen, datalen);
subscriptions[i]->datalen = datalen;
DEBUG_PRINT(F("Data len: ")); DEBUG_PRINTLN(datalen);
DEBUG_PRINT(F("Data: ")); DEBUG_PRINTLN((char *)subscriptions[i]->lastread);

View File

@ -203,6 +203,9 @@ class Adafruit_MQTT_Subscribe {
uint8_t qos;
uint8_t lastread[SUBSCRIPTIONDATALEN];
// Number valid bytes in lastread. Limited to SUBSCRIPTIONDATALEN-1 to
// ensure nul terminating lastread.
uint8_t datalen;
private:
Adafruit_MQTT *mqtt;
};