printing idx is a very good idea. I tried that and it does increment like it should.
I get the following Arduino output and the server transmitted "VektorTek 0.1".
this is idx 1
this is serialData
this is idx 2
this is serialData
Vthis is idx 3
this is serialData
ethis is idx 4
this is serialData
kthis is idx 5
this is serialData
tthis is idx 6
this is serialData
othis is idx 7
this is serialData
rthis is idx 8
this is serialData
Tthis is idx 9
this is serialData
ethis is idx 10
this is serialData
kthis is idx 11
this is serialData
this is idx 12
this is serialData
0this is idx 13
this is serialData
.this is idx 14
this is serialData
1this is idx 15
this is serialData
this is idx 16
this is serialData
Here is the entire code, it requires some explanation though. It is a bread board Arduino running 8mhz internal with a 32.768 crystal which increments the timer variable every 8 seconds.
#include <SoftwareSerial.h> //used for the GPS port 5 which is GPS TX
SoftwareSerial mySerial(5, 2); // RX, TX MAKE SURE TO CHANGE THE TX PORT FOR PRODUCTION
int timer = 0;
SIGNAL(TIMER2_OVF_vect){
timer++;
}
char serialData[100];
char inByte;
int i = 0;
int idx = 0;
boolean reply = false;
char hello[10] = "hello";
boolean check = false;
boolean reg = false;
int test;
boolean IP = false;
boolean banner = false;
void setup(){
mySerial.begin(9600);
delay(2000);
mySerial.println("testing the port");
Serial.begin(9600);
pinMode(A2, OUTPUT);
digitalWrite(A2, LOW); // needs to be LOW to be on, HIGH is off
delay(2000);
pinMode(A0, OUTPUT);
digitalWrite(A0, LOW); // needs to be LOW for 3 seconds to turn on the GSM modem
delay(2000); //
pinMode(A0, INPUT);
digitalWrite(A0, HIGH);
delay(3000); //wait for the GSM modem to fully wake up before sending any commands.
mySerial.println("testing the port2");
}
void loop(){
signal();
if (IP == true){
socket();
}
delay(15000); //delay to keep it from looping quickly
//
}
void socket(){
banner = false;
idx = 0;
timer = 0;
Serial.println("AT#SKTD=0,4444,46.102.168.139"); //open the socket connection to the server
mySerial.println("AT#SKTD=0,4444,46.102.168.139");
delay(1000);
while (banner == false && timer < 10){
while (Serial.available() > 0){
inByte = Serial.read();
serialData[idx] = inByte;
serialData[idx+1] = '\0';
idx++;
mySerial.print(inByte);
mySerial.print("this is idx ");
mySerial.println(idx);
mySerial.print("this is serialData ");
mySerial.println(serialData);
if (inByte == 10){
idx = 0;
mySerial.println("got an LF and checking to see if the string matches");
mySerial.println(serialData);
if (strncmp(serialData, "CONNECT", 6) ==0){
mySerial.println("CONNECT matched");
delay(3000);
Serial.println("0123456789");
mySerial.println("0123456789");
//banner = true;
//delay(2000);
}
if (strncmp(serialData, "Option:", 6) ==0){
Serial.println("option matched");
}
}
}
}
}
void signal(){
delay(500);
Serial.println("AT");
delay(1000);
Serial.println("ATE0"); //disable echo
delay(1000);
Serial.println("AT#SIMDET=1"); //turn on the SIM card
mySerial.println("AT#SIMDET=1");
// delay(2000);
// Serial.println("AT\\Q0"); //disable flow control
// mySerial.println("AT\\Q0");
delay(2000);
Serial.println("AT+CMGF=1");
mySerial.println("AT+CMGF=1");
delay(17000); //delay to allow time for network registration
Serial.println("AT+CGDCONT=1,IP,vfinternet.au");
mySerial.println("AT+CGDCONT=1,IP,vfinternet.au");
delay(2000);
Serial.println("AT\\Q0");
mySerial.println("AT\\Q0");
delay(2000);
Serial.println("AT#GPRS=1"); //open a GPRS connection and get an IP
mySerial.println("AT#GPRS=1");
timer = 0;
idx = 0;
IP = false;
while (IP == false && timer < 2){
while (Serial.available() > 0){
inByte = Serial.read();
serialData[idx] = inByte;
serialData[idx+1] = '\0';
idx++;
mySerial.write(inByte);
//mySerial.print(serialData);
if (inByte == 10){
idx = 0;
mySerial.println("got an LF and checking to see if the string matches");
mySerial.println(serialData);
mySerial.println(test);
if (strncmp(serialData, "+IP: ", 4) ==0){
mySerial.println("+IP matched");
IP = true;
delay(2000);
}
}
}
}
}