Send SMS

I am trying to write a code that sends automatically a sms. But I don’t know what i am doing wrong. Can anyone help me?

#include "adl_global.h"
#include "generated.h"
void SimHdlr(u8 Event)
{
	switch(Event)
	{
	case ADL_SIM_EVENT_INSERTED:
	{
		adl_atSendResponse(ADL_AT_RSP, "Sim Inserted");
		break;
	}
	case ADL_SIM_EVENT_REMOVED:
	{
		adl_atSendResponse(ADL_AT_RSP, "Sim Removed");
		break;
	}
	case ADL_SIM_EVENT_FULL_INIT:
	{
		adl_atSendResponse(ADL_AT_RSP, "Sim Initialized");
		break;
	}
	}
}
s32 SmsHdlr(ascii *SmsTel, ascii *SmsTimeOrLength, ascii *SmsText)
    {
        s32 sms_tobe_fwd = ADL_SMS_FORWARD_INDICATION_AND_STORE;
        TRACE (( 1, "In SMS_Handler - 1 more SMS received" ));
        return sms_tobe_fwd;
    }
void SmsCtrlHdlr(u8 Event, u16 Nb)
{
	switch (Event)
	{
	case ADL_SMS_EVENT_SENDING_OK:
	{
		adl_atSendResponse(ADL_AT_RSP, "Msg Send");
		break;
	}
	case ADL_SMS_EVENT_SENDING_ERROR:
		adl_atSendResponse(ADL_AT_RSP, "Msg Send Err");
		break;
	}
    TRACE (( 1, "In SMS_ctrl_Handler" ));
}
void main_task(void)
{
	adl_InitType_e init=adl_InitGetType();
	adl_simSubscribe(SimHdlr, NULL);
	u8 a=adl_smsSubscribeExt(SmsHdlr, SmsCtrlHdlr, ADL_SMS_MODE_TEXT);
	adl_smsSend(a, "**********", "Test", ADL_SMS_MODE_TEXT);
}

So what actually happens when you run it :question:

I get something like “Sim Initialized” and after that nothing happends

You should wait ADL_SIM_EVENT_FULL_INIT event BEFORE trying to send an SMS.

Marc

That’s necessary - but not sufficient.

You need to be GSM-Registered before you can send a text - just like on a phone!

Hiya,

A couple of things:

  1. You really should have a ‘default’ case in each of your switch statements. Not strictly required, but makes sure that every case is dealt with - even if it’s being ignored
  2. As noted above, you need wait for the network registration event after getting your ‘SIM_FULL_INIT’ event. This can only be done by polling the AT+CREG? command and parsing the AT response. See in some of the DevStudio GPRS samples for a quick overview

ciao, Dave

Well, that’s not the only way - you could also enable unsolicited +CREG: indications, and use them…

I managed to send a sms by calling smsSubscribe and smsSend in ADL_SIM_EVENT_FULL_INIT

That’s working more by luck than design, then!

It’s GSM Registration that you really need to wait for - the SIM might be initialised before you have GSM Service.

Note that you can subscribe before either GSM Registration or SIM Init - it’s only the actual sending that requires Service…