void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
asm clrwdt
while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
asm clrwdt
GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);
UART1_Write_Text(s8);
Delay_ms(500);
UART1_Write(0x1A);
DelayXSec(6);
}
memset(gsmBuffer, '\0', sizeof(gsmBuffer));
(*idx) = 0;
asm clrwdt
}
sbit sendSmsFlag at myFlags.B0;
char sms[30];
char smsIndex[4];
const char sms1[] = "LED is ON";
const char sms2[] = "LED is OFF";
const char sms3[] = "Invalid Command Received";
case Send_AT: // Send AT and check for AT\r\n\r\n
GSM_Send_Const_Command(GSM_Buffer, buffer1, ATR11, ATC00, \
&gsmBufferIndex, &GSM_Attempt, 0);
char gsmBuffer[270];
char message[50];
char buffer1[50];
char buffer2[50];
char sms[100];
char smsIndex[4];
char value[4];
char str[23];
char lightDelayCode[10];
char temperatureThresholdData[5];
char gsmAttempt = 0;
char port = 0;
unsigned int diff = 0;
unsigned int iTemperature = 0, iPreviousTemperature = 0;
unsigned int iTemperatureThreshold = 0;
unsigned int delayCounter = 0, lightBlinkCounter = 0;
unsigned long lightDelayValue = 0, noOf200MilliSecondsCounter = 0, gsmBufferIndex = 0;
unsigned int addr = 0, val = 0;
unsigned char iEvent = 15;
unsigned int mainsVoltage = 0, prevMainsVoltage = 0;
double fTemperature = 0.0, fPreviousTemperature = 0.0;
//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
//const char atCommand9[] = "AT+CMGS=\"9900516837\"\r";
const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";
const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";
const char secretCode[] = "20!4";
const char secretCode0[] = "20!4#l1"; //to turn lights ON
const char secretCode1[] = "20!4#l0"; //to turn lights OFF
const char secretCode2[] = "20!4#ls"; //to get STATUS of lights
const char secretCode3[] = "20!4#gt"; //to get temperature reading
const char secretCode4[] = "20!4#da"; //to de-activate the alarm
const char secretCode5[] = "20!4#aa"; //to activate the alarm
const char secretCode6[] = "20!4#as"; //to get the STATUS of the alarm
const char secretCode7[] = "20!4#cg"; //to close the electric gate
const char secretCode8[] = "20!4#og"; //to open the electric gate
const char secretCode9[] = "20!4#gs"; //to get the STATUS of the electric gate to see if its OPEN/CLOSED
const char secretCodeA[] = "20!4#ps"; //to get the STATUS of the power supply if its interrupted or not
const char secretCodeB[] = "20!4#rt"; //to get set temperature thtreshold value
const char secretCodeC[] = "20!4#d"; //to set Light On / OFF Delay
const char secretCodeD[] = "20!4#t"; //to set Light On / OFF Delay
const char sms1[] = "Light is ON";
const char sms2[] = "Light is OFF";
const char sms3[] = "Gate is open";
const char sms4[] = "Gate is closed";
const char sms5[] = "Alarm is ON";
const char sms6[] = "Alarm is OFF";
const char sms7[] = "Temperature is high";
const char sms8[] = "Power supply is OK";
const char sms9[] = "Power supply is not OK";
const char smsA[] = "Temperature Threshold is set to ";
const char smsB[] = " degree C";
const char smsC[] = "Temperature is ";
const char smsD[] = "Cannot control Gate. Voltage is not Ok";
const char smsE[] = "Incorrect Code Received";
const char smsF[] = "Light Will Turn ON after ";
const char smsG[] = "Light will turn OFF after ";
const char smsH[] = " minutes";
const char smsI[] = "First time use. ";
const char smsJ[] = " Threshold is not set.";
//Function Prototypes
char *CopyConst2Ram(char *dest, const char *src);
void DelayXSec(unsigned long int sec);
char *CopyConst2Ram(char *dest, const char *src);
void GSM_RESET();
void Extract_SMS(char *s1, char *s2);
void Get_SMS_gsmBufferIndex(char *s1, char *s2);
void Get_GSM_Time(char *s1, char *s2);
void Get_Code(char *s1, char *s2);
void GSM_Send_Const_Command(char *s1, char *s2, const char *s3, const char *s4, unsigned int *idx, char *gsmAttempt, char clr);
void GSM_Get_SMS(char *s1, char *s2, const char *s3, const char *s4, char *s5, unsigned int *idx, char *gsmAttempt, char *s6, char clr);
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr);
#define SEND_AT_COMMAND GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_GSM_BAUDRATE GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand4, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_GSM_TEXT_MODE GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand5, &gsmBufferIndex, &gsmAttempt, 1);
#define SET_SIM_MEMORY_FOR_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand6, &gsmBufferIndex, &gsmAttempt, 1);
#define ENABLE_NEW_SMS_NOTIFICATION GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand7, &gsmBufferIndex, &gsmAttempt, 1);
#define DELETE_ALL_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommandA, &gsmBufferIndex, &gsmAttempt, 1);
#define READ_SMS GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);
#define SEND_SMS Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
const char SMS1[] = "Modem Check.";
const char SMS2[] = "xxxxx Error Detected!";
const char SMS3A[] = "xxxx1 Failure!";
const char SMS3B[] = "xxxx1 Warning!";
const char SMS3C[] = "xxxx1 Alarm!";
const char SMS4A[] = "xxxx2 Failure!";
const char SMS4B[] = "xxxx2 Warning!";
const char SMS4C[] = "xxxx2 Alarm!";
const char Ph1[] = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph2[] = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph3[] = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph4[] = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
const char Ph5[] = "AT+CMGS=\"+960xxxxxxx\"\r\n"; //
char SMS[22];
Some day I wish to write like this...for now I get dizzy.See this.
C:char gsmBuffer[270]; char message[50]; char buffer1[50]; char buffer2[50]; char sms[100]; char smsIndex[4]; char value[4]; char str[23]; char lightDelayCode[10]; char temperatureThresholdData[5]; char gsmAttempt = 0; char port = 0; unsigned int diff = 0; unsigned int iTemperature = 0, iPreviousTemperature = 0; unsigned int iTemperatureThreshold = 0; unsigned int delayCounter = 0, lightBlinkCounter = 0; unsigned long lightDelayValue = 0, noOf200MilliSecondsCounter = 0, gsmBufferIndex = 0; unsigned int addr = 0, val = 0; unsigned char iEvent = 15; unsigned int mainsVoltage = 0, prevMainsVoltage = 0; double fTemperature = 0.0, fPreviousTemperature = 0.0; //GSM Constant Strings const char atCommand1[] = "AT\r"; const char atCommand2[] = "ATE0\r"; const char atCommand3[] = "ATE1\r"; const char atCommand4[] = "AT+IPR=9600\r"; const char atCommand5[] = "AT+CMGF=1\r"; const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r"; const char atCommand7[] = "AT+CNMI=2,1\r"; const char atCommand8[] = "AT+CMGR="; //const char atCommand9[] = "AT+CMGS=\"9900516837\"\r"; const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r"; const char atCommandA[] = "AT+CMGD=1,4\r"; const char atResponse1[] = "\r\nOK\r\n"; const char atResponse2[] = "ERROR"; const char atResponse3[] = "+CMTI: \"SM\","; const char atResponse4[] = "> "; const char atResponse5[] = "RING"; const char atResponse6[] = "NO CARRIER"; const char atResponse7[] = "NO ANSWER"; const char atResponse8[] = "+CFUN: 1"; const char atResponse9[] = "+CPIN: READY"; const char secretCode[] = "20!4"; const char secretCode0[] = "20!4#l1"; //to turn lights ON const char secretCode1[] = "20!4#l0"; //to turn lights OFF const char secretCode2[] = "20!4#ls"; //to get STATUS of lights const char secretCode3[] = "20!4#gt"; //to get temperature reading const char secretCode4[] = "20!4#da"; //to de-activate the alarm const char secretCode5[] = "20!4#aa"; //to activate the alarm const char secretCode6[] = "20!4#as"; //to get the STATUS of the alarm const char secretCode7[] = "20!4#cg"; //to close the electric gate const char secretCode8[] = "20!4#og"; //to open the electric gate const char secretCode9[] = "20!4#gs"; //to get the STATUS of the electric gate to see if its OPEN/CLOSED const char secretCodeA[] = "20!4#ps"; //to get the STATUS of the power supply if its interrupted or not const char secretCodeB[] = "20!4#rt"; //to get set temperature thtreshold value const char secretCodeC[] = "20!4#d"; //to set Light On / OFF Delay const char secretCodeD[] = "20!4#t"; //to set Light On / OFF Delay const char sms1[] = "Light is ON"; const char sms2[] = "Light is OFF"; const char sms3[] = "Gate is open"; const char sms4[] = "Gate is closed"; const char sms5[] = "Alarm is ON"; const char sms6[] = "Alarm is OFF"; const char sms7[] = "Temperature is high"; const char sms8[] = "Power supply is OK"; const char sms9[] = "Power supply is not OK"; const char smsA[] = "Temperature Threshold is set to "; const char smsB[] = " degree C"; const char smsC[] = "Temperature is "; const char smsD[] = "Cannot control Gate. Voltage is not Ok"; const char smsE[] = "Incorrect Code Received"; const char smsF[] = "Light Will Turn ON after "; const char smsG[] = "Light will turn OFF after "; const char smsH[] = " minutes"; const char smsI[] = "First time use. "; const char smsJ[] = " Threshold is not set."; //Function Prototypes char *CopyConst2Ram(char *dest, const char *src); void DelayXSec(unsigned long int sec); char *CopyConst2Ram(char *dest, const char *src); void GSM_RESET(); void Extract_SMS(char *s1, char *s2); void Get_SMS_gsmBufferIndex(char *s1, char *s2); void Get_GSM_Time(char *s1, char *s2); void Get_Code(char *s1, char *s2); void GSM_Send_Const_Command(char *s1, char *s2, const char *s3, const char *s4, unsigned int *idx, char *gsmAttempt, char clr); void GSM_Get_SMS(char *s1, char *s2, const char *s3, const char *s4, char *s5, unsigned int *idx, char *gsmAttempt, char *s6, char clr); void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr); #define SEND_AT_COMMAND GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1); #define SET_GSM_BAUDRATE GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand4, &gsmBufferIndex, &gsmAttempt, 1); #define SET_GSM_TEXT_MODE GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand5, &gsmBufferIndex, &gsmAttempt, 1); #define SET_SIM_MEMORY_FOR_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand6, &gsmBufferIndex, &gsmAttempt, 1); #define ENABLE_NEW_SMS_NOTIFICATION GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand7, &gsmBufferIndex, &gsmAttempt, 1); #define DELETE_ALL_SMS GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommandA, &gsmBufferIndex, &gsmAttempt, 1); #define READ_SMS GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1); #define SEND_SMS Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
//const char atCommand9[] = "AT+CMGS=\"9900516837\"\r";
const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";
const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
asm clrwdt
while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
asm clrwdt
GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);
UART1_Write_Text(s8);
Delay_ms(500);
UART1_Write(0x1A);
DelayXSec(6);
}
memset(gsmBuffer, '\0', sizeof(gsmBuffer));
(*idx) = 0;
asm clrwdt
}
GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);
UART1_Write_Text(s8);
Delay_ms(500);
UART1_Write(0x1A);
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, const char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
asm clrwdt
while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
asm clrwdt
GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);
UART1_Write_Text(CopyConst2Ram(s2, s8));
Delay_ms(500);
UART1_Write(0x1A);
DelayXSec(6);
}
memset(gsmBuffer, '\0', sizeof(gsmBuffer));
(*idx) = 0;
asm clrwdt
}
You can if you useSome day I wish to write like this...for now I get dizzy.
void GSM_Get_SMS(char *s1, char *s2, const char *s3, const char *s4, char *s5, unsigned int *idx, char *gsmAttempt, char *s6, char clr) {
CLEAR_WATCH_DOG_TIMER
while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
CopyConst2Ram(s2, s4);
CLEAR_WATCH_DOG_TIMER
strcat(s2, s5);
strcat(s2, "\r");
UART1_Write_Text(s2);
CLEAR_WATCH_DOG_TIMER
DelayXSec(2);
CLEAR_WATCH_DOG_TIMER
if((*gsmAttempt)++ == 3) {
GSM_RESET() ;
CLEAR_WATCH_DOG_TIMER
(*gsmAttempt) = 0;
(*idx) = 0;
memset(gsmBuffer, '\0', sizeof(gsmBuffer));
}
}
(*idx) = 0;
Extract_SMS(s1, s6);
CLEAR_WATCH_DOG_TIMER
if(clr)memset(gsmBuffer, '\0', sizeof(gsmBuffer));
CLEAR_WATCH_DOG_TIMER
}
GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);
//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
const char atCommand9[] = "AT+CMGS=\"+27000038668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";
const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";
char gsmBuffer[270];
char message[50];
char buffer1[50];
char buffer2[50];
char sms[100];
char smsIndex[4];
char value[4];
char str[23];
char gsmAttempt = 0;
GSM_Get_SMS(gsmBuffer, buffer1, atResponse1, atCommand8, smsIndex, &gsmBufferIndex, &gsmAttempt, sms, 1);
| Thread starter | Similar threads | Forum | Replies | Date |
|---|---|---|---|---|
| T | RS232 to TTL custom board, no output from MAX232 | General Electronics Chat | 25 | |
| O | MAX232 for ±25V from 5V supply | General Electronics Chat | 35 | |
| T | Max232 capacitor placing issues | Microcontrollers | 11 | |
|
|
MAX232 Heating issue..! | General Electronics Chat | 23 | |
|
|
Question about serial comms between a pic and a pc using a max232 | Microcontrollers | 11 |