Thanks for the reply,
Can you modify this code from http in
https://www.cooking-hacks.com/projects/ ... on-tracker so that it can be used with raspberry pi.
Code:
/*
* Geocaching Santa Claus
*
* Copyright (C) Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* a
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* Version: 2.0
* Design: David Gascón
* Implementation: Luis Martin
*/
int8_t answer;
int onModulePin= 2;
char gps_data[100];
int counter;
char aux_string[30];
char phone_number[]="*********";
int data_size = 0;
int end_file = 0;
char aux_str[100];
char data[350];
int x = 0;
long previous;
char url[ ]="cooking-hacks.com";
int port= 80;
char request[ ]="GET /t/gps-route.php?gps=";
char request1[ ]= "HTTP/1.1\r\nHost: cooking_hacks.com\r\nContent-Length: 0\r\n\r\n";
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);
}
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,\"IP\",\"movistar.es\"", "OK", 2000);
sendATcommand("AT+CSOCKAUTH=1,1,\"movistar\",\"movistar\"", "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");
delay(3000);
}
else
{
answer = sendATcommand("AT+CGPS=0","OK",1000);
// request the url
sprintf(aux_str, "AT+CHTTPACT=\"%s\",%d", url, port);
answer = sendATcommand(aux_str, "+CHTTPACT: REQUEST", 60000);
if (answer == 1)
{
Serial.print(request);
Serial.print(gps_data);
Serial.println(request1);
// Sends
aux_str[0] = 0x1A;
aux_str[1] = 0x00;
answer = sendATcommand(aux_str, "+CHTTPACT: DATA,", 60000);
if (answer == 1)
{
Serial.print("Sent ");
int a=0;
for(int a=0;a<60;a++){ //Wait 30 minutes
delay(30000);
}
// 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);
}
}
else
{
Serial.print("error ");
}
}
else
{
Serial.print("error ");
Serial.println(answer, DEC);
}
}
}
else
{
Serial.println("Error");
}
}
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));
return answer;
}