Receive SMS

From openPicus Wiki
Jump to: navigation, search

Contents

What you are going to learn

This tutorial shows how to read each new SMS received on taskFlyport.c file, using GSM_Events.c functions.

Introduction to SMS Reading

All the communication with GPRS Module is handled by GSMTask. Each GSM event (like connection changed, sms received, etc...) a function of GSM_Events.c file is automatically executed. Each type of event has a different function.
When an SMS is received Flyport GPRS performs OnSMSReceived.

NOTE: you cannot read SMS content from GSM_Events.c file. You always have to perform the SMSRead function and related LastSMSxxx functions on taskFlyport.c (or any other user file that actually runs on FlyportTask and not GSMTask).

How to use it

Open Serial Monitor utility of the IDE to read Flyport GPRS messages. In this tutorial there OnSMSReceived code is modified (please, see the below code) to let taskFlyport.c to know if a new SMS was received. The code sets the incomingSMS variable to TRUE, writes the index to incomingIndexSMS variable and memory type used as message storage on incomingMemSMS.
taskFlyport.c code reads continously incomingSMS value. If its value is TRUE a message is written to Serial Monitor:
Reading SMS...done!
SMS sender: phone number of sender
SMS text: text message content

NOTE: On Serial Monitor utility you may read also other debug messages sent by GSM_Events.c. Those messages can be disabled using the Wizard of IDE (unchecking "Debug messages on UART1")

Code example

Code to change on GSM_Events.c:

// Code added to provide information to taskFlyport.c
BOOL incomingSMS = FALSE;
int incomingIndexSMS = 0;
BYTE incomingMemSMS = ME_MEM;
 
void OnSMSReceived(BYTE memtype, int index)
{
    #if defined(STACK_USE_UART)
    UARTWrite(1,"Event: On SMS Received\r\nmemory type: ");
    if(memtype == SM_MEM)
	UARTWrite(1, "SIM card");
    else
	UARTWrite(1, "Module Memory");
    UARTWrite(1, "\r\nmemory index: ");
    char smsRec[7];
    sprintf(smsRec, "%d\r\n", index);
    UARTWrite(1, smsRec);
    #endif
 
    // Code added to provide information to taskFlyport.c
    incomingIndexSMS = index;
    incomingMemSMS = memtype;
    incomingSMS = TRUE;
}


Source code for taskFlyport.c:

#include "taskFlyport.h"
 
extern BOOL incomingSMS;
extern int incomingIndexSMS;
extern BYTE incomingMemSMS;
 
void FlyportTask()
{
    vTaskDelay(20);
    UARTWrite(1,"Flyport Task Started...\r\n");
 
    //Wait for GSM Connection successfull
    do
    {
	UpdateConnStatus();
	while(LastExecStat() == OP_EXECUTION);
    }while((LastConnStatus() != REG_SUCCESS)&&(LastConnStatus() != ROAMING));
 
    vTaskDelay(20);
    UARTWrite(1,"Flyport registered on network!\r\n");
 
    while(1)
    {
	if(incomingSMS == TRUE)
	{
	    incomingSMS = FALSE;
	    vTaskDelay(30);
	    UARTWrite(1, "Reading SMS...");
	    SMSRead(incomingIndexSMS, incomingMemSMS);
 
	    vTaskDelay(20);
	    while(LastExecStat() == OP_EXECUTION)
	    {
        	vTaskDelay(1);
	    }
	    vTaskDelay(20);
	    if(LastExecStat() == OP_SUCCESS)
	    {
		UARTWrite(1, "done!\r\n");
		UARTWrite(1, "SMS sender: ");
		UARTWrite(1, LastSmsSender());
		UARTWrite(1, "\r\nSMS text: ");
		UARTWrite(1, LastSmsText());
		UARTWrite(1, "\r\n");
	    }
	    else
	    {
		UARTWrite(1, "Unable to read SMS\r\n");
	    }
	}
    }
}
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox