Problem with texting data from GPS

Hi all, I am trying to build a GPS tracker using an adafruit FONA (cell phone/gps module) but I can’t seem to convert the latitude and longitude from a floating integer to something I can text. I’m not great at coding and most of this is hacked together from example codes, but I keep getting the error

“invalid conversion from ‘char’ to ‘char*’ [-fpermissive]”

Messages apparently can only be one character?? A little confused

/***************************************************
This is an example for our Adafruit FONA Cellular Module (modified slightly by mrwillcreates)

Designed specifically to work with the Adafruit FONA
----> http://www.adafruit.com/products/1946
----> http://www.adafruit.com/products/1963
----> http://www.adafruit.com/products/2468
----> http://www.adafruit.com/products/2542

These cellular modules use TTL Serial to communicate, 2 pins are
required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

/*
THIS CODE IS STILL IN PROGRESS!

This code will receive an SMS and send location data back to the same number

For use with FONA 800 & 808, not 3G
*/

#include “Adafruit_FONA.h”

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

// this is a large buffer for replies
char replybuffer[255];

// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

void setup() {
while (!Serial);

// make it slow so its easy to read!
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
Serial.println(F(“Couldn’t find FONA”));
while(1);
}

// Print SIM card IMEI number.
char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
uint8_t imeiLen = fona.getIMEI(imei);
if (imeiLen > 0) {
}

}

char fonaInBuffer[64]; //for notifications from the FONA

void loop() {
float latitude, longitude, speed_kph, heading, speed_mph, altitude;

// if you ask for an altitude reading, getGPS will return false if there isn’t a 3D fix
boolean gps_success = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
char* bufPtr = fonaInBuffer; //handy buffer pointer

if (fona.available()) //any data available from the FONA?
{
int slot = 0; //this will be the slot number of the SMS
int charCount = 0;
//Read the notification into fonaInBuffer
do {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != ‘\n’) && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-1)));

//Add a terminal NULL to the notification string
*bufPtr = 0;

//Scan the notification string for an SMS received notification.
// If it’s an SMS message, we’ll get the slot number in ‘slot’
if (1 == sscanf(fonaInBuffer, “+CMTI: “SM”,%d”, &slot)) {

char callerIDbuffer[32]; //we’ll store the SMS sender number in here

// Retrieve SMS sender address/phone number.
if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
}

//Send back an automatic response
//Convert floating int to char
char longitude;
if (!fona.sendSMS(callerIDbuffer, longitude)) {
Serial.println(F(“Failed”));
} else {
Serial.println(F(“Sent!”));
}

// delete the original msg after it is processed
// otherwise, we will fill up all the slots
// and then we won’t be able to receive SMS anymore
if (fona.deleteSMS(slot)) {
Serial.println(F(“OK!”));
} else {
Serial.println(F(“Couldn’t delete”));
}
}
}
}

  //Read the notification into fonaInBuffer
  do  {
    *bufPtr = fona.read();
    Serial.write(*bufPtr);
    delay(1);
  } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-1)));

That’s a nice comment, but that is not what the code is doing.

    //Convert floating int to char
    char longitude;

longitude was declared globally as a float. Why is it defined here as a char? Why does the comment mention int? Where is the code to actually perform the conversion?

Does the fona.sendSMS() function really expect a single character as the message? I doubt it.

I was trying to take the data (a 12 digit number) and convert in into something spendable by sms. However, in the error log it says char was expected. I can't send it as a string, integer or floating integer either. It works fine in the serial monitor, so I guess it converts it automatically. Thanks for responding!

(I didn't write those comments, they were left over from Adafruit's example)

I can't find a code that works to convert a floating int to text.. In the example Adafruit used a set message in quotes, the problem is that mine changes as location changes.

However, in the error log it says char was expected.

I'm going to guess that it said either pointer to char or char array, NOT char. But, we can't see the actual, complete errors.

I guess its something with the libraries... it keeps referencing them.. Thanks anyway!

/Users/****/Desktop/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR "-I/Users/*/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino" "-I/Users/*/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs" "-I/Users/*/Documents/Arduino/libraries/Adafruit_FONA" "-I/Users/*/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial" "/var/folders/4z/lgkjk6cj26j6nv4xj_7187ph0000gn/T/build239e8ff38b6f598767bd805af53a24aa.tmp/sketch/Trackr2.ino.cpp" -o "/var/folders/4z/lgkjk6cj26j6nv4xj_7187ph0000gn/T/build239e8ff38b6f598767bd805af53a24aa.tmp/sketch/Trackr2.ino.cpp.o" /Users/***/Documents/Arduino/Trackr2/Trackr2.ino: In function 'void loop()': Trackr2:110: error: invalid conversion from 'char' to 'char' [-fpermissive] if (!fona.sendSMS(callerIDbuffer, longitude)) {

In file included from /Users/****/Documents/Arduino/Trackr2/Trackr2.ino:31:0: /Users/***/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.h:121:11: error: initializing argument 2 of 'boolean Adafruit_FONA::sendSMS(char, char*)' [-fpermissive] boolean sendSMS(char *smsaddr, char *smsmsg);

Using library Adafruit_FONA at version 1.3.2 in folder: /Users/****/Documents/Arduino/libraries/Adafruit_FONA Using library SoftwareSerial at version 1.0 in folder: /Users/****/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial exit status 1 invalid conversion from 'char' to 'char' [-fpermissive]

I was messing around with the code and put an asterisk after char and it worked... I didn't realize it before. Thanks!

I was messing around with the code and put an asterisk after char and it worked... I didn't realize it before. Thanks!

If you change

   char latitude;

to

   char *latitude;

you have created a pointer, but NOT made it point anywhere. Using a dangling pointer is NOT a good idea.

Oh.. I'm not really acquainted with Arduino. Do you have any suggestions to get it to be sendable? (it compiled so I assumed it worked)

it compiled so I assumed it worked

That the code that you didn’t post compiled means only that the compiler didn’t find any syntax errors and that all the arguments had the correct type to match the function call.

It does NOT mean that there are not logic errors.

Running the code, and actually getting a text message that contains valid data would be better proof, but still does not mean that there are not array bounds errors, dangling pointers, memory leaks, etc. that will eventually haunt you.

A compiler can't understand what you wrote. It can only check it against a book of rules. Since it's not possible to define what is foolish and what isn't, it can't alert you when you do something that is legal but stupid. If it was possible for computers to make that distinction, it would be possible to let them do all the coding, and every programmer would be out of a job.

I can't find a code that works to convert a floating int to text..

You should do some research on dtostrf() which is the function to convert a float to a character string.