I wrote a code for arduino uno, so that it collects data from the GPS sensor and sends it to the server via GET method via the GPRS shield. Here is the code:
#include <GPRS_Shield_Arduino.h>
#include <TroykaGPS.h>
#include <SoftwareSerial.h>
#define IMEI "861508038977104"
#define INTERVAL 60000
#define LEN 370
char time[16];
char date[16];
char tcpBuffer[370];
char buf[16];//time buffer
unsigned long previousMillis = 0;
SoftwareSerial gprsStream(10, 11);
SoftwareSerial gpsStream(4, 5);
GPS gps(gpsStream);
GPRS gprs(gprsStream);
void setup(){
Serial.begin(9600);
while(!Serial){}
Serial.println("Serial opened on 9600");
delay(100);
gpsStream.begin(115200);
Serial.println("gpsStream opened on 115200");
gpsStream.write("$PMTK251,9600*17\r\n");
Serial.println("gpsStream changed to 9600");
gpsStream.end();
Serial.println("gpsStream closed");
}
void loop(){
gprsStream.begin(9600);
Serial.println("gprsStream opened on 9600");
gprs.powerOn();
gprs.getDateTime(buf);
Serial.print("time on gprs: ");
Serial.println(buf);
gprs.powerOff();
gprsStream.end();
Serial.println("gprsSerial closed");
gpsStream.begin(9600);
Serial.println("gpsStream opened on 9600");
if(gps.available()){
gps.readParsing();
switch(gps.getState()){
case GPS_OK:
gps.getTime(time, 16);
gps.getDate(date, 16);
sprintf(tcpBuffer, "GET /recvdata.php?%s_%s.txt&data=%s_%s_%s_%f_%f HTTP/1.0\r\n\r\n", date, time, IMEI, date, time, gps.getLatitudeBase10(), gps.getLongitudeBase10());
Serial.print("formed: ");
Serial.print(tcpBuffer);
break;
case GPS_ERROR_DATA:
sprintf(tcpBuffer, "GET /recvdata.php?filename=%s_err.txt&data=ERROR_DATA_%s_%s HTTP/1.0\r\n\r\n", buf, buf, IMEI);
Serial.print("formed: ");
Serial.println(tcpBuffer);
break;
case GPS_ERROR_SAT:
sprintf(tcpBuffer, "GET /recvdata.php?filename=%s_err.txt&data=ERROR_SAT_%s_%s HTTP/1.0\r\n\r\n", buf, buf, IMEI);
Serial.print("formed: ");
Serial.println(tcpBuffer);
break;
}
}
else{
Serial.println("GPS not available");
return;
}
gpsStream.end();
Serial.println("gpsStream closed");
gprsStream.begin(9600);
Serial.println("gprsStream opened on 9600");
gprs.powerOn();
while(!gprs.init()){
Serial.println("GPRS init error");
delay(500);
}
Serial.println("GPRS init success");
delay(3000);
while(!gprs.join("internet.beeline.ru", "beeline", "beeline")){
Serial.println("GPRS error joining network");
delay(1000);
}
Serial.println("GPRS connected to the network");
Serial.print("IP address is ");
Serial.println(gprs.getIPAddress());
while(!gprs.connect(TCP, "188.44.53.81", 80)){
Serial.println("GPRS could not connect to the internet");
delay(1000);
}
Serial.println("GPRS connected to the internet");
gprs.send(tcpBuffer);
clearTcpBuffer();
gprs.close();
gprs.disconnect();
delay(100);
Serial.println("Buffer sent");
gprs.powerOff();
gprsStream.end();
Serial.println("gprsStream closed");
Serial.println("waiting...");
while(millis() - previousMillis < INTERVAL){
}
previousMillis = millis();
}
void clearTcpBuffer(){
for(int i = 0; i < 370; i++){
tcpBuffer[i] = 0;
}
}
This code does not give any output on the hardware Serial port. The parts for GPS and GPRS shield work perfectly separately