This article describes the AT commands for reading, sending and deleting SMS from the SIM900 GSM modem inbox. Before you send any SMS or CALL command to the SIM900 modem via the UART interface after power up, wait for the CALL READY message from the SIM900.
The CALL READY message from the SIM900 indicates that the modem is powered up and has acquired a valid network. Next thing is to make sure you have set the SIM900 into TEXT mode by sending the command AT+CMGF=1; followed by a carriage return(rn).
If you are facing any problem with respect to modem not responding to commands read my previous article to solve it.. it applies to SIM900 problems too.
Reading a SMS message from the Inbox:
- To read the first SMS from the inbox send the command AT+CMGR=1 followed by rn. The modem will reply with the text of the first SMS in the inbox along with senders mobile number and date and time.
- To read the second SMS from the inbox send the command AT+CMGR=2 followed by rn. The modem will reply with the text of the second SMS in the inbox along with senders mobile number and date and time.
... and so on. The maximum number of SMS messages in the inbox depends on the SIMCARD you have put in the modem.
- To read all the SMS messages from the inbox send the command AT+CMGL=ALL followed by rn. The modem will reply with the text, senders number, timestamp of the all the messages in the inbox in one shot.
Sim800l Delete All Sms
Sending SMS message from SIM900:
- To send SMS from SIM900 send the command AT+CMGS=9900243245 followed by /r/n and then the message text and then the ascii code of Ctrl^Z character which is 0x1A
ex: To send 'Hello' to 9900243245 mobile number
AT+CMGS=9900243245 followed by rn
Hello
Ctrl^Z ascii code 0x1A followed by rn (Ascii code for n is 0x0A and Ascii code for r is 0x0D)
Deleting a SMS message from the Inbox:
- To delete the first message from the inbox send the command AT+CMGD=1 followed by rn. The modem will delete the first message in the inbox.
- To delete the second message from the inbox send the command AT+CMGD=2 followed by rn. The modem will delete the second message in the inbox.
... and so on. The maximum number of messages in the inbox depends on the SIMCARD you have put in the modem.
Calling to a number using SIM900:
- To call to a number send the command ATD followed by the mobile number and carriage return ,
To call the mobile number 9900243245 send the command as,
ATD9900243245 rn
Hanging up a call in SIM900:
- To hang up a ringing call or a call in progress send the command ATH; followed by carriage return
ATHrn
Recieving a call in SIM900:
- To receive a ringing call, Send the command ATA; followed by carriage return
ATArn
Finding the number of the incoming call in SIM900:
- To get the number of the incoming call you need to enable the Caller Line Identification in SIM900.
- To enable the incoming caller line identification issue the command AT+CLIP=1 followed by carriage return
AT+CLIP=1rn
Once you issue this command, any incoming call will be notified in the following format,
RING
+CLIP:+9916258273
Here +9916259273 is the number of the incoming call.
Click on below Image to Watch the video for Live demonstration of the above commands:
View the discussion thread.
Hi All,It is about time I updated the SMS code I posted a long time ago.
OLD Post:
http://www.ccsinfo.com/forum/viewtopic.php?t=42527
This new 'Driver' ... yeah, lets call it that... is cleaner IMO and easier to adapt to what the next user would want, I hope.
The main update is in how the 'commands' are searched/found.
I got smart and used the <strings.h> library which for some reason I did not use in my previous code.
The Sample program is VERY verbose using PCM's Flex_LCD driver.
Thanks PCM!
As is, the sample program responds to 3 commands: 'Luz1', 'Luz2' & 'Aire'.
(spanish for Light1, Light2, and Airconditioning)
The only action taken by the code is to display a message on the LCD.
The Exception is 'Luz2' which aditionally, replys back with an SMS to a SET & and PREDEFINED Number... See SEND_SMS();
ALL of the Experienced Programmers here will probably point out that my Function names should NOT be in ALL CAPS... I KNOW... Sorry.
I included a Pre-Paid Card recharge function.. however this will probably vary for your country...can't help you there...
however to USE this function you will need to write a small program that runs the function once..... i can't do everything...
Test Conditions:
Quote: |
MODEM: ENFORA 1218 PIC: 16F886 @20MHz / 5V BAUD: 115.2 COM: RS-232 / MAX232 Chip LCD:16x2 + Flex_LCD driver (available in library) COMPILED: PCM 4.135 - MPLAB 8.85 |
FAQ:
Q: How much support can I expect on this code?
A:
Q: Is it Flawless and Awesome?
A: Awesome Yes! Flawless...you tell me.
... im kidding, ill try to help in what I can.
UPDATE: 06/05/2013
Forum user EZFLYR noted the 'New Message Indicator' was missing.
He also noted that most modules Default with this feature OFF.
A new Function SET_CNMI() has been added to correct this.
'AWESOME SMS DRIVER': (That word you keep using....)
Code: |
//****************************************************************************** // GSM/SMS CONTROL 'Driver' //****************************************************************************** // AUTHOR: GABRIEL BARRIOS // DATE: 29/04/2013 // Panama, Rep. Panama. //______________________________________________________________________________ // // This 'Driver' contains the _basic_ functions required to succesfully control // 'something' via SMS. // The included delay function waits for a character or times out. // Ive included a function to recharge credit to a prepaid sim. // Also included is a reply to sms function. // // YOU NEED TO CLEARLY UNDERSTAND HOW TO ADD NEW COMMANDS // There are 3 example commands - I use defines as 'pointers' to the commands // // UPDATE: 06/05/2013 // Forum user EZFLYR noted the 'New Message Indicator' was missing. // He also noted that most modules Default with this feature OFF. // A new Function SET_CNMI() has been added to correct this. //______________________________________________________________________________ //****************************************************************************** //****************************************************************************** // These defines are for code readability purposes. They must match EXACTLY with: // Strings[][] + SIZE_COMMAND + TOTAL_STRINGS + GET_SMS_COMMAND() // Makes it a whole lot easier to add new ones. // I have arbitrarily set the max command length to 10 chars, including '0'. // This can be changed with the defines below. //****************************************************************************** // (See TOTAL_STRINGS BELOW) #DEFINE OK 0 // 1 <-- Required #DEFINE CMTI 1 // 2 <-- Required #DEFINE ERROR 2 // 3 <-- Required #DEFINE EXITO 3 // 4 <-- Untested #DEFINE AIRE 4 // 5 <-- USER DEFINED #DEFINE LUZ1 5 // 6 <-- USER DEFINED #DEFINE LUZ2 6 // 7 <-- USER DEFINED #DEFINE SIZE_COMMAND 10 // Sets the Max command Length including '0' #DEFINE TOTAL_STRINGS 7 // Total number of Searchable strings #DEFINE SIZE_BUFFER 80 // Serial Buffer Size #DEFINE NULL '0' // Easier to type than '0' //______________________________________________________________________________ //****************************************************************************** // FUNCTION DECLARATIONS //****************************************************************************** #INT_RDA void SerialInt(); // Serial ISR used int1 CHECK_COM(); // Checks Modem comms are OK int1 SET_PDU(); // Sets modem to TXT MODE int1 SET_MEM(); // Sets the Prefered Message Storage int1 SET_CNMI(); int1 DEL_SMS(int); // Deletes SMS form memory int1 READ_SMS(int); // Loads SMS onto buffer int1 RECHARGE_ACCOUNT(); // If using Pre_Paid cards *Might* vary depending on country int1 STRING_SEARCH(int); // Searchs for strings or commands int1 DELAY(int); // Delay with Limit int GET_SMS_COMMAND(); // Similar to string_search but 'simpler' and for user level. void CMD_LOAD(int); // Loads commands to a temp buffer from main 'Strings' data base void SEND_SMS(); // Sends an SMS // These are helpfull to have around void CLEAR_BUFFER(); // Clears the serial buffer void PRINT_BUFFER(); // Just a serial buffer Print //______________________________________________________________________________ //****************************************************************************** // MAIN STRINGS or COMMANDS ARRAY and TEMPORARY COMMAND STORAGE //****************************************************************************** // It is _IMPERATIVE_ that these match the define statements at the top // // (SEE DEFINES AT TOP) const char Strings[TOTAL_STRINGS][SIZE_COMMAND]={ 'OK0', // index 0 '+CMTI0', // index 1 'ERROR0', // index 2 'Exitosa0', // index 3 'Aire0', // index 4 'Luz10', // index 5 'Luz20'}; // index 6 char Command[SIZE_COMMAND]; // Temp command buffer char Receive_String[SIZE_BUFFER]; // Serial Buffer int counter_read = 0x00; // Serial Buffer Counter //______________________________________________________________________________ //****************************************************************************** // HAVE *ALL* THE CODES!!! //****************************************************************************** // (It's a meme reference) //______________________________________________________________________________ // // CHECKS COMMS WITH MODEM int1 CHECK_COM() { counter_read=0; // Reset buffer counter printf('ATr'); // Send Attention Command DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter return(STRING_SEARCH(OK)); // Check for OK response } //______________________________________________________________________________ // // SET MODEM TO TXT MODE int1 SET_PDU() { counter_read=0; // Reset buffer counter printf('AT+CMGF=1r'); // Set modem to TXT mode DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter return(STRING_SEARCH(OK)); // Check for OK response } //______________________________________________________________________________ // // SET MESSAGE STORAGE int1 SET_MEM() { counter_read=0; // Reset buffer counter printf('AT+CPMS='SM','SM','SM'r'); // Store in SIM Card DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter return(STRING_SEARCH(OK)); // Check for OK response } //______________________________________________________________________________ // // SET NEW SMS ALERT MSG int1 SET_CNMI() { counter_read=0; // Reset buffer counter printf('AT+CNMI=2,1,2,0,0r'); //text part of the command. DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter return(STRING_SEARCH(OK)); // Check for OK response } //______________________________________________________________________________ // // DIALS PREPAID CARDS int1 RECHARGE_ACCOUNT() { counter_read=0; // Reset buffer counter // Card # // // |--------------| // printf('ATD*166*5096294738864525#I;r'); // Dial carrier with prepaid card# DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter return(STRING_SEARCH(EXITO)); } //______________________________________________________________________________ // // LOADS SMS INTO BUFFER int1 READ_SMS(int index) // index' is the memory address/location { counter_read=0; // Reset buffer counter printf('AT+CMGR=%dr',index); // Send Read SMS command DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter if(STRING_SEARCH(OK)) // Check for OK response return(1); // OR if(STRING_SEARCH(ERROR)) // Check for ERROR response return(0); } //______________________________________________________________________________ // // DELETES SMS FROM MODEM int1 DEL_SMS(int index) // index' is the memory address/location { counter_read=0; // Reset buffer counter printf('AT+CMGD=%dr',index); // Send Delete SMS command DELAY(5); // Delay a maximum of X seconds counter_read=0; // Reset buffer counter if(STRING_SEARCH(OK)) // Check for OK response return(1); // OR if(STRING_SEARCH(ERROR)) // Check for ERROR response return(0); } //______________________________________________________________________________ // // SEND SMS void SEND_SMS() { counter_read=0; printf('AT+CMGS='########'r'); // send command and cel # delay_ms(1000); // Delay long enough for modem response printf('LORD JESUS ITS A FIRE!!!nr'); // Text to reply putchar(0x1A); // send Ctrl-z DELAY(20); // Delay a maximum of X seconds } //______________________________________________________________________________ // // SEARCHES FOR A SPECIFIC STRING IN BUFFER int1 STRING_SEARCH(int index) // index' is Strings[index][SIZE_COMMAND] { // See defines at top. CMD_LOAD(index); // Loads into temp array the string to be found if(STRSTR(Receive_String,Command)!=NULL) // Find String or Command in main Buffer return(1); // Return 1 if found else return(0); // Return 0 if not found. } //______________________________________________________________________________ // // LOADS TO TEMP ARRAY THE SEARCHABLE STRING void CMD_LOAD(int index) { int var=0; // temp index for array memset(Command,NULL,SIZE_COMMAND); // Reset data array index while((Strings[index][var]!=NULL)&&(var<SIZE_COMMAND)) // Copy data from main 'Strings' to commparing array. { Command[var]=Strings[index][var]; // Copy into temp array the strings from Main Database var++; // Up index } } //______________________________________________________________________________ // // SEARCHES TRHOUGH ALL POSSIBLE COMMANDS int GET_SMS_COMMAND() { if(STRING_SEARCH(AIRE)1)return(AIRE); // Using string_search() goes through else // all user defined commands. if(STRING_SEARCH(LUZ1)1)return(LUZ1); else if(STRING_SEARCH(LUZ2)1)return(LUZ2); else return(0); // returns zero if nothing found } //______________________________________________________________________________ // // PRINT SERIAL BUFFER void PRINT_BUFFER() { int var=0; // Temp data array index while(var<SIZE_BUFFER) // print all data array { Printf('%c-%u, ',Receive_String[var],var); // pring in ASCII content and index var++; // Up index } Printf('rn'); // Send return & new line } //______________________________________________________________________________ // // CLEAR SERIAL BUFFER void CLEAR_BUFFER() { memset(Receive_String,NULL,SIZE_BUFFER); // Set all elements to NULL counter_read=0; // Reset index } //______________________________________________________________________________ // // LIMITED DELAY int1 DELAY(int Delay_ctr) { counter_read=0; // Reset buffer counter while((counter_read0)&&(Delay_ctr>0)) // stay here until modem responds (X Seconds is arbitrary) { delay_ms(1000); Delay_ctr--; } if((counter_read0)&&(Delay_ctr0)) return(1); if((counter_read0)&&(Delay_ctr>0)) return(0); } //______________________________________________________________________________ // // SERIAL BUFFER ISR #INT_RDA void SerialInt() { Receive_String[counter_read]=getchar(); // Gets chars from uart counter_read++; // Increment counter if(counter_readSIZE_BUFFER)counter_read=0; // Circle Buffer } |
SAMPLE PROGRAM:
Code: |
#include <16f886.h> #device adc=8 #device *=16 #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG #use delay(clock=20000000) #use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS) #include 'string.h' #include 'enfora1218_driver -12-02-2013.c' #include 'flex_lcd.c' // void main() { int sms_index=1; ENABLE_INTERRUPTS(GLOBAL); // Enable Interrupts ENABLE_INTERRUPTS(INT_RDA); // Enable Serial Interrupts SETUP_TIMER_2(T2_DIV_BY_4,207,1); // Set Timer source for PWM setup_ccp1(CCP_PWM|CCP_PULSE_STEERING_A); // Configure CCP1 as a PWM set_pwm1_duty(416L); // Set Duty to %50 (Drives LCD -Ve pump) lcd_init(); // Initialize LCD Screen //************************************************************************** // Clears the Comm buffer //************************************************************************** CLEAR_BUFFER(); lcd_putc('fBUFFER CLEAREDn'); DELAY(1); // Delay a maximum of X seconds while(1) { //************************************************************************** // Check if modem is attached //************************************************************************** if(CHECK_COM()) { CLEAR_BUFFER(); lcd_putc('fCOMMS ARE GOODn'); lcd_putc('MOVING ON...n'); DELAY(1); // Delay a maximum of X seconds } else { lcd_putc('fCOMMS FAILEDn'); DELAY(1); // Delay a maximum of X seconds while(!CHECK_COM()) { lcd_putc('RETRYING - STUCK IN LOOPn'); DELAY(1); // Delay a maximum of X seconds } lcd_putc('f'); lcd_putc('fCOMMS ARE GOODn'); } DELAY(1); // Delay a maximum of X seconds; //************************************************************************** // Set Modem to TXT mode //************************************************************************** lcd_putc('fSET MODEM TO TXT MODEn'); DELAY(1); // Delay a maximum of X seconds if(SET_PDU()) { CLEAR_BUFFER(); lcd_putc('OK! - MOVING ON...n'); DELAY(1); // Delay a maximum of X seconds } else { lcd_putc('ERROR - STUCK IN LOOP...n'); while(1); } //************************************************************************** // Set Prefered message Storage //************************************************************************** lcd_putc('fSETTING SMS MEMORYn'); DELAY(1); // Delay a maximum of X seconds; if(SET_MEM()) { CLEAR_BUFFER(); lcd_putc('OK! - MOVING ON...n'); DELAY(1); // Delay a maximum of X seconds } else { lcd_putc('ERROR - STUCK IN LOOP...n'); while(1); } //************************************************************************** // Set SMS Alert Message //************************************************************************** lcd_putc('fSETTING SMS ALERTn'); DELAY(1); // Delay a maximum of X seconds; if(SET_CNMI()) { CLEAR_BUFFER(); lcd_putc('OK! - MOVING ON...n'); DELAY(1); // Delay a maximum of X seconds } else { lcd_putc('ERROR - STUCK IN LOOP...n'); while(1); } //************************************************************************** // WAIT FOR SMS AND READ //************************************************************************** lcd_putc('fMODEM SETUP IS DONEn'); lcd_putc('CLEARING BUFFER...n'); CLEAR_BUFFER(); lcd_putc('DONE ---> RUN PROGRAMn'); DELAY(1); // Delay a maximum of X seconds while(1) { lcd_putc('f'); lcd_putc('fWAITING FOR SMSn'); while(!STRING_SEARCH(CMTI)){} lcd_putc('fSMS RECEIVED!!!n'); CLEAR_BUFFER(); sms_index=1; while(READ_SMS(sms_index)) { if(GET_SMS_COMMAND()AIRE)lcd_putc('PRENDE AIREn'); if(GET_SMS_COMMAND()LUZ1)lcd_putc('PRENDE LUZ 1n'); if(GET_SMS_COMMAND()LUZ2) { lcd_putc('PRENDE LUZ 2n'); CLEAR_BUFFER(); SEND_SMS(); } DELAY(3); // Delay a maximum of X seconds DEL_SMS(sms_index); sms_index++; CLEAR_BUFFER(); } } }//--END OF MAIN WHILE } |
Obviously all the Tabs and Spacing got Screwed up, but dont worry, think of it as an exiting adventure!
.... So, That's that and I hope it helps others and solves a lot of the issues of the previous code...
Gracias...
.
.
.
.
...TOTALES,
Gabriel
_________________
CCS PCM 4.135 & CCS PCH 5.013
Last edited by Gabriel on Mon May 06, 2013 8:09 pm; edited 3 times in total
SIM800L module API
SMS
send SMS (
AT+CMGS='<the_number>'
):
send unicode SMS (
AT+CMGS='<the_number>'
):
receive SMS (
+CMTI: 'SM',<total>
):
get one/all SMS (
AT+CMGR=<index>
, AT+CMGL='ALL'
):
delete all/one SMS (
AT+CMGD=<index>
, AT+CMGDA='DEL ALL'
):
Calls
initiate calls (
ATD<number>;
):
receive calls (
RING
):
accept calls (
ATA
):
know if call ended (
NO CARRIER
):
hangup call (
ATH
):
reject calls (
AT+GSMBUSY
):
use or not buzzer sound for incoming calls (
AT+CBUZZERRING
):
General
toggle Net LED (
AT+CNETLIGHT
):
toggle using the Net LED as GPRS status indicator (
AT+CSGS
):
toggle opening or closing the mike (
AT+CEXTERNTONE
):
get module name & version (
ATI
):
turn on verbose errors (
ATI+CMEE=2
):
get SIM card number (
AT+CCID
):
check network connection (
AT+COPS?
):
check signal strength (
AT+CSQ
):
check battery state (
AT+CBC
):
check the codepages supported by the module, for ex IRA,GSM,UCS2,HEX,PCCP,PCDN,8859-1..: (
AT+CSCS=?
):
for locked SIM cards, to enter PIN before connecting to a network (
AT+PIN=<pin_code>
):
I have a Huawei Modem connected to my VB.net projectall AT Commands work such as
CONNECT
, READ
and SEND SMS
The only thing that I cannot work with is the
DELETE SMS
I have this code:
But the
at_status
throws me 'ERROR' always.AT+CMGD=1,4
as what I've read on the documentation is the right command but it throws me an 'ERROR' always.
What do you think is wrong with my code? All other command works, except this.
MatSnow
5,5562 gold badges13 silver badges27 bronze badges
Quest MajorQuest Major
2 Answers
Sim800 At Commands
I figured it out, I only need to put some linebreaks
& vbCrLf
after every AT Commands.
Read Sms In Sim800l
Quest MajorQuest Major
Pang
7,10116 gold badges68 silver badges107 bronze badges
ramberramber
Not the answer you're looking for? Browse other questions tagged vb.netat-command or ask your own question.
Remote control, especially when this no ethernet or Wifi in the outdoor, has been a very profound things in the past. When I was a child, I always image that I have an equipment which can control all home appliances. Now, this becomes a reality,with Arduino and GPRS modules and some other related modules. And, it is also quite easy, even for the beginners. Here I will step by step to show you how to remote control your home appliances via the GPRS/GSM SMS and relays.
At first, let me give a brief introduction about relay to you.
Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between control and controlled circuits). It acts as a “low voltage controlled switch to control high voltage”, For example, if you want to control power of your washer or air conditioner, which is oftern110v or 220v,by microchip such as AVR or PIC, it is necessary and safe to make your microchip control the relay first, and then control the power supply of those device with the relay.
With the GSM SMS, it is possible to control the relay remotely. You can send a message via phone to control the relay on&off. With this, it will convenient to control any device wirelessly, especially helpfully on irrigation, smart home, outdoor remote control etc.
So, let’s make such a “SMS controlled Relay” with Arduino, GPRS/GSM and a Relay module.
At first, let me give a brief introduction about relay to you.
Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between control and controlled circuits). It acts as a “low voltage controlled switch to control high voltage”, For example, if you want to control power of your washer or air conditioner, which is oftern110v or 220v,by microchip such as AVR or PIC, it is necessary and safe to make your microchip control the relay first, and then control the power supply of those device with the relay.
With the GSM SMS, it is possible to control the relay remotely. You can send a message via phone to control the relay on&off. With this, it will convenient to control any device wirelessly, especially helpfully on irrigation, smart home, outdoor remote control etc.
So, let’s make such a “SMS controlled Relay” with Arduino, GPRS/GSM and a Relay module.