problems with auto sending sms

ascii a[20]="+6592273855";
ascii b[20]=“hi”;
ascii SmsTel[20]="+6581507582";
ascii SmsTimeorLength[20]=“1000”;
ascii SmsText[20]=“hi”;
u8 h;
u8 s;
s8 j;
//ascii c[20]=“65”;
bool SMS_TELE_Handler(ascii *SmsTel, ascii *SmsTimeOrLength, ascii *SmsText)
{
return TRUE;
}
void SMS_TELE_ctrl_Handler ( u8 Event, u16 Nb )
{
// Switch on event
switch ( Event )
{
case ADL_SMS_EVENT_SENDING_OK :
TRACE (( 1, “Report OK” ));
break;

case ADL_SMS_EVENT_SENDING_ERROR :
TRACE (( 1, “Report sending error %d”, Nb ));
adl_atSendResponse ( ADL_AT_UNS, “\r\nFailed…\r\n” );

// Check for 512
if ( Nb == 512 )
{
// Please Wait error… retry in 2 seconds
TRACE (( 1, “Retry later…” ));
//adl_tmrSubscribe ( FALSE, 20, ADL_TMR_TYPE_100MS, tele_tmrRetryHandler );
}
break;
}
}

void adl_main ( adl_InitType_e InitType )
{

h=adl_smsSubscribe( SMS_TELE_Handler, SMS_TELE_ctrl_Handler, ADL_SMS_MODE_TEXT );
s=adl_smsSend(h,a,b,ADL_SMS_MODE_TEXT);
j=adl_smsUnsubscribe(h);
TRACE ((1, " Send SMS: %d ", h));
TRACE ((1, " Send SMS: %d ", s));
TRACE ((1, " Send SMS: %d ", j));

}

this is our code and we get the trace:
send sms: 0
send sms: 248
send sms: 0.

we don’t know what’s the error and we need your help! thanks
best regard,
fonix

Please use the ‘Code’ button to post sourec code legibly!

Is u8 appropriate for the return code from adl_smsSend… :question:

Did you look up what 248 means as a return code from adl_smsSend… :question:

thx awneil for the reply, we found that it should be s8 for the adl_smssend but now we got the error (s=-8) which mean the modem is not ready to send the sms. We check the network registration and found out that whenever we start the program we the network registration will be set to +creg (1,2) then after awhile it will change to +creg (1,1). How can we start the program after it had change to +creg(1,1)? thank for your help!!!

Best Regard,
Fonix

Of course it does!

+CREG: 1, 2 indicates the the unit is searching for the network;
+CREG: 1, 1 indicates that it has found it!

Your mobile phone behaves in exactly the same way, doesn’t it?!

Your program needs to behave in exactly the same way that you’d do it manually on a phone - it has to wait until the unit tells you it’s ready!

We put the “retry handler” to resend the sms after a few second. Now the trace show. s=-3 , which is “unknown handler/handle error”.

if ( !tele_tmrRetryHandle )
                {
                    // Retry...
                    TRACE (( 1, "Retry later..." ));
                    tele_tmrRetryHandle = adl_tmrSubscribe ( FALSE, 20, ADL_TMR_TYPE_100MS,TimerHandler );
                     s=adl_smsSend(h,a,b,ADL_SMS_MODE_TEXT); 
                   
                    TRACE ((1, " Send SMS: %d ", h));
                    TRACE ((1, " Send SMS: %d ", s));
                    TRACE ((1, " Send SMS: %d ", j)); 
                }

This code is place under the void adl_main ( adl_InitType_e InitType ) . The rest of the code is the same as shown from the orginal post. I’m not sure about the value “TimerHandler”. That one is under adl_timerHandler.h

Best Regard,
Fonix

Please post the complete code - it’s hard to try to piece it together!

Also check the preview carefully before you post to make sure that it’s actually legible

Again here as well…You should subscribe to SIM then to declare adl_smsSend in one of the cases. That s why you get -8 error. Try this and you will send an SMS

Again here as well, it is not necessary to either subscribe the SIM Service or to call adl_smsSend in the SIM Event handler;
It is one way to proceed, but it is by no means the only way!

See: viewtopic.php?f=19&t=378&p=17098#p17098

.
-8 means “BAD STATE” - that’s because the SIM is not ready.

Therefore, what you need to do is to wait until the SIM is ready…