• No results found

Now you can compile and upload your code supporting highier buffered serial input data. */

N/A
N/A
Protected

Academic year: 2021

Share "Now you can compile and upload your code supporting highier buffered serial input data. */"

Copied!
7
0
0

Loading.... (view fulltext now)

Full text

(1)

/*

SMS_SS - a-gsm 2.064 send/read/list SMS example utility COPYRIGHT (c) 2014 Dragos Iosub / R&D Software Solutions srl

You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH a-gsm DEVICES USAGE. Modifications, derivates and redistribution

of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms

of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.

This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied

warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Dragos Iosub, Bucharest 2014. http://itbrainpower.net

*/

/*

In order to make your Arduino serial communication reliable (especially for Arduino Uno) with a-gsm shield, you must edit:

C:\Program Files\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp

comment the line 42

#define _SS_MAX_RX_BUFF 64

this, will look after that like: //#define _SS_MAX_RX_BUFF 64

and add bellow the next line:

#define _SS_MAX_RX_BUFF 128

You just increased the RX buffer size for UNO and other "snails".

Now you can compile and upload your code supporting highier buffered serial input data. */

//#define atDebug //uncomment this line if you want to catch OK/ERROR/TIMEOUT modem response

//modify the next 2 line to be convenient for you

char message[]="Hi!\r\nThis message has been sent from a-gsm v2.064 Arduino shield connected with my Arduino board."; //no more than 160 chars -text SMS maximum lenght

char destinationNumber[]="+40123456789"; //usually phone number with International prefix eg. +40 for Romania - in some networks you must use domestic numbers

#define powerPIN 7//Arduino Digital pin used to power up / power down the modem //#define resetPIN 6//Arduino Digital pin used to reset the modem

#define statusPIN 5//Arduino Digital pin used to monitor if modem is powered

#define RXSoft 2 //RX soft -used for software communication #define TXSoft 3 //TX soft -used for software communication #include <SoftwareSerial.h>

(2)

int totSMS; } simmSMS;

simmSMS SSMS = {0,0};

int sendSMS(char* phno, char* phtype, char* message);

void readSIMM(void);

void setupMODEMforSMSusage(void);

void listSMSstatus(void);

/*do not change under this line! Insteed, make one copy for playing with.*/

int state=0, i=0, powerState = 0;

char ch;

char buffd[256];

char IMEI[18];

unsigned long offsetTime;

int totalChars = 0;

SoftwareSerial SSerial(RXSoft, TXSoft); //setup software serial for modem communication /*

utility for sending SMS

phno - destination phone number, international format eg.:+40123456789 - char* phtype - destination phone number type 129 (international)/ 147(domestic) - char* message - ...what you want to transmit in your SMS :)) - max. 160 chars - char*

returns 1 for SUCCESS 0 for FAILURE */

int sendSMS(char* phno, char* phtype, char* message){

//...function code here return SUCCESSorFAILURE; }

/*

setupMODEMforSMSusage() -utility to set up the modem for SMS (text mode) usage */

void setupMODEMforSMSusage(){

//...function code here

}

/*

utility for listing SMS (received) from memmory store into SSMS the used/total SMSs

SSMS.noSMS --- used SMS (locations)... if >0, we have something to read :) SSMS.totSMS --- total SMS (locations)

*/

void listSMSstatus(){

//...function code here

}

/*clear buffd preparing it for writing*/

void clearBUFFD(void){//just clear the data buffer memset(buffd, 0x00, sizeof(buffd));

(3)

}

/*send command -cmd to themodem, waiting Delay_mS msecs after that*/ size_t aGsmCMD(char* cmd, int Delay_mS){

//...function code here

}

/*send string -str to the modem, NOT ADDING \r\n to the line end*/ size_t aGsmWRITE(char* str){

//...function code here

}

/*return read char from the modem*/ inline char aGsmREAD(void){

//...function code here

}

/*

Receive data from serial until event: SUCCESS string - 1'st argument

FAILURE string - second argument TIMEOUT - third argument in secconds! return: int

-1 TIMEOUT 0 FAILURE 1 SUCCESS

the string collected from modem => buffd */

int recUARTDATA( char* ok, char* err, int to){

//...function code here return(cmdSuccesCode); }

/*

send AT command, looking for SUCCES STRING(1'st) or FAILURE STRING(second), and TIMEOUT(third) return 1 for succes, 2 for failure, -1 for timeout

modem response is loaded in buffd */

int sendATcommand(char* outstr, char* ok, char* err, int to){

//...function code here

res = recUARTDATA( ok, err, to);

return(res); }

bool TXavailable(){

//...function code here

return(CharsAvailableForRead); }

/* just print debug to Serial*/ void printDebugLN(char* what){

Serial.println(what); }

/*utility that load into IMEI var the modem IMEI*/ void getIMEI(){//AT+GSN

(4)

}

/*Arduino hardware setup utility*/ void setup(){

//...function code here

}

/*here is the main code*/ void loop(){ char someBuffer[161]; int SMSindex = 1; char * pch0; char * pch1; int res; int i; switch(state){

case 0://check modem status, power it if necessary if(!digitalRead(statusPIN)) restartMODEM();

else

state++;

i=0;

res= 0;

while(res != 1){

res = sendATcommand("AT","OK","ERROR",2);

if (res != 1) {

if(i++ >= 10) restartMODEM(); }

delay(500); }

sendATcommand("AT+IPR=19200;&w","OK","ERROR",2);

delay(2000);

break;

case 1://next some init strings... clearBUFFD(); aGsmCMD("AT+QIMODE=0",200); aGsmCMD("AT+QINDI=0",200); aGsmCMD("AT+QIMUX=0",200); aGsmCMD("AT+QIDNSIP=0",200); offsetTime=0; clearBUFFD(); state++; break;

case 2://stop if PIN is requested printDebugLN("try CPIN...");

if(!offsetTime) offsetTime = millis();

if ((millis() - offsetTime) > 20000) restartMODEM();

clearBUFFD(); aGsmCMD("AT+CPIN?",200); i = 0; while(TXavailable()){ ch = aGsmREAD(); buffd[i] = ch; i++;

(5)

} //printDebugLN(buffd); delay(100); if(strstr(buffd,"READY")) { offsetTime=0; state++; printDebugLN("READY"); } else {} clearBUFFD(); clearHDSerial(); delay(100); offsetTime = millis(); state++; break;

case 3: //is the modem registered? getIMEI();//just for fun clearBUFFD();

if(!offsetTime) offsetTime = millis();

if ((millis() - offsetTime) > 30000) restartMODEM();

clearBUFFD();

printDebugLN("Query GSM registration?");

aGsmCMD("AT+CREG?",1000);//GSM network registration i = 0; while(TXavailable()){ ch = aGsmREAD(); buffd[i] = ch; i++; } //printDebugLN(buffd); delay(100); if(strstr(buffd,"0,1")) { offsetTime=0; state++; printDebugLN("Ready"); } else {} clearBUFFD(); clearHDSerial(); offsetTime = millis(); state++; break;

case 4: //it is SIM/MODEM full initialised? clearBUFFD();

printDebugLN("Query State of Initialization");

aGsmCMD("AT+QINISTAT",200); i = 0; while(TXavailable()){ ch = aGsmREAD(); buffd[i] = ch; i++; } if(strstr(buffd,"3")) { offsetTime=0; state++;

printDebugLN("Ready"); delay(100);

} else {printDebugLN("Not yet..."); delay(1000);}

clearBUFFD();

clearHDSerial(); delay(100);

(6)

case 5://Initialize the modem for DTMF receive usage if(!offsetTime) offsetTime = millis();

if ((millis() - offsetTime) > 5000) restartMODEM();

clearBUFFD();

clearHDSerial();

printDebugLN("Let's prepare modem for SMS usage! Wait 10-11 seconds, please!");

setupMODEMforSMSusage();

delay(10000);

offsetTime = millis();

state++;

break;

case 6://let's send one SMS to the destination receipment if(!offsetTime) offsetTime = millis();

if ((millis() - offsetTime) > 5000) restartMODEM();

printDebugLN("Let's send one SMS to the destination receipment!"); delay(100);

//if(sendSMS(destinationNumber,"147",message)==1) printDebugLN("test SMS has been send with succees!");

if(sendSMS(destinationNumber,"129",message) == 1) printDebugLN("test SMS has been send with succees!");

else printDebugLN("SMS send FAILURE");

clearBUFFD(); clearHDSerial(); delay(10000); offsetTime = millis(); state++; break;

case 7://let's read SMSs from active memmory

printDebugLN("Let's find SMS storage usage!"); delay(100);

clearBUFFD(); listSMSstatus(); printDebugLN(buffd); delay(5000); clearBUFFD(); clearHDSerial(); state++; break;

case 8://let's read one SMS

printDebugLN("Let's read one SMS!"); delay(100);

//start READ SMS

SMSindex = 1;//h used as SMS index here we read only first index... h >=1, h<=SMS.totSMS!!!!

clearBUFFD();

sprintf(buffd,"AT+CMGR=%i,0\r",SMSindex);//format the read command ... with SMS status changing(second argument) from REC UNREAD to REC READ

(7)

aGsmWRITE(buffd);//send command to modem

recUARTDATA("OK","ERROR",5);//receive modem's response...in buffd //end read SMS

printDebugLN("Modem response:");

printDebugLN(buffd);//let's see what modem say //let's extract the message

memset(someBuffer,0x00,sizeof(someBuffer));

pch0 = strstr(buffd,"\"\r\n");

pch1 = strstr(buffd,"\r\nOK");

strncpy(someBuffer, pch0+3, pch1-pch0-4);

printDebugLN("List message:");

printDebugLN(someBuffer);//here is the message .... //end extract the message

delay(15000); clearBUFFD(); clearHDSerial(); state++; break; default: //restartMODEM(); delay(10000); state=0; break; } } /*

just flush remaining chars from serial */

void clearHDSerial(){

//..function code here

References

Related documents

After you have evaluated your current payroll software and procedures, it’s time to compile a list of key software capabilities your company will need in a new payroll solution..

After you have evaluated your current payroll software and procedures, it’s time to compile a list of key software capabilities your company will need in a new payroll solution..

In this paper, multi-feature fusion using Scale Invariant Feature Transform (SIFT) and Local Extensive Binary Pattern (LEBP) was proposed to obtain a feature that

Avocados Australia Infocado Wholesaler Instructions March 2010 v1 14 Retrieving Industry Summary Dispatch reports. In the Menu Selection drop list select “View

From materials selection and cable manufacture to cable rating in common deployment situations, along with network constraint and life cycle assessment, the outputs were integrated

Physiological aspects of Corylus avellana associated with the French black truffle fungus Tuber melanosporum and the consequence for commercial production of black truffles in

Este proceso/método puede utilizarse para crear un mortero adhesivo de color para facilitar la instalación de mosaicos de vidrio traslúcido, transparente u opaco, así como de

After you have evaluated your current payroll software and procedures, it’s time to compile a list of key software capabilities your company will need in a new payroll solution..