0

i bought this shield.

My project is to make a tracker using the gps and upload the data to server

this is the code im using

int8_t answer;
int onModulePin= 2;
char gps_data[100];
int counter;


char aux_str[50];

char server[ ]="***.***.net"; 
char port[ ]="80";


void setup(){

pinMode(onModulePin, OUTPUT);
Serial.begin(115200); 

Serial.println("Starting...");
power_on();

delay(5000);

// starts GPS session in stand alone mode
answer = sendATcommand("AT+CGPS=1,1","OK",1000); 
if (answer == 0)
{
Serial.println("Error starting the GPS");
Serial.println("The code stucks here!!");
while(1);
}

//sendATcommand("AT+CPIN=5512", "OK", 2000);
//delay(3000);

while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || 
sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

// sets APN, user name and password
sendATcommand("AT+CGSOCKCONT=1,\"\",\"jawalnet.com.sa\"", "OK", 2000);
sendATcommand("AT+CSOCKAUTH=1,1,\"\",\"\"", "OK", 2000);


}
void loop(){

answer = sendATcommand("AT+CGPSINFO","+CGPSINFO:",1000); // request info from GPS
if (answer == 1)
{

counter = 0;
do{
while(Serial.available() == 0);
gps_data[counter] = Serial.read();
counter++;
}
while(gps_data[counter - 1] != '\r');
gps_data[counter] = '\0';
if(gps_data[0] == ',')
{
Serial.println("No GPS data available"); 
}
else
{
Serial.print("GPS data:");
Serial.println(gps_data); 
Serial.println("");


sprintf(aux_str, "AT+NETOPEN=\"TCP\",%s", port);
answer = sendATcommand(aux_str, "Network opened", 20000);

if (answer == 1)
{
Serial.println("Network opened");
sprintf(aux_str, "AT+TCPCONNECT=\"%s\",%s", server, port);
answer = sendATcommand(aux_str, "Connect ok", 20000);
if (answer == 1)
{
Serial.println("Socket opened");
sprintf(aux_str, "AT+TCPWRITE=%d", strlen(gps_data));
answer = sendATcommand(aux_str, ">", 20000);
if (answer == 1)
{
sendATcommand(gps_data, "Send OK", 20000); 
}
sendATcommand("AT+NETCLOSE", "OK", 20000);
}
else
{
Serial.println("Error opening the socket");
sendATcommand("AT+NETCLOSE", "OK", 20000);
}
}
else
{
Serial.println("Error opening the nertwork");
sendATcommand("AT+NETCLOSE", "OK", 20000);
}

} 

}
else
{
Serial.println("Error"); 
}

delay(5000);
}

void power_on(){

uint8_t answer=0;

// checks if the module is started
answer = sendATcommand("AT", "OK", 2000);
if (answer == 0)
{
// power on pulse
digitalWrite(onModulePin,HIGH);
delay(3000);
digitalWrite(onModulePin,LOW);

// waits for an answer from the module
while(answer == 0){ 
// Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", "OK", 2000); 
}
}

}


int8_t sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout)
{

uint8_t x=0, answer=0;
char response[100];
unsigned long previous;

memset(response, '\0', 100); // Initialize the string

delay(100);

while( Serial.available() > 0) Serial.read(); // Clean the input buffer

Serial.println(ATcommand); // Send the AT command 


x = 0;
previous = millis();

// this loop waits for the answer
do{

if(Serial.available() != 0){ 
response[x] = Serial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL) 
{
answer = 1;
}
}
// Waits for the asnwer with time out
}
while((answer == 0) && ((millis() - previous) < timeout)); 

 Serial.println(response); 

return answer;
}

i don't know why its not connecting to the server !

this is on serial monitor

    AT+NETOPEN="TCP",80

    Network opened

    AT+TCPCONNECT="malik.basalamah.net",80


    Connect ok
    Socket opened
    AT+TCPWRITE=55

    >
    2124.751744,N,03946.686557,E,010314,154812.0,267.0,0,0

    ted</h1>
    <p>AT+TCPWRITE=55 to /index.html not supported.<br />
    </p>
    </body></html>


    +IPCLOSE: 255, 1, 173.236.148.10, 80

    +IPCLOSE: 255, 2, 173.236.148.10, 80
    html><head>
    <title>501 Method NotStarting...

this is the php script < im just trying to get response from server >

<?php
 var_dump($_REQUEST["gps_data"]);
?>

please help me !

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
user1248503
  • 81
  • 1
  • 6

1 Answers1

-1

You are opening TCP connection and trying to read it as HTTP, it wont work this way. If you want to get data in PHP, you have to open HTTP connection instead.