0

I have a problem to combine both code for Arduino GSM Shield and Adafruit Ultime GPS Shield. I already change my code to the basic one like examples. I think i found the problem. The problem is when i want to do get request to the url/web.

Here is the link to the Adafruit Ultimate GPS Shield. Adafruit Library Adafruit Ultimate GPS Shield Info

My code base on example of Arduino GSM Library (GSM Web Client) and Adafruit GPS Library (Parsing)

This is the code that make my code not working. If i put the code i do not receive any data at serial.

Blank Data at serial

 // if you get a connection, report back via serial:
 if (client.connect(server, port))
 {
 Serial.println("connected");
 // Make a HTTP request:
 client.print("GET ");
 client.print(path);
 client.println(" HTTP/1.1");
 client.print("Host: ");
 client.println(server);
 client.println("Connection: close");
 client.println();
 } 
 else
 {
 // if you didn't get a connection to the server:
 Serial.println("connection failed");
 }

This is the basic code that working so far

Working Code

// ********************************************
// GPS Library
// ********************************************
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <stdlib.h>
// ********************************************
// GSM Library
// ********************************************
#include <GSM.h>
// ********************************************
// Sim Card Pin Number if available
// ********************************************
#define PINNUMBER ""
// ********************************************
// Set Up APN data for GPRS Connection
// ********************************************
#define GPRS_APN "Maxis" // replace your GPRS APN
#define GPRS_LOGIN "maxis" // replace with your GPRS login
#define GPRS_PASSWORD "wap" // replace with your GPRS password
// ********************************************
// Initialize GSM Library
// ********************************************
GSMClient client;
GPRS gprs;
GSM gsmAccess; 
// ********************************************
// Setup Arduino to browse URL/web through GPRS
// The code below will setup path like:
// http://arella.com.my/urltomysql.php?firstname=Muhammad&lastname=Faiz
// When Arduino browse the web, it will submit firstname:Muhammad
// and lastname:Faiz into database. I want to store GPS data into database later
// ********************************************
char server[] = "arella.com.my";
char path[] = "/urltomysql.php?firstname=Muhammad&lastname=Faiz";
int port = 80; // port 80 is the default for HTTP
// ********************************************
// Set Adafruit GPS to use software serial on pin 
// D9 & D10 on Arduino. Use Jumper Wire from D7,D8 to D9,D10
// ********************************************
SoftwareSerial mySerial(10, 9);
Adafruit_GPS GPS(&mySerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences. 
#define GPSECHO false
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
//***********************************************
// convert NMEA GPS Format to Google Map Format
//***********************************************
int degLatInt, degLongInt;
float minLatFloat, minLongFloat, googleMapsLat, googleMapsLong;
char* lat_str = new char[10];
char* long_str = new char[10];
char degLatString[5], degLongString[5];
void setup() 
{ 
 Serial.begin(115200);
 gsmAccess.begin(PINNUMBER);
 gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);
 boolean notConnected = true;
 while(notConnected)
 {
 if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
 (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
 notConnected = false;
 else
 {
 Serial.println("Not connected");
 delay(1000);
 }
 }
 // If i enable the code below, my code not working.
 /* if (client.connect(server, port))
 {
 Serial.println("connected");
 // Make a HTTP request:
 client.print("GET ");
 client.print(path);
 client.println(" HTTP/1.1");
 client.print("Host: ");
 client.println(server);
 client.println("Connection: close");
 client.println();
 } */
 //***********************************************
 // Setup Adafruit GPS Shield
 //***********************************************
 // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
 // also spit it out
 Serial.println("Adafruit GPS library basic test!");
 // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
 GPS.begin(9600);
 // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
 // uncomment this line to turn on only the "minimum recommended" data
 //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
 // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
 // the parser doesn't care about other sentences at this time
 // Set the update rate
 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
 // For the parsing code to work nicely and have time to sort thru the data, and
 // print it out we don't suggest using anything higher than 1 Hz
 // Request updates on antenna status, comment out to keep quiet
 GPS.sendCommand(PGCMD_ANTENNA);
 // the nice thing about this code is you can have a timer0 interrupt go off
 // every 1 millisecond, and read data from the GPS for you. that makes the
 // loop code a heck of a lot easier!
 useInterrupt(true);
 delay(1000);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
 char c = GPS.read();
 // if you want to debug, this is a good time to do it!
 #ifdef UDR0
 if (GPSECHO)
 if (c) UDR0 = c; 
 // writing direct to UDR0 is much much faster than Serial.print 
 // but only one character can be written at a time. 
 #endif
}
void useInterrupt(boolean v) {
 if (v) 
 {
 // Timer0 is already used for millis() - we'll just interrupt somewhere
 // in the middle and call the "Compare A" function above
 OCR0A = 0xAF;
 TIMSK0 |= _BV(OCIE0A);
 usingInterrupt = true;
 } else 
 {
 // do not call the interrupt function COMPA anymore
 TIMSK0 &= ~_BV(OCIE0A);
 usingInterrupt = false;
 }
}
uint32_t timer = millis();
void loop() // run over and over again
{
 // if a sentence is received, we can check the checksum, parse it...
 if (GPS.newNMEAreceived()) {
 // a tricky thing here is if we print the NMEA sentence, or data
 // we end up not listening and catching other sentences! 
 // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
 //Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
 if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
 return; // we can fail to parse a sentence in which case we should just wait for another
 }
 // if millis() or timer wraps around, we'll just reset it
 if (timer > millis()) timer = millis();
 // approximately every 2 seconds or so, print out the current stats
 if (millis() - timer > 5000) { 
 timer = millis(); // reset the timer
 Serial.print("\nTime: ");
 Serial.print(GPS.hour+8, DEC); Serial.print(':');
 Serial.print(GPS.minute, DEC); Serial.print(':');
 Serial.print(GPS.seconds, DEC); Serial.print('.');
 Serial.println(GPS.milliseconds);
 Serial.print("Date: ");
 Serial.print(GPS.day, DEC); Serial.print('/');
 Serial.print(GPS.month, DEC); Serial.print("/20");
 Serial.println(GPS.year, DEC);
 Serial.print("Fix: "); Serial.print((int)GPS.fix);
 Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
 if (GPS.fix) { 
 /////////// Latitude /////////////
 // Convert NMEA Latitude to String
 dtostrf(GPS.latitude, 7, 4, lat_str); //convert GPS.latitude from float to String. 7 - means 8 characters long ; 4 - means 4 decimal point 
 // Get Degree substring from latitude String
 strncpy(degLatString, lat_str, 1); // Get Degree from Full Latitude String. Example 311.7799 - Get 3
 // Get Minutes substring from latitude String
 char* minLatString = lat_str + 1; // Move pointer up 1 position. Example 311.7799 will move to 11.7799
 // Convert Deg String to int
 degLatInt = atoi(degLatString);
 // COnvert Min String to float
 minLatFloat = atof(minLatString);
 //Convert NMEA latitude to Google Maps latitude
 googleMapsLat = degLatInt + (minLatFloat / 60); 
 Serial.print("Google Map Latitude: ");
 Serial.println(googleMapsLat, 4);
 //////////// Longitude /////////////
 // Convert NMEA Longitude to String
 dtostrf(GPS.longitude, 8, 4, long_str); //convert GPS.latitude from float to String. 8 - means 9 characters long ; 4 - means 4 decimal point 
 // Get Degree substring from latitude String
 strncpy(degLongString, long_str, 3); // Get Degree from Full Latitude String. Example 10141.91699 - Get 141
 // Get Minutes substring from latitude String
 char* minLongString = long_str + 3; // Move pointer up 3 position. Example 10141.9169 will move to 41.7799
 // Convert Deg String to int
 degLongInt = atoi(degLongString);
 // COnvert Min String to float
 minLongFloat = atof(minLongString);
 //Convert NMEA latitude to Google Maps latitude
 googleMapsLong = degLongInt + (minLongFloat / 60); 
 Serial.print("Google Map Longitude: ");
 Serial.println(googleMapsLong, 4);
 Serial.print("Speed (KM): "); Serial.println(GPS.speed * 1.85);
 }
 }
}
asked Oct 2, 2014 at 11:25

1 Answer 1

1

I'm working on the same project (with the same hardware) and I have an identical problem. Seems like an HTTP request blows up your serial monitor, but is not true in my view. In fact, if you use the TinyGPS++ library will not have this problem anymore. Take as reference the GsmWebClient example, you can add a few lines of code.

This is all you need for parse with tinyGPS:

#include <AltSoftSerial.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
AltSoftSerial ss;
//Add this to your sketch, in loop() or setup()
ss.begin(9600);
while (ss.available() > 0)
 if (gps.encode(ss.read())) {
 gps.location.lat(); //return latitude as a double
 gps.location.lng(); //return longitude as a double
}
Anonymous Penguin
6,36510 gold badges34 silver badges62 bronze badges
answered Nov 22, 2014 at 15:35
2
  • Does that code fix the issue? Commented Nov 25, 2014 at 1:52
  • Thanks penguin for editing! This is not a real fix for the error, it's a bypass.. I think the problem is given by AdafruiGPS lib, and everything is solved using TinyGPS. This code is all you need for get the coordinates with the new library. Commented Nov 26, 2014 at 11:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.