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.
Locked
User avatar
pierrot10
 
Posts: 349
Joined: Tue Nov 17, 2015 4:34 pm

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

Post by pierrot10 »

Good evening,

I am using FONA808 and Feather MO to log location to Adafruit IO:
I follow that tutotial https://learn.adafruit.com/geofencing-w ... ng-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

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

#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

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

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

Post by adafruit_support_rick »

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

  //sprintf(&sendBuffer[index], "%.6f", latitude);
The "%.6f" is wrong. You need a minimum field width before the '.'

User avatar
pierrot10
 
Posts: 349
Joined: Tue Nov 17, 2015 4:34 pm

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

Post by pierrot10 »

Dear Rick

Thank for your information.

Have a nice evening
Cheers

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”