Problem with URL string for web server.

Hello all,

Been trying to get the Arduino to display my current location on a google map. I have a Wiznet Ethernet Shield and the SparkFun GPS shield. The Ethernet shield is serving the webpage and the GPS shield supplies the co-ordinates (just to state the obvious :grin:). My problem is I get an error saying:

GPS_WebServer:93: error: missing terminating " character
GPS_WebServer:117: error: missing terminating " character
GPS_WebServer:93: error: expected `)' before numeric constant
GPS_WebServer:93: error: 'q' was not declared in this scope
GPS_WebServer:105: error: expected primary-expression before '<' token
GPS_WebServer:105: error: expected primary-expression before '/' token
GPS_WebServer:105: error: 'iframe' was not declared in this scope
GPS_WebServer:105: error: expected primary-expression before '<' token
GPS_WebServer:105: error: 'br' was not declared in this scope
GPS_WebServer:105: error: expected primary-expression before '>' token
GPS_WebServer:105: error: expected primary-expression before '<' token
GPS_WebServer:105: error: 'small' was not declared in this scope
GPS_WebServer:105: error: expected primary-expression before '<' token
GPS_WebServer:105: error: 'a' was not declared in this scope

I'm guessing this is down to the // and >? Is there a way to escape these characters?

// Sketch to output current location to web server. --CSW

#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>

//Pins to communicate with the GPS module
#define RXPIN 2
#define TXPIN 3

#define TERMBAUD  115200 //Serial rate for the terminal program.
#define GPSBAUD  4800

TinyGPS gps; //Create an instance of the TinyGPS opject.
SoftwareSerial uart_gps(RXPIN, TXPIN); //Intialise the NewSoftSerial Library to the pins above.
void getgps(TinyGPS &gps);

//Setup MAC and IP address of Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,102);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);


void setup()
{
 Serial.begin(TERMBAUD);  // Open serial communications and wait for port to open:
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  
 uart_gps.begin(GPSBAUD);
 Serial.println("");
 Serial.println("GPS Shield QuickStart");
 Serial.println("       ...waiting for lock...           ");
 Serial.println("");

 
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("Server is at ");
  Serial.println(Ethernet.localIP());
}


void loop()
{
  
// GPS LOOP START  
  while(uart_gps.available())     // While there is data on the RX pin...
  {
      int c = uart_gps.read();    // load the data into a variable...
      if(gps.encode(c))      // if there is a new valid sentence...
      {
        getgps(gps);         // then grab the data.
      }
  }
// Define the variables that will be used
  float latitude, longitude;
// Then call this function
  gps.f_get_position(&latitude, &longitude);

//GPS LOOP FINISH

//ETHERNET LOOP START
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
//	  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.print("<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https:maps.google.co.uk/maps?safe=off&amp;q=");
          client.print(latitude,5);
          client.print(",+");
          client.print(longitude,5);
          client.print("&amp;ie=UTF8&amp;hq=&amp;hnear=0x48778bd16cef42bb:0x39dd825ada7ffaef,");
          client.print(latitude,5);
          client.print(",+");
          client.print(longitude,5);
          client.print("&amp;gl=uk&amp;t=m&amp;z=14&amp;ll=");
          client.print(latitude,5);
          client.print(",+");
          client.print(longitude,5);
          client.print("&amp;output=embed"></iframe>
<small><a href="https://maps.google.co.uk/maps?safe=off&amp;q=");
          client.print(latitude,5);
          client.print(",+");
          client.print(longitude,5);
          client.print("&amp;ie=UTF8&amp;hq=&amp;hnear=0x48778bd16cef42bb:0x39dd825ada7ffaef,");
          client.print(latitude,5);
          client.print(",+");
          client.print(longitude,5);
          client.print("&amp;gl=uk&amp;t=m&amp;z=14&amp;ll=");
          client.print(latitude,5);
          client.print(",+");
          client.print(longitude,5);
          client.print("&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>");

          client.println();
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }

}

// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
  // To get all of the data into varialbes that you can use in your code, 
  // all you need to do is define variables and query the object for the 
  // data. To see the complete list of functions see keywords.txt file in 
  // the TinyGPS and NewSoftSerial libs.
  
  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  gps.f_get_position(&latitude, &longitude);
  // You can now print variables latitude and longitude
  Serial.print("Lat/Long: "); 
  Serial.print(latitude,5); 
  Serial.print(", "); 
  Serial.println(longitude,5);
  delay(10000);
}

The errors are all around the embed code from google (client.print section of the code). The way I have produced the html code is very tacky, but was just wanting to get something working before I go cleaning the code up a bit. As you all will tell, I am a very novice programmer. On another question, I'd rather use the function at the bottom of the code called 'getgps' to input the lat and long into the html string, but can't for the life of me work out how to do it. Any ideas?

Sorry for the long winded question, any help is much appreciated.

Chris

          client.print("<iframe width="425" height="350" ...

If you have a quote within a quote you have to escape it.

eg,

          client.print("<iframe width=\"425\" height=\"350\" ...

Perfect, thanks a lot!!

Chris

In the world of HTML, usually a single quote ' can be used instead of a double quote ", which can reduce visual clutter in the arduino HTML coding.