Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

MQTT Library can't send floats without dtostrf.h
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

MQTT Library can't send floats without dtostrf.h

by jdamelio on Thu Jun 25, 2020 10:32 pm

I am getting some peculiar behavior from the Adafruit MQTT library. Publishing floats, using the "publish" function, causes the error: "MQTT ERROR: error saving data on jdamelio/feeds/test-feed, data missing required value" to appear on the Adafruit IO webpage. Other data types work fine.

If I both add #include "avr/dtostrf.h" and use the dtostrf function in the body of my sketch, the publishes work.

What is going on here? It seems like without the include, the mqtt library doesn't have a dtostrf function to use, but I don't understand how it could compile if this were the case.

I'm using a Metro M4 Airlift Lite with Arduino.

jdamelio
 
Posts: 15
Joined: Mon Mar 30, 2020 10:18 pm

Re: MQTT Library can't send floats without dtostrf.h

by brubell on Fri Jun 26, 2020 9:58 am

dtostrf isn't included with the SAMD architecture, you may want to include it here: https://github.com/adafruit/Adafruit_MQ ... MQTT.h#L27 instead of the sketch itself.


Alternatively, the Adafruit IO Arduino library handles type conversions for sending to Adafruit IO, for you: https://github.com/adafruit/Adafruit_IO_Arduino

brubell
 
Posts: 946
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.