sprintf error not able to recitfy !!

Ive written down the program in order to send the gps location to a http using the functions of a gsm shield and gps module but there exist a error in the code please help me out!!
Thanks in advance.

The function below describes a set of values from adruino shield and uno board using gps module.

I receive some errors perhaps it is in the syntax. Please ignore the line in which the error has been pointed out. I don’t want people to get scared seeing a large coding.
the whole programming is attached below as attachment.
And I get the following errors.

Arduino: 1.7.5 (Windows 8.1), Board: “Arduino Uno”

sketch_aug22e.ino:459:13: error: missing terminating " character

sketch_aug22e.ino: In function ‘void send_HTTP()’:

sketch_aug22e.ino:460:34: error: expected ‘)’ before ‘;’ token

Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.
the whole programming is attached below.

   void send_HTTP(){
   
   uint8_t answer=0;
   // Initializes HTTP service
   answer = sendATcommand("AT+HTTPINIT", "OK", 10000);
   if (answer == 1)
   {
       // Sets CID parameter
       answer = sendATcommand("AT+HTTPPARA=\"CID\",1", "OK", 5000);
       if (answer == 1)
       {
           // Sets url 
           sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http://%s/demo_sim908.php?", url);// line number :459
           Serial.print(aux_str);
           sprintf(frame, "visor=false&latitude=%s&longitude=%s&altitude=%s&time=%s&satellites=%s&speedOTG=%s&course=%s",       
           latitude, longitude, altitude, date, satellites, speedOTG, course);   // line number : 460
           Serial.print(frame);
           answer = sendATcommand("\"", "OK", 5000);
           if (answer == 1)
           {
               // Starts GET action
               answer = sendATcommand("AT+HTTPACTION=0", "+HTTPACTION:0,200", 30000);
               if (answer == 1)
               {

                   Serial.println(F("Done!"));
               }
               else
               {
                   Serial.println(F("Error getting url"));
               }

           }
           else
           {
               Serial.println(F("Error setting the url"));
           }
       }
       else
       {
           Serial.println(F("Error setting the CID"));
       }    
   }
   else
   {
       Serial.println(F("Error initializating"));
   }

   sendATcommand("AT+HTTPTERM", "OK", 5000);
   
}


[code]

[/code]

http included.txt (13.3 KB)

Ok...over 500 lines of code and the most help you give us is: :...there exist a error in the code...". Also, please read Nick Gammon's two posts at the top of this Forum on guidelines for posting here, especially the use of code tags when posting source code.

BTW, there are a lot of people here who could probably be charging $100/hr for their time and before they are will to give that to you, they want to see some effort on your part to solve the problem before they get involved. I don't see any of that in this post.

Is it better now sir?

Yes, that is better, but if you want us to be able to duplicate your errors, we need the entire source code file. That makes it much easier for us to dig around in the code.

econjack:
Yes, that is better, but if you want us to be able to duplicate your errors, we need the entire source code file. That makes it much easier for us to dig around in the code.

yes sir I have attached the file as an attachement

I get the "missing terminating " character" in Line 436 character 30 (the " in "AT+) but that line and the ones around it look OK to me:

        // Sets CID parameter
        answer = sendATcommand("AT+HTTPPARA=\"CID\",1", "OK", 5000);
        if (answer == 1)
        {
            // Sets url 
(436)    sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http://%s/demo_sim908.php?", url);
            Serial.print(aux_str);
            sprintf(frame, "visor=false&latitude=%s&longitude=%s&altitude=%s&time=%s&satellites=%s&speedOTG=%s&course=%s",
            latitude, longitude, altitude, date, satellites, speedOTG, course);
            Serial.print(frame);

You have five " in this line... Probably not what you need. :slight_smile:

sprintf(aux_str, "AT+HTTPPARA="URL","http://%s/demo_sim908.php?", url);

You have five " in this line... Probably not what you need. :slight_smile:

Actually, I think it needs one more:

                                                                   // right here...
sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http://%s/demo_sim908.php?\"", url);

econjack:
Actually, I think it needs one more:

                                                                   // right here...

sprintf(aux_str, "AT+HTTPPARA="URL","http://%s/demo_sim908.php?"", url);

I added that escaped quote and the symptom did not change.
What seems to be causing the problem is the "//" in http://%s. If that is changed to // the code compiles. O.o? I guess the colorizer is seeing it as part of a string but the compiler is seeing it as a start of comment. Looks like the compiler will let you start a comment in the middle of a string!?!

@John: Good grief! I would never have even thought that was possible in a normal parsing scheme. Good catch!

You must have stumbled upon an Arduino bug. If I look at that line in the Arduino-processed file pre-compilation, that line gets translated to the following:

           sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http:

So, like you said, the Arduino pre-pre-processor is mistreating that double slash as a comment and truncating the line.

A possible workaround is writing the line as follows:

sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http:/" "/%s/demo_sim908.php?", url);

Anyway I think you should really file a bug to the Arduino team.

Things get weird after this:

        //Stores phone calling number
          for (int i=0; i<=14; i++){
            if(number[i]== '"'){

Normally comments are stripped from the he generated .cpp file, but after the above lines comments are intact.

A small sketch to replicate the weirdness:

void setup() {
  // comment 1
  if ('0' == '"') {}
  // comment 2
  char aux_str[128];
  char url[] = "foo.bar";
  sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http://%s/demo_sim908.php?\"", url);
}

void loop() { }

Generated .cpp file:

#line 1 "sketch_aug27c.ino"
#include "Arduino.h"
void setup();
void loop();
#line 1
void setup() {
              
  if ('0' == '"') {}
  // comment 2
  char aux_str[128];
  char url[] = "foo.bar";
  sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http:                               
}

void loop() { }

When I change '"' to '\"' everything gets back to normal.

This is an IDE problem; I can compile the sketch (after adding #include <stdio.h> and main()) directly without problems.

This is way too short

char aux_string[30];

Wait a minute, I meant this

char aux_str[30];

SukkoPera:
You must have stumbled upon an Arduino bug. If I look at that line in the Arduino-processed file pre-compilation, that line gets translated to the following:

           sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http:

So, like you said, the Arduino pre-pre-processor is mistreating that double slash as a comment and truncating the line.

A possible workaround is writing the line as follows:

sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http:/" "/%s/demo_sim908.php?", url);

Anyway I think you should really file a bug to the Arduino team.

THANKS a lot it worked , I didn't still upload on my board but it compiled without any errors.