0

Is there any reason that dtostrf() does not work wihtin logL
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.

Is there any reason that dtostrf() does not work wihtin logL

by pierrot10 on Sat Dec 12, 2015 5:03 pm

Good evening,

I am using FONA808 and Feather MO to log location to Adafruit IO:
I follow that tutotial https://learn.adafruit.com/geofencing-with-the-fona-808-and-adafruit-io/testing-the-gps

I configure my Arduino IDE 1.6.5 as is described into the Feather MO tutoria.

All works excepted the function
Code: Select all | TOGGLE FULL SIZE
void logLocation(float latitude, float longitude, float altitude, Adafruit_MQTT_Publish& publishFeed) {
  // Initialize a string buffer to hold the data that will be published.
  char sendBuffer[120];
  memset(sendBuffer, 0, sizeof(sendBuffer));
  int index = 0;

  // Start with '0,' to set the feed value.  The value isn't really used so 0 is used as a placeholder.
  sendBuffer[index++] = '0';
  sendBuffer[index++] = ',';

  // Now set latitude, longitude, altitude separated by commas.
  dtostrf(latitude, 2, 6, &sendBuffer[index]);
  //sprintf(&sendBuffer[index], "%.6f", latitude);
  index += strlen(&sendBuffer[index]);
  sendBuffer[index++] = ',';
  dtostrf(longitude, 3, 6, &sendBuffer[index]);
  //sprintf(&sendBuffer[index], "%6f", longitude);
  index += strlen(&sendBuffer[index]);
  sendBuffer[index++] = ',';
  dtostrf(altitude, 2, 6, &sendBuffer[index]);
  //sprintf(&sendBuffer[index], "%9.6f", altitude);

  // Finally publish the string to the feed.
  sprint(F("Publishing location: "),2);
  sprintln(sendBuffer,2);
  if (!publishFeed.publish(sendBuffer)) {
    sprintln(F("Publish failed!"),2);
    txFailures++;
  }
  else {
    sprintln(F("Publish succeeded!"),2);
    txFailures = 0;
  }
}


The above function use dtostrf() and wen I compile, the following error message is shown in Serial Terminal

mo808.ino: In function 'void logLocation(float, float, float, Adafruit_MQTT_Publish&)':
mo808:787: error: 'dtostrf' was not declared in this scope
'dtostrf' was not declared in this scope


Then, at the top of my sketch, I added stdlib.h
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_FONA.h>

// For Adafruit IO
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_FONA.h>

#include <stdlib.h> // because dtostrf()


But it did not solved my problem.

Is there a way to use dtostrf()?
I tried to use sprintf insetad, but sprintf does not store the value and it display this:
MQTT
Publishing location: 0,,,



Thnak for your advises

pierrot10
 
Posts: 290
Joined: Tue Nov 17, 2015 4:34 pm

Re: Is there any reason that dtostrf() does not work wihtin

by adafruit_support_rick on Sun Dec 13, 2015 5:30 pm

The SAMD run-time library doesn't support dtostrf. But as far as I know, sprintf should work. I don't know why you're having problems with it.
Although this line doesn't look right
Code: Select all | TOGGLE FULL SIZE
  //sprintf(&sendBuffer[index], "%.6f", latitude);

The "%.6f" is wrong. You need a minimum field width before the '.'

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Is there any reason that dtostrf() does not work wihtin

by pierrot10 on Sun Dec 13, 2015 5:39 pm

Dear Rick

Thank for your information.

Have a nice evening
Cheers

pierrot10
 
Posts: 290
Joined: Tue Nov 17, 2015 4:34 pm

Please be positive and constructive with your questions and comments.