Where is dtostrf defined?

I’m trying to use the official ThingSpeak library on a Core. This library includes, for the Core, a call to dtostrf. I get an error when trying to compile since dtostrf is not defined in the current scope. But I have no idea which h-file to include to get the definitions for dtostrf. Can anybody help?

@Dr_Strangelove,

It is a AVR lib function http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga060c998e77fb5fc0d3168b3ce8771d42.html
So it is probably un reachable because it is not exposed by the HAL (Hardware Abstraction Layer).

I used this function for other projects to convert a double to ascii

char *ftoa(char *a, double f, int precision)
{
  long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};
 
  char *ret = a;
  long number = (long)f;
  itoa(number, a, 10);
  while (*a != '\0') a++;
  *a++ = '.';
  long decimal = abs((long)((f - number) * p[precision]));
  itoa(decimal, a, 10);
  return ret;
}

maybe you can use it.

It wouldn’t since it’s not really hardware specific :wink:

But what’s about sprintf(), or do you need arbitrary radixes?

No, I guess I don’t. I just wanted to use the ThingSpeak library as is. But what confuses me is that in the ThingSpeak library it is claimed that the Core “has” dtostrf, whereas the Photon has dtoa, and therefore there’s compile-time switch between them. Also, in the github repository for the Core’s firmware, the function dtostrf is included in spark_wiring_string.cpp. Can’t see it in spark_wiring_string.h, though. So I’m curious, is dtostrf implemented in the firmware for the Core or not?

Which of the two (!) ThingSpeak libraries on Particle Build are you using?
The official one, provided by ThingSpeak developers
https://github.com/mathworks/thingspeak-particle
or the private port of the Arduino version
https://github.com/dareid/sparkcore.thingspeak

The thing with dtostrf()/dtoa() seems to be that these were/are only intended for internal use in spark_wiring_string.cpp and are not meant for external use.

BTW, dtostrf() internally uses sprintf() anyhow.

1 Like

As I wrote in the original post, I am trying to get the official library running.

Thanks for the explanation. Interesting that ThingSpeak uses this internal version of dtostrf().

I managed to get one version to compile successfully by extracting the definition of dstostrf() from spark_wiring_string.cpp and putting it in separate .cpp and .h files.