hi ...
i try make program to get location gps from cellular operator here the script :
/*
*Turn ON GSM at Pin12
*Turn on GPRS
*Get location with CIPGSMLOC
*Capture Serial and print
*28.Sept.2016 @sonjayadotwebdotid
*
*/
char latitude[15];
char longitude[15];
char inChar;
int index;
char inData[100];
int pinpwr = 12;
void setup()
{
//Init the driver pins for GSM function
pinMode(pinpwr,OUTPUT);
turn_ON_GSM();
delay(15000);
start_NET();
delay(5000);
}
void loop()
{
read_GPS_GSM();
delay(5000);
show_GPS();
delay(5000);
}
void turn_ON_GSM (){
Serial.println("Turn On GSM");
digitalWrite(pinpwr,HIGH); //turn on at pin 12
delay(2000);
digitalWrite(pinpwr,LOW); //
delay(10000);
Serial.begin(9600); //set bautrate serial
delay(20000);
}
void start_NET(){
delay(5000);
Serial.println("Start GPRS");
delay(2000);
Serial.println("AT+SAPBR=3,1,\"APN\",\"indosatgprs\""); //set apn name
delay(2000);
Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\""); //profile with be use
delay(2000);
}
void read_GPS_GSM(){
Serial.println("read GSM loc");
Serial.println("AT+SAPBR=1,1"); //connected to gprs
delay(2000);
Serial.println("AT+CIPGSMLOC=1,1"); //get location from cellular
delay(3000);
read_String(); //get out serial
strtok(inData, ",");
strcpy(longitude,strtok(NULL, ",")); // Gets longitude
strcpy(latitude,strtok(NULL, ",")); // Gets latitude
delay(2000);
Serial.println("AT+SAPBR=0,1"); //disconneted gprs
delay(2000);
}
void show_GPS(){
Serial.println("Show GPS data");
Serial.println("&latitude=");
Serial.println("&latitude=");
Serial.print(latitude);
Serial.print("&longitude=");
Serial.print(longitude);
Serial.println("\"");
delay(2000);
}
void read_String() {
index=0;
while(Serial.available() > 0) // Don't read unless
// there you know there is data
{
if(index < 50) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
}
but the result in serial nothing , before uploading i try with manual at command with connected to serial.
he result from serial.
Start GPRS
AT+SAPBR=3,1,"APN","indosatgprs"
AT+SAPBR=3,1,"Contype","GPRS"
read GSM loc
AT+SAPBR=1,1
AT+CIPGSMLOC=1,1
AT+SAPBR=0,1
Show GPS data
&latitude=
&latitude=
&longitude="
read GSM loc
AT+SAPBR=1,1
AT+CIPGSMLOC=1,1
AT+SAPBR=0,1
Show GPS data
&latitude=
&latitude=
&longitude="
read GSM loc
AT+SAPBR=1,1
AT+CIPGSMLOC=1,1
AT+SAPBR=0,1
Show GPS data
&latitude=
&latitude=
&longitude="
please advice and many thanks