Edit: find the updated version with more functions in gnokii-extras git repository.
I just added gnokii_open() and gnokii_close().
gnokii_open() has two optional arguments, just like command line gnokii: path of config file and name of phone section
gnokii_close() is optional since PHP will close for you at the end of the script
Bug: a script can't open two phones at the same time because the second open will overwrite the pointer of the first one (I will implement a global pool).
Updated function list:
static function_entry gnokii_functions[] = {
PHP_FE(gnokii_open, NULL)
PHP_FE(gnokii_close, NULL)
PHP_FE(gnokii_identify, NULL)
PHP_FE(gnokii_lasterror, NULL)
PHP_FE(gnokii_version, NULL)
PHP_FE(gnokii_getsmsstatus, NULL)
PHP_FE(gnokii_getsms, NULL)
PHP_FE(gnokii_deletesms, NULL)
PHP_FE(gnokii_reset, NULL)
{NULL, NULL, NULL}
};
Comments
Dear Daniele, I have been
Dear Daniele,
I have been trying to write a php program to send sms through gsm mobile phone using gnokii. I need a sample php program to do that. Could you guide me in doing that?
Thanks.
Daniel
At the moment you can't send
At the moment you can't send an SMS only with PHP: there are too many options available with command line gnokii that wouldn't fit in the current design of the PHP extension.
If you need to send a single SMS or if the phone is not always connected, the best option is calling the gnokii executable using PHP's exec() using input redirection for message body.
If you need to send more than one message, consider using smsd either with one of the database modules (with PHP you simply have to do SQL INSERT) or with the file module (you just create a file in the configured spool directory) and smsd will try to send it. For the file module you may want to look at the smsd examples.
Hi daniele, I develop
Hi daniele,
I develop management websites for companies (generating reports, creating work-flows etc)."; /* Recently, I came across a requirement to send sms from the management system when certain conditions were met. I had two options, either to use a service like txtlocal (the internet connection is a bit choppy and I did not want to go down this road) or to go with Gnokii which I had used once before. So installed gnokii on the server, configured it and got everything working off the terminal. Thinking I had accomplished the task and all I now had to do was use 'system', 'passthru' or 'shell_exec' and everything would be perfect, I went over to Netbeans and nothing seemed to want to work as .gnokiirc was not in the apache user's folder which did not even have a home directory variable. After flaffing about for a couple of hours, I finally managed to get everything to work by using php ssh2 and connecting to my localhost through ssh. Here is the code:
$connection = ssh2_connect('localhost');
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'echo "SMS Text" | gnokii --sendsms Phone_Number');
Everything seems to work perfect using this approach so far. I can send text messages without any problems.
I would really appreciate if you could tell me if you have been able to use the exec command successfully since I always get
'Command failed.
GNOKII Version 0.6.28
Couldn't read (��/.gnokiirc config file.
Couldn't read (��/.gnokiirc config file.
ERROR: Can't find HOME environment variable!
WARNING: cannot open logfile, logs will be directed to stderr
Gnokii serial_open: open: Permission denied
Couldn't open ATBUS device: Permission denied
Telephone interface init failed: Command failed.
Quitting.'
I would also appreciate if you could tell me of any changes that you had to make to apache.
Regards,
Ali
The HOME directory is useful
The HOME directory is useful only if you need different settings for each user else you can put the configuration in /etc/gnokiirc or in a file of your choice if you use the "--config" option.
But in your case gnokii is failing because of a permission problem because Apache isn't supposed to talk to serial ports, you can change that but then every script in you server can talk to your phone; the proper solution would be running smsd as the restricted user of your choice (neither root, nor apache, nor www-data) with a database that the scripts can use only with a password. If you're the only user of the server and you only need to send SMS and only a couple of times a day then gnokii can do.
My approach was different because I used a PHP extension but it has some drawbacks when used inside Apache, better use it as a replacement of gnokii CLI with plain PHP, without Apache.