I have used gnokii to send sms-messages with several programs. I found that while gnokii is useful for single messages, some sort of queue needed to be utilized when sending/receiving more messages. If queue is not utilized, serial port lockup could (and will) occur when multiple gnokii-programs try to ccess GSM-phone simultaneously. I found that Juraj Bednar has created nice queue for gnokii. However, I couldn't get it to work on my machine (problems with lock-files mostly) and decided to try on my own.
The language I choose was Perl. It's so obious language for small text-processing program like this that it hardly needs any explanation. So I just made a little script that reads queue directory and sends any messages in there. After sending them it copies messages to either "sent" or "fail" folders. I also created small program (sendsms.pl) for actually putting the files to queue directories for easy use from procmail and similar programs.
Basic operation is simple. One script handles outgoing messages (gsmqueue.pl) and another script (getsms.pl) handles incoming scripts. These are run by cron once in a while. In addition, there are couple scripts for ease of use and for controlling various things with GSM.
Installation is pretty straightforward.
total 28 drwxrwxrwx 2 henkka henkka 4096 Dec 3 17:15 fail drwxrwxrwx 2 henkka henkka 4096 Dec 13 14:06 in drwxrwxrwx 2 henkka henkka 4096 Dec 13 14:06 in.handled drwxrwxrwx 2 henkka henkka 4096 Dec 13 14:07 out drwxrwxrwx 2 henkka henkka 12288 Dec 13 14:07 sentmkdir /var/gsm
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/bin/getsms.pl 2> /dev/null 2,7,13,17,22,27,32,37,42,47,52,57 * * * * /usr/local/bin/gsmqueue.pl * * * * * /usr/local/bin/gsmcontrol.pl 2>/dev/nullSo that means getsms.pl and gsmqueue.pl are run at 5 minute differences between each other. This is because only one script can call gnokii at a time (due the serial-port lockup).
echo "First test SMS"|/usr/local/bin/sendsms.pl 0129876543(Of course, replace number with your own number...
[henkka@kilpikonna gsmqueue]$ ls /var/gsm/out/ sendsms.out.FIOAys [henkka@kilpikonna gsmqueue]$ cat /var/gsm/out/sendsms.out.FIOAys NUMBER: 0129876543 First test SMSSo that message is eventually read by gsmqueue.pl and sent to you ! After that, you can find message from /var/gsm/sent
If something goes wrong, try running programs from commandline. First your should be able to call sendsms.pl with
echo "First test SMS"|/usr/local/bin/sendsms.pl 0129876543
This should copy your message to /var/gsm/out. Then you can try running gsmqueue.pl by hand:
Edit your ~/.procmailrc and put following line to it:
:0 c * ^From.*myself * ^Subject.*sendsms |formail -I "" | /usr/local/bin/sendsms.plThat way, any messages sent from "myself" with subject containing "sendsms" are copied to sendsms.pl script. Messages should be in
NUMBER: 12309987645 TEXTformat.
#!/usr/bin/perl use CGI qw/:standard/; my $q = new CGI; my $text = $q->param('text'); my $number = $q->param('number'); my $smssend = "/usr/local/bin/sendsms.pl"; system("echo $text|$smssend $number"); print header, start_html('SMS SENDING VIA WEB'); print "Message sent to $number."; print end_html;
<HTML> <form action="/cgi-bin/sms.cgi"> Text:<textarea name="text" rows="5" cols="20"></textarea> Number:<input type="text" name="number"><br> <input type="submit" value="send"> </form> </HTML>
Released under GPL. (c) Henry Palonen, 2001, h@-nospam-.yty.net