0

I'm basically trying to make a device that pulls the GPS information from a SIM808 and pushes it to a server online via GPRS.

I am sorry as I am not good at programming so ive spent days trying to debug this but i have not been able to figure out whats wrong.

Ill get the basics out of the way.

Board: Mega2560 (I know its overkill but its what i had in hand) SIM+GPS sensor: SIM808 Module TinyGPS v13 RTC: DS1307 Arduino IDE v1.8.8

Down to the specifics, I started with SoftwareSerial Library but i heard it was inefficient so i switched to AltSoftSerial. The serial library is working as I do get output using AT commands. The problem is that when i load up the stock TinyGPS example sketch sometimes it works sometimes it gives me error saying the GPS module wasn't detected.

i tried using AT commands directly or a different GPS library but i cant figure out how to pass on data to a database over GPRS.

but basically I am sure the wiring isn't faulty nor is the GPS module (i hope) as it gives an output at ATCommands, even the RTC module is confirmed working. I know the URL in the ATCommand is fake but that is for demonstration purposes.

Coming to the code below. If i change the bool newData = false; to bool newData = true; the the code works just once with wrong GPS information.

any help would be greatly appreciated. Thank You

Edit 1: The problem has been solved, it wasn't working when i used both GPS and GPRS on SIM808 i switched to NeoGPS 6m module and GPRS from SIM800/808 it worked. Thank You.

#include <AltSoftSerial.h>
#include <TinyGPS.h>

#include <Wire.h>
#include <DS1307new.h>


TinyGPS gps;

SoftwareSerial sGPS (46,48);

uint16_t startAddr = 0x0000;  //Start address to store in NVRam
uint16_t lastAddr;        //New address to store in NVRam
uint16_t TimeIsSet = 0xaa55;  //Helper that time must not be set again

int currentDay = 0;
int currentMonth = 0;
int currentYear = 0;
int currentHour = 0;
int currentMinute = 0;

float flat, flon;
float previousFLat = 0.0;
float previousFLon = 0.0;

void setup()
{


  Serial.begin(9600);
  sGPS.begin(9600);


  /*
  Control the clock.
  Clock will only be set if NV-RAM Address does not contain 0xaa.
  DS1307 should have a battery backup.
  */

  RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
  if (TimeIsSet != 0xaa55)
  {
    RTC.stopClock();

    RTC.fillByYMD(2011,4,8);
    RTC.fillByHMS(22,7,0);

    RTC.setTime();
    TimeIsSet = 0xaa55;
    RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
    RTC.startClock();
  }
  else
  {
    RTC.getTime();
  }

  /*
   Control Register for SQW pin which can be used as an interrupt.
*/
  RTC.ctrl = 0x00;                      // 0x00=disable SQW pin, 0x10=1Hz,
                                        // 0x11=4096Hz, 0x12=8192Hz, 0x13=32768Hz
  RTC.setCTRL();
  delay(5000);
  }

  void loop()
{
    RTC.getTime();

    currentDay = RTC.day;
    currentMonth = RTC.month;
    currentYear = RTC.year;
    currentHour = RTC.hour;
    currentMinute = RTC.minute;


  bool newData = false;

  //For one second we parse GPS data and report some key values

  for (unsigned long start = millis(); millis() - start < 1000;)

  {
  while (sGPS.available())
    {
      char c = sGPS.read();
      Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
      newData = true;
    }

  }

  if (newData)
  {
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);

    if ((flat !=previousFLat)||(flon !=previousFLon))
    {
      previousFLat = flat;
      previousFLon = flon;
      Serial.print (previousFLat,6);
      Serial.println(previousFLon,6);
      SendSQL();
    }
  }

}  


  void SendSQL()
  {

    //Serial.println("Start Send");
    Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
    delay(500);
    Serial.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"");
    delay(500);
    Serial.println("AT+SAPBR=1,1");
    delay(500);
    Serial.println("AT+SAPBR=2,1");
    delay(3000);
    Serial.println("AT+HTTPINIT");
    delay(500);
    Serial.println("AT+HTTPARA=\"CID\",1");
    delay(500);
    Serial.print("AT+HTTPARA=\"URL\",\"www.google.com/add_data.php?");
    Serial.print("addDay=");

      if (currentDay <10)
        {
        Serial.print("0");
        Serial.print(currentDay);
        }

      else
        {
        Serial.print(currentDay);
        }

      Serial.print("/");

      if (currentMonth < 10)
        {
          Serial.print("0");
          Serial.print(currentMonth);
        }

      else 
        {
          Serial.print(currentMonth);
        }

      Serial.print("/");
      Serial.print(currentYear);
      Serial.print("&addHour=");

      if (currentHour <10) 
        {
          Serial.print("0");
          Serial.print(currentHour);
        }

        else

        {
          Serial.print(currentHour);
        }

        Serial.print(":");

        if (currentMinute <10) 

        {
          Serial.print("0");
          Serial.print(currentMinute);
        }

        else

        {
          Serial.print (currentMinute);
        }

          Serial.print ("&addLati=");
          Serial.print(previousFLat, 6);
          Serial.print("&addLongti=");
          Serial.print(previousFLon, 6);
          Serial.println("\"");
          delay(3000);
          Serial.println("AT+HTTPACTION=0");
          delay(15000);
          Serial.println("AT+HTTPTERM");
          delay(500);
          Serial.println("AT+SAPBR=0,1");
          delay(500);
          Serial.println("Finish");
        }
  • what did you do to debug the problem? .... which parts worked? .... which parts failed? – jsotola Dec 27 '18 at 17:32
  • tip: replace if (currentDay <10) block with only two lines if (currentDay <10) Serial.print("0"); and Serial.print(currentDay); ...... do the similarly for the other if blocks – jsotola Dec 27 '18 at 17:38
1

I agree with above answer use the Serial ports available and do something in your setup to probe the sim808 until you get some feedback I am using SIM868 in one of my projects and had the same problem of not getting any feedback until i set a while loop up in the setup that was probing by only sending 'AT' to the module (I did not use tinyGPS i only used Serial and sent it AT commands)

Here the application notes with the AT commands for the GPS side of SIM808

This approach will give you a better idea of what is happening and where you are going wrong

0

You have a Mega with 4 hardware serial ports. Use of those - Serial1, Serial2, Serial 3 - to talk to the GPS.

I did a project with a SIM808 module from DF Robotics. I spent some time just powering the GPS part of it up and watching what came out. Do the same with some simple serial print statements.

if (Serial1.available() >0){
Serial.print(Serial1.read());
}

Then when you understand what comes out, you can watch in setup() for the end of messages that indicate you have good GPS data, or just send AT commands until you get a good reply back. My module took I think 7-8 seconds before it would talk, so I just waited in setup() until I started getting messages. I knew what to expect from the above testing, it was always a fixed amount, so I grabbed all that, looked at the last few to make sure it was as expected, then started the GPS commands to see if it had good data from the satellites before continuing. I suspect the TinyGPS library does similar, but the SIM808 module added some extra characters, or you had to add extra characters, to identify GPS commands from the text message commands the SIM808 expected.

0

The problem has been solved, it wasn't working when i used both GPS and GPRS on SIM808 i switched to NeoGPS 6m module and GPRS from SIM800/808 it worked. Thank You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.