Good evening,
I am actually using a function. Here is the code
// Serialize the lat, long, altitude to a CSV string that can be published to the specified feed.
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]);
index += strlen(&sendBuffer[index]);
sendBuffer[index++] = ',';
dtostrf(longitude, 3, 6, &sendBuffer[index]);
index += strlen(&sendBuffer[index]);
sendBuffer[index++] = ',';
dtostrf(altitude, 2, 6, &sendBuffer[index]);
// 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;
}
}
Since I am not using SoftwareSerial, the function dtostrf()() bufs and teh Serial Terminal return me an error
error: 'dtostrf' was not declared in this scope
How can replace dtostrf()?
I think sprintf() can help, but I do not understanf exactely how works dtostrf(), particularely regarding the 2nd and 3rd parameter.
Someone can give me a exemple how a way to use dtostrf()?
Thanks a lot