I had build a program that run ceratin AT comands to GSM module through software serial library.I am using 2 software serial as i need to keep hardware serial vaccant for debugging.
i had ceratin question
i) Some time when everything works fine..means both sofwtare serial work fine(1 for GPRS and 1 for GPS) and i remove USB cable from Arduyino Duemilanove, everything stop working(means software serial stop sending data) and as i plug the cable again, they start sending data again.I don't know why this is happening.
ii) Secondly, setup function in my code is not getting executed.Sketch directly start from the void loop function and that is causing me troble.I had searched a lot about it, but maximum i can get is , it is due to declaring too many global variables outside set-up.
Here is my code for getting GPRS coordinates and pusghing themover to a HTTP server.
#include <stdio.h>
#include <SoftwareSerial.h>
#define DATABUFFERSIZE 100
const int ledPin = 13;
char dataBuffer[DATABUFFERSIZE+1];
char startChar = '
i used GprsSerial.listen();, so that i can listen what GPRS is reverting and send it across to serial for debugging purpose.I dont know wether it right or wrong.But i need to get the response from server so as to debug whether i am able to send data to server or not.
;
char endChar = '\n';
boolean storeString = false;
SoftwareSerial BTSerial(10, 11);
SoftwareSerial GprsSerial(7, 8);
char *a, *b, *c, *d, *e,*f,*g,*h,*i,*j;
void setup()
{
Serial.begin(9600);
GprsSerial.begin(9600);
GprsSerial.listen();
GprsSerial.println("AT+CGATT?"); // attach or detach from GPRS service //if = 1, that means GPRS service is active over SIm and 0 means not.
toSerial();
//GprsSerial.flush();
//Serial.flush();
GprsSerial.println("AT+SAPBR=3,1,"CONTYPE","GPRS""); // bearer settings
toSerial();
GprsSerial.println("AT+SAPBR=3,1,"APN","rcomnet""); //here rcomnet is the APN name for reliance in Delhi, you have to change it to the APNname for your provider
toSerial();
GprsSerial.println("AT+SAPBR=1,1");
toSerial();
BTSerial.begin(9600);
}
void loop(){
if(getSoftwareSerialstring()){
//GprsSerial.println(dataBuffer);
if(strstr(dataBuffer,"$GPGGA")){
Serial.println(dataBuffer);
char FinalDatatobeSend[500];
char *a, *b, *c, *d, *e,*f,*g,*h,*i,*j;
a = strtok(dataBuffer,",");
b = strtok(NULL,",");
c = strtok(NULL,",");
d = strtok(NULL,",");
e = strtok(NULL,",");
f = strtok(NULL,",");
g = strtok(NULL,",");
h = strtok(NULL,",");
i = strtok(NULL,",");
j = strtok(NULL,",");
GprsSerial.listen();
char *URLdatatobeSend="AT+HTTPPARA="URL","http://requestb.in/mzqsddmz?id=1&latitude=%s&latDir=%s&longitude=%s&lonDir=%s&&altitude=%s\"";
sprintf(FinalDatatobeSend,URLdatatobeSend,c,d,e,f,i);
// initialize http service
GprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
GprsSerial.println("AT+HTTPPARA="CID",1");
delay(1000);
GprsSerial.println(FinalDatatobeSend); //string embedded with sensor value
delay(1000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
GprsSerial.println("AT+HTTPACTION=1");
delay(2000);
toSerial();
// read server response
GprsSerial.println("AT+HTTPREAD");
delay(1000);
toSerial();
GprsSerial.println("");
GprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300);
GprsSerial.println("");
delay(1000);
toSerial();
BTSerial.listen();
}
}
}
void toSerial()
{
while(GprsSerial.available()!=0)
{
Serial.write(GprsSerial.read());
}
}
boolean getSoftwareSerialstring(){
static byte dataBufferIndex = 0;
while(BTSerial.available()>0){
char incomingByte = BTSerial.read();
if(incomingByte ==startChar){
dataBufferIndex = 0;
storeString =true;
}
if(storeString){
if(dataBufferIndex == DATABUFFERSIZE){
dataBufferIndex = 0;
break;
}
if(incomingByte==endChar){
dataBuffer[dataBufferIndex] = 0;
return true;
}
else{
dataBuffer[dataBufferIndex++]=incomingByte;
dataBuffer[dataBufferIndex] = 0;
}
}
else{
}
}
return false;
}
i used GprsSerial.listen();, so that i can listen what GPRS is reverting and send it across to serial for debugging purpose.I dont know wether it right or wrong.But i need to get the response from server so as to debug whether i am able to send data to server or not.