9 years, 9 months ago.

How to read sms?

Hi,

I'm testing the program with (SIM900) nucleo F401 and can send sms to my phone, but I have a problem with reading sms. I've modified the program to monitor sms message at pc terminal, here is my program

GPRS_Shield_Test

#include "mbed.h"
#include "gprs.h"

Serial pc(USBTX, USBRX);  //to monitor at pc terminal

#define GPRS_TX_PIN        PA_9     
#define GPRS_RX_PIN        PA_10     


#define SEND_SMS_TEST           1
#define CALL_UP_TEST            0
#define ANSWER_TEST             0
#define READ_SMS_TEST           1

#define BAUD_RATE               9600 // Baud rate of GPRS Shield 
#define PHONE_NUMBER            "9*****5"

GPRS  gprsTest(GPRS_TX_PIN, GPRS_RX_PIN, BAUD_RATE, PHONE_NUMBER);

void messageHandle(void)
{        
	 __disable_irq();
	int messageType = gprsTest.loopHandle();
	if(MESSAGE_RING == messageType) {
			gprsTest.answer();
	} else if(MESSAGE_SMS == messageType) {
			char smsMessage[SMS_MAX_LENGTH];
			gprsTest.getSMS(smsMessage);
			pc.puts("\n\rSMS");
	}
	__enable_irq();
}

int main(void)
{
	pc.printf("\n\rSMS with SIM900\n\r");
	while(0 != gprsTest.init()) {
			wait(2);
	}

#if SEND_SMS_TEST
    gprsTest.sendSMS(PHONE_NUMBER, "hello world"); //define phone number and text
#endif

#if CALL_UP_TEST
    gprsTest.callUp(PHONE_NUMBER);
#endif

#if ANSWER_TEST || READ_SMS_TEST
    gprsTest.gprsSerial.attach(&messageHandle);
#endif
    while(1);
//    return 0;
}

It should show "SMS" at pc terminal when a sms is received

Aung

Question relating to:

give example to use GPRS Shield library
Be the first to answer this question.