Here is my coding;
My coding is successfully send data to thinspeak using GSM but it send cordinate 0 0 because the code for GPS not running
What i notice that my coding GPS did not running ss.begin(9600) i dont know why ss.println("Gps read"); and Serial.println("GPS start"); did not print on serial moitor
here is my code
#include <SoftwareSerial.h>
#include <String.h>
#include <TinyGPS++.h>
const int rxPin = 4;
const int txPin = 3;
TinyGPSPlus gps;
SoftwareSerial ss(rxPin, txPin);
SoftwareSerial gprsSerial(9,10);
//const int gsmrxPin = 9;
//const int gsmtxPin = 10;
float MyValue1, MyValue2;
void setup()
{
Serial.begin(9600); // the GPRS baud rate
ss.begin(9600);
Serial.println("GPS start");
delay(1000);
gprsSerial.begin(9600); // the GPRS baud rate
Serial.println("GSM start");
delay(1000);
}
void loop()
{
ss.println("Gps read");
while (ss.available() > 0) {
if (gps.encode(ss.read())) {
// If so, display the current GPS coordinates
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
// Save the coordinates to variables
float myvalue1 = gps.location.lng();
float myvalue2 = gps.location.lat();
}
}
gprsSerial.println("GsM read");
if (gprsSerial.available())
Serial.write(gprsSerial.read());
gprsSerial.println("AT");
delay(1000);
gprsSerial.println("AT+CPIN?");
delay(1000);
gprsSerial.println("AT+CREG?");
delay(1000);
gprsSerial.println("AT+CGATT?");
delay(1000);
gprsSerial.println("AT+CIPSHUT");
delay(1000);
gprsSerial.println("AT+CIPSTATUS");
delay(2000);
gprsSerial.println("AT+CIPMUX=0");
delay(2000);
ShowSerialData();
gprsSerial.println("AT+CSTT=\"airtelgprs.com\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
gprsSerial.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
gprsSerial.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
gprsSerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
delay(6000);
ShowSerialData();
gprsSerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String str="GET https://api.thingspeak.com/update?api_key=XOY6CRHBEIH04QCM&field1=0"+ String(MyValue1) +"&field2="+String(MyValue2);
Serial.println(str);
gprsSerial.println(str);//begin send data to remote server
delay(4000);
ShowSerialData();
gprsSerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
gprsSerial.println();
ShowSerialData();
gprsSerial.println("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}
void ShowSerialData()
{
while(gprsSerial.available()!=0)
Serial.write(gprsSerial.read());
delay(5000);
}
and here is my serial monitor
I working this troubleshooting this code almost a week find in the internet to solve the problem. I am really grateful if you guys can help. And sorry about my bad English grammar