im using arduino uno with sm5100b module.
#include <NewSoftSerial.h>
#include <String.h>
#include <Wstring.h>
#define BUFFSIZE 512
char c='n';
int bytesread = 0;
int val = 0;
char ATBuff[BUFFSIZE];
char szInPut = 0;
NewSoftSerial cell(2,3);
int CELL_REG = 0;
int CELL_AT = 0;
int CELL_SMSMODE = 0;
int nBufPos;
int msg = 0;
char number[12];
char message1[6];
int fog=0;
int fmg=0;
void setup()
{
Serial.begin(9600);
cell.begin(9600);
Serial.println(" ");
Serial.println("Starting Communication...");
;
}
void loop()
{
{
while(CELL_REG == 0 || CELL_AT == 0) {
ATGetResp();
ParseATResp();
}
char incoming_ms[20]=" ";
String buff = String(20);
if(cell.available() >0)
{
bytesread = 0;
while(bytesread=0) {
val = cell.read();
incoming_ms[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
int i=0;
int j=0;
char incoming_let=0;
char incoming_char[200]=" ";
String buff1 = String(200);
cell.println("AT+CMGF=1");
//cell.println("AT+CMGD=1,4");
cell.println("AT+CMGL=\"ALL\"");
delay(450);
if(cell.available() >0)
{
while(cell.available() >0)
{
incoming_let = cell.read();
incoming_char[j]=incoming_let;
j++;
}
}
buff1=incoming_char;
if(c=='n')
{
int l=0;
int flag=0;
int k=0;
for(k=0;buff1[k];k++)
{
if(buff1[k]==',')
{
flag++;
}
if(flag==3)
{
if(!(buff1[k]=='"'||buff1[k]==','))
{
number[l]=buff1[k];
Serial.print(number[l]);
l++;
}
}
c='y';
if(flag==7)
{
while(buff1[k]!='"')
{
k++;
}
k++;
for(l=0;buff1[k]!='\0';l++)
{message1[l]=buff1[k];
Serial.print(message1[l]);
k++;
}
}
}
}
}
}
void ATGetResp() {
char c;
memset(ATBuff, '\0', BUFFSIZE);
nBufPos = 0; // start at begninning
int nBytes = 0;
nBytes = cell.available();
if (nBytes > 0) {
for (int iii = 1; iii <= nBytes; iii++) {
if (nBufPos == BUFFSIZE - 3)
break;
c = cell.read();
if (c == '\r') {
ATBuff[nBufPos] = c;
c = cell.read();
if (c == '\n') {
ATBuff[nBufPos] = '\0';
return;
}
}
ATBuff[nBufPos] = c;
nBufPos++;
}
}
ATBuff[nBufPos] = '\0';
return;
}
void ParseATResp(void) {
if (strstr(ATBuff, "+SIND: 11") != 0) {
CELL_REG = 1;
return;
}
if (strstr(ATBuff, "+SIND: 4") != 0) {
CELL_AT = 1;
return;
}
}
i am having a problem with this code.i am getting result as given below
+CMGL: 1,0,"REC READ","+919845600000","10/12/06,11:12:22+59+00"
Talk na
OK
but when i run with sparkfun example code im getting as given below.
OK
+CMGL: 1,0,"REC READ","+919845600000","10/12/06,11:12:22+00"
Hello
+CMGL: 2,0,"REC READ","+919686210008","10/12/06,11:14:59+00"
Talk na
OK
i need to get +919845600000 and Hello as output.