Go Down

Topic: inetGSM Library (Read 3611 times) previous topic - next topic

moemzn

Greetings,
I'm using inetGSM library to send AT Commands to my GSM shield, everything went good with GSM shield testing i could connect to my TCP server and send receive data.
Now i tried to interface a GPS module along with the GSM to send the coordinates to the TCP server and receive commands from the TCP server.
The first problem i faced is, since booth libraries use software serial, i have to use gsm.listen() gps.listen() so i can switch between modules since software serial doesnt work in the same time.
The gps library have the definition of the ports outside the library so i could use GPS.listen() without any problems, but when i try to listen to the GSM module by using gsm.listen() i get this error ("'class SIMCOM900' has no member named 'listen' ) and i understand why i'm getting this error, but i don't know how to get the MC to listen to the GSM module.
The second problem is, when i want to receive data from TCP server and save it in any variable it doesn't work, again because there is no ("gsm.available()") in the library to check if there is any coming data from the server.
NOTE: Tried to push AT commands without using the library, it's not working!

moemzn

Here is the code
Code: [Select]
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include "inetGSM.h"
InetGSM inet;
SoftwareSerial GPS(10,11);

char msg[50];
int numdata;
char inSerial[50];
int i=0;
char a;
boolean started=false;
byte count=0;
unsigned long start;
int time_to_go;
unsigned long fix_age; //GPS
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;




void setup()
{
  //Serial connection.
  Serial.begin(9600);
  GPS.begin(4800);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  gsm.listen();
  if (gsm.begin(4800))
  {
    Serial.println("\nstatus=READY");
    started=true; 
    gsm.forceON();
  }
  else Serial.println("\nstatus=IDLE");
  if(started)
  {
    //GPRS attach, put in order APN, username and password.
    //If no needed auth let them blank.
    if (inet.attachGPRS("Etisalat", "", ""))
      Serial.println("status=ATTACHED");
    else Serial.println("status=ERROR");
    delay(1000);
 
   
    gsm.SimpleWriteln("AT+CIFSR");
    delay(5000);
    //Read until serial buffer is empty.

   gsm.WhileSimpleRead(); //Read until serial buffer is empty.
   gsm.SimpleWrite("AT+CIPSTART=\"TCP\",\"");
   gsm.SimpleWrite("41.**.**.***");
   gsm.SimpleWrite("\",");
   gsm.SimpleWriteln("70");
   Serial.println("Connecting.....");
   delay(5000);
   gsm.WhileSimpleRead();
  }
  }
   void loop()
   {
GPS.listen(); // GPS Begin
        long lat, lon;
        unsigned long fix_age, time, date, speed, course, year,month,day,hour,minute,second;
        unsigned long chars;
        unsigned short sentences, failed_checksum;
        // retrieves +/- lat/long in 100000ths of a degree
        gps.get_position(&lat, &lon, &fix_age);
        //time in hh:mm:ss, date in dd/mm/yy
        gps.get_datetime(&date, &time, &fix_age);
        getGPS();

        gsm.SimpleWriteln("AT+CIPSEND");
        gsm.SimpleWrite(LON);
        gsm.SimpleWrite(LAT);
        delay(500);
        gsm.SimpleWrite(0x1A);       //sends ++
        gsm.SimpleWrite(0x0D);
        gsm.SimpleWrite(0x0A);
        delay(500);
   
   
   }
   void getGPS()
{
 
bool newdata = false;
unsigned long start = millis();
// Every 1 seconds we print an update
while (millis() - start < 1000)
{
 
if (feedgps ()){
newdata = true;
}
}
if (newdata)
{Serial.println("test:");
gpsdump(gps);
}
}
bool feedgps(){
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}
return 0;
}
void gpsdump(TinyGPS &gps)
{
//byte month, day, hour, minute, second, hundredths;
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
  {
   feedgps();
   
// If we don't feed the gps during this long routine, we may drop characters and get checksum errors;
  }
 

  // blank line to separate data from the two ports:
  Serial.println();
}

RudiAhlers

To which pins do you have the GPS, and GSM modules / shields connected respectively?
And which Arduino do you have?

Go Up