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

Probelms with Adafruit_MQTT_Publish::publish #35

Closed
nelisse opened this issue Apr 13, 2016 · 1 comment
Closed

Probelms with Adafruit_MQTT_Publish::publish #35

nelisse opened this issue Apr 13, 2016 · 1 comment

Comments

@nelisse
Copy link

nelisse commented Apr 13, 2016

The Adafruit_MQTT_Publish::publish(int32_t) and Adafruit_MQTT_Publish::publish(uint32_t i) already rollover after 32768 (because they use the itoa function).
The Adafruit_MQTT_Publish::publish(double f.... could potentially have a buffer problem (because of unsuffiient room for a terminating zero).

I think this will fix it:

bool Adafruit_MQTT_Publish::publish(int32_t i) {
  char payload[12];  // Need to technically hold int32 max: 10 digits, minus sign and terminating zero.
  ltoa(i, payload, 10); // // Changed itoa to ltoa, int32_t => long
  return mqtt->publish(topic, payload, qos);
}

bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision) {
  char payload[41];  // Need to technically hold float max, 39 digits, minus sign and terminating zero.
  dtostrf(f, 0, precision, payload);
  return mqtt->publish(topic, payload, qos);
}

bool Adafruit_MQTT_Publish::publish(uint32_t i) {
  char payload[11];  // Need to technically hold uint32 max: 10 digits and terminating zero.
  ultoa(i, payload, 10); // Changed itoa to ultoa, uint32_t => unsigned long
  return mqtt->publish(topic, payload, qos);
}
ladyada added a commit that referenced this issue Jul 6, 2016
@ladyada
Copy link
Member

ladyada commented Jul 6, 2016

changed payload to [41]!

@ladyada ladyada closed this as completed Jul 6, 2016
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

2 participants