SMS Code


#1

Hi,
I am new to Wavecom programming and having read all the documentation and run Eclipse, I cannot find any simple
samples that I can use to send and receive SMS text messages.
It would be very useful to have code to receive specific text message when an IO port line toggles state and to turn ON
an output if a specific text message is sent.

I use a Q2686 module and any code implementation in Lua. AT or C would be appreciated.

Thanks.


#2

Hiya,

Have a look at the Telemetry sample application, included in the OpenAT/Oasis sample directory.

cheers, Dave


#3

Thanks, Dave.
However, this code is only for inputs. How do I send specific text message to turn on/off an output pin ?

Rgds


#4

Here is a complete sample to toggle an output pin (here GPIO44) when an incoming SMS message arrives with the text “ON” or “OFF”:

#include "adl_global.h"

const u16 wm_apmCustomStackSize = 2048;

// select the IO pin (here GPIO44) --> Check the Product Technical Specification of your Wireless CPU
#define OUTPUT_PIN  44
adl_ioDefs_t output_pin = ADL_IO_GPIO | OUTPUT_PIN;
// configure the IO pin as output with default level set to LOW
adl_ioDefs_t output_pin_cfg = ADL_IO_GPIO | OUTPUT_PIN | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW;
// io handle
s32 output_pin_hdl;
// sms handle
s8 sms_handle;        

void toggle_output( bool state )
{
    adl_ioWriteSingle ( output_pin_hdl, &output_pin , state );
}

void SMS_ctrl_Handler( u8 Event, u16 Nb )
{
    TRACE (( 1, "SMS_ctrl_Handler: Event=%d Nb=%d", Event, Nb ));
}

s32 SMS_Handler( ascii *SmsTel, ascii *SmsTimeOrLength, ascii *SmsText )
{
    TRACE (( 1, "SMS_Handler: new SMS message received" ));
    
    if ( ! wm_strncmp( SmsText, "ON", 2 ) )
    {
        TRACE (( 1, "SMS_Handler: message received to turn ON GPIO%d", OUTPUT_PIN ));
        toggle_output( TRUE );
        return FALSE; // don't show the SMS indication
    }
    else if ( ! wm_strncmp( SmsText, "OFF", 3 ) )
    {
        TRACE (( 1, "SMS_Handler: message received to turn OFF GPIO%d", OUTPUT_PIN ));
        toggle_output( FALSE );
        return FALSE; // don't show the SMS indication
    }
    else
    {
        TRACE (( 1, "SMS_Handler: Unknown message" ));
    }
    return TRUE; // show the SMS indication
}

void adl_main ( adl_InitType_e InitType )
{
    output_pin_hdl = adl_ioSubscribe( 1, &output_pin_cfg, 0, 0, 0 );
    
    if ( output_pin_hdl < 0 )
    {
        TRACE (( 1, "Failed to subscribe to GPIO%d (error=%d)", OUTPUT_PIN, output_pin_hdl ));
        return;
    }

    sms_handle = adl_smsSubscribe( SMS_Handler, SMS_ctrl_Handler, ADL_SMS_MODE_TEXT );        
}

I tested it on OASiS 2.20 (OS 6.20).

I hope this will help you :wink:

Jay


#5

Thanks, Jay - I will try it out later.

Sean.


#6

Hi !
I can’t find how to clear SMS memory.
When I have 30 SMS, new SMS didn’t call SMS handler. I must call AT+CMGD=0,4 from terminal. Is there any other way?

Andrey


#7

If you don’t want to store the SMS messages into the SIM card, then you have just to return FALSE instead of TRUE in the SMS handler.

+++

Jay