gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sending SMS via libgnokii


From: Peter Koch
Subject: Sending SMS via libgnokii
Date: Mon, 28 Nov 2011 15:33:10 +0100

Dear Gnokii-Experts:

I'm trying to send multiple SMS from an application written in
C. I don't want to initialize gnokii for every SMS. This
works well if my applications sends out lots of SMS without
any delay. If there's a delay between two SMS of about 5 seconds
then I must reinitialize gnokii.

Here's a short application that demostrates my problem:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <gnokii.h>

int main(
        int   argc,
        char *argv[]
){
        struct gn_statemachine *state=NULL;
        gn_sms_message_center msg_center;
        gn_data *data;
        gn_sms sms;
        gn_error err;
        int i;

        printf("Initializing Gnokii-State\n");
        gn_lib_phoneprofile_load_from_file("/etc/gnokiirc",NULL,&state);
        gn_lib_phone_open(state);

        data=&state->sm_data;
        data->sms=&sms;
        gn_sms_default_submit(data->sms);

        data->message_center=&msg_center;
        data->message_center->id=1;
        gn_sm_functions(GN_OP_GetSMSCenter, data, state);
        printf("Got SMS-Center %s\n", msg_center.smsc.number);

        for(i=0; i<3; ++i){
                char msg[100], *phone=argv[2];
                int delay=atoi(argv[1]);

                sprintf(msg,"Message No %d", i);

                data=&state->sm_data;
                data->sms=&sms;
                gn_sms_default_submit(data->sms);

                snprintf(sms.smsc.number, sizeof(sms.smsc.number), "%s", 
msg_center.smsc.number);
                sms.smsc.type=msg_center.smsc.type;

                snprintf(sms.remote.number,sizeof(sms.remote.number), "%s", 
phone);
                sms.remote.type=GN_GSM_NUMBER_Unknown;

                sms.user_data[0].type=GN_SMS_DATA_Text;
                sprintf((char*)sms.user_data[0].u.text, "%.918s", msg);
                sms.user_data[0].length=strlen((char*)sms.user_data[0].u.text);
                sms.user_data[1].type=GN_SMS_DATA_None;

                if((err=gn_sms_send(data, state))!=GN_ERR_NONE){
                        printf("gn_sms_send(%s, %s) failed\n%s\n", phone, msg, 
gn_error_print(err));
                        exit(1);
                }
                printf("Success: %s => %s\n", msg, phone);
                printf("Sleep(%d)\n", delay);
                sleep(delay);
        }
}


If I start this application with delay==1 I get the following output:

# gnokii-test 1 0172xxxxxx
Initializing Gnokii-State
Lockfile /var/lock/LCK..ttyS0 is stale. Overriding it...
Got SMS-Center +491722270333
Success: Message No 0 => 0172xxxxxx
Sleep(1)
Success: Message No 1 => 0172xxxxxx
Sleep(1)
Success: Message No 2 => 0172xxxxxx
Sleep(1)

If I choose delay==5 the the exact same program does:

# gnokii-test 5 0172xxxxxx
Initializing Gnokii-State
Lockfile /var/lock/LCK..ttyS0 is stale. Overriding it...
Got SMS-Center +491722270333
Success: Message No 0 => 0172xxxxxx
Sleep(5)
gn_sms_send(0172xxxxxx, Message No 1) failed
Command timed out.

Of course I'm using a correct phone number instead of 0172xxxxxx

What am I doing wrong? Is this correct behaviour?

I'm using a very old Nokia 6310 with a DLR3P cable and latest
Gnokii sources.

# cat /etc/gnokiirc
[global]
port        = /dev/ttyS0
model       = 6310
connection  = dlr3p
use_locking = yes

[logging]
debug    = off
rlpdebug = off
xdebug   = off

Kind regards

Peter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]