Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

//#define PIN_TX    1
//#define PIN_RX    0
//SoftwareSerial mySerial(PIN_TX,PIN_RX);
//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

//make sure that the baud rate of SIM900 is 9600!
//you can use the AT Command(AT+IPR=9600) to set it through SerialDebug

DFRobot_SIM808 sim808(&Serial);

char buffer[512];
int i = 0;

void setup(){
  //mySerial.begin(9600);
  Serial.begin(9600);

  //******** Initialize sim808 module *************
  while(!sim808.init()) {
      delay(1000);
      Serial.print("Sim808 init error\r\n");
  }
  delay(3000);

  //*********** Attempt DHCP *******************
  while(!sim808.join(F("mobitel3g"))) {
      Serial.println("Sim808 join network error");
      delay(2000);
  }

  //************ Successful DHCP ****************
  Serial.print("IP Address is ");
  Serial.println(sim808.getIPAddress());


  //************* Turn on the GPS power************
    while(!sim808.attachGPS()) {
      delay(1000);
      Serial.print("Open the GPS power failure\r\n");
  }
  
  delay(3000);  
  Serial.println("Open the GPS power success");

for(int i = 0; i<=40;i++)
{
  for(int y = 0;y<=i;y++)
  {
  Serial.print(".");
  delay(60);
  }
 Serial.println("");
}
}

void loop(){
  tcp();      
  delay(2000);

  //Calls the function every 2 seconds
}


void tcp()
{
    // Update the GPS data
    float lati, longi;
    if (sim808.getGPS()) {
      
      Serial.print(sim808.GPSdata.year);
    Serial.print("/");
    Serial.print(sim808.GPSdata.month);
    Serial.print("/");
    Serial.print(sim808.GPSdata.day);
    Serial.print(" ");
    Serial.print(sim808.GPSdata.hour);
    Serial.print(":");
    Serial.print(sim808.GPSdata.minute);
    Serial.print(":");
    Serial.print(sim808.GPSdata.second);
    Serial.print(":");
    Serial.println(sim808.GPSdata.centisecond);
    
        lati = sim808.GPSdata.lat,6;
        longi = sim808.GPSdata.lon,6;

        //print the variables 
        Serial.print("LAT =");
        Serial.println(lati);
        Serial.print("LON =");
        Serial.println(longi);
        sim808.detachGPS();
    }
    else {
        // No gps, abort
        Serial.println("No GPS");
        return;
    }
    //*********** Establish a TCP connection ************

    if (!sim808.connect(TCP,"http://syntiq.lk", 80)) {
       Serial.println("Connect error");
       return;
    }
    else {
       Serial.println("Connect mbed.org success");
    }

   //*********** Send a GET request *****************

    char http_cmd[100];
    sprintf(http_cmd, "GET /GPS/Addtoserver.php?data2=%f&data1=%f HTTP/1.0\r\n\r\n\0", lati, longi);
    sim808.send(http_cmd, strlen(http_cmd));

    /*
    int ret = sim808.recv(buffer, sizeof(buffer) - 1);
    if (ret <= 0){
        Serial.println("error receiving");
    }
    else {
        buffer[ret] = '\0';
        Serial.print(buffer);
    }
    */

    //************* Close TCP or UDP connections **********
    sim808.close();

    //*** Disconnect wireless connection, Close Moving Scene *******
    sim808.disconnect();
}


What I have tried:

Above is my code that fetches the GPS coordinates and inserts it into a mysql database. I'm sure that the GPS module and the Arduino is working because i tried both the TCP and the GPS codes separately. So can someone point me in the right direction where i went wrong. Your help will be greatly appreciated. Thank You
Posted
Updated 28-Jan-19 21:41pm
Comments
Richard MacCutchan 29-Jan-19 4:35am    
You first need to explain what the problem is.
Member 14046963 30-Jan-19 3:34am    
The problem is that im not receiving any GPS data when i insert the TCP connection into the GPS code. GPS code itself alone works fine.
Richard MacCutchan 30-Jan-19 4:07am    
Then you need to debug that code and gather more information. We cannot tell what is happening.

1 solution

The code shows just the Arduino code, not the server side one.
Assuming (as you claim) both the TCP and GPS Arduino code works well, then you must have a problem on the very server side.
Anyway, to debug the server code, I would try to upload some well known simple data from a well known simple HTTP client.
 
Share this answer
 
Comments
Member 14046963 29-Jan-19 4:54am    
Hey @CPallini im also sure that the php file is working and theres no error in the server side. My only issue is that though I ran the codes separately, in this case i use the sim808 functions in a different order. I'm not sure if that's the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900