Login   Register  
PHP Classes
elePHPant
Icontem

send sms using phpSerial class

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP Serial  >  All threads  >  send sms using phpSerial class  >  (Un) Subscribe thread alerts  
Subject:send sms using phpSerial class
Summary:how to pass on a control-z
Messages:10
Author:kyeyune grace
Date:2008-02-19 13:22:54
Update:2013-03-27 16:05:27
 

  1. send sms using phpSerial class   Reply  
Picture of kyeyune grace
kyeyune grace
2008-02-19 13:22:55
hi,
am trying to implement a web sms application using this phpSerial class and a modem.
COULD SOMEONE PLIZ LOOK AT THE CODE BELOW
to send the sms on this modem, one enters the receipients number followed by Enter key whose special character is "\r". then type the message and end with control-z whose special character i suppose is "\x1a".
but when i use the ctrl-z special character no message is sent. come someone pliz help me out. or is it me who is doin g it in the wrong way

<?php

include "php_serial.class.php";

// Let's start the class
$serial = new phpSerial;

// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)

$serial->deviceSet("/dev/ttyS0");
$serial->confBaudRate(19200);

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("AT+cmgf=1;+cnmi=2,1,0,1,0\r");
// Wait and read from the port
$read = $serial -> readPort();

// construct the msg and send it
$serial->sendMessage("at+cmgs=\"+256782847346\"\r\n");
$serial->sendMessage("this is a text message from *****\r\n");
$serial->sendMessage("\x1a");
// Wait and read from the port
sleep(5);
$read=$read . $serial->readPort();

//wait for modem to send message
sleep(7);
$read=$read . $serial->readPort();

$serial->deviceClose();

// We can change the baud rate
// etc...

echo $read;
?>

  2. Re: send sms using phpSerial class   Reply  
Picture of tijijose
tijijose
2008-11-18 09:33:53 - In reply to message 1 from kyeyune grace
Hi,
I have also same problem,
So please change the portion,
$serial->sendMessage("\x1a"); in your code to
$serial->sendMessage(chr(26)); I think this will work for your code

  3. Re: send sms using phpSerial class   Reply  
Picture of MOURIER
MOURIER
2009-01-08 13:58:49 - In reply to message 1 from kyeyune grace
Hello,
Unable to reach Remy, can u help me please?
I try to make working the class for example with your programm. On a machine I received back port not open etc.. on the other one nothing only php back. Does I need to do something before launching programm? I check the port with stty, if I change a parameter with the class nothing is changed throught php!! Linux basis are centos4.7 et 5.2



  4. Re: send sms using phpSerial class   Reply  
Picture of adumas
adumas
2009-02-10 19:08:15 - In reply to message 3 from MOURIER
Hi... I'm having problems with this class working on Windows...

I created a very short php script and it fails everytime. I get HTTP 500 error... If I take everything out after the initial hello, then I get a hello message on the screen.

Can someone please help?

For what it is work, I am using ISAPI for the Server API.


<?php

echo ('hello');

include "../php/php_serial.class.php";

// Let's start the class
$serial = new phpSerial;

// First we must specify the device.
$serial->deviceSet("COM4");

$serial->confBaudRate(9600);

// Then we need to open it
$serial->deviceOpen();

sleep(1);

// To write into
$serial->sendMessage("H");

//wait for modem to send message
sleep(1);

$serial->deviceClose();

echo ('goodby');
?>

  5. Re: send sms using phpSerial class   Reply  
Picture of MOURIER
MOURIER
2009-02-11 10:17:54 - In reply to message 4 from adumas
Hi,
I test your (very complicated!) programm similar to mine: it goes to the end on Centos 5.0 Linux, but nothing change on serial port. I am in the same step. No answer from no one.

  6. Re: send sms using phpSerial class   Reply  
Picture of robert
robert
2009-05-29 08:27:11 - In reply to message 2 from tijijose
you can send sms with that script because i try an is not working?

thanks

  7. Re: send sms using phpSerial class   Reply  
Picture of Mauricio Silveira
Mauricio Silveira
2012-01-25 01:42:19 - In reply to message 1 from kyeyune grace
AFAIK, this:

// construct the msg and send it
$serial->sendMessage("at+cmgs=\"+256782847346\"\r\n");
$serial->sendMessage("this is a text message from *****\r\n");
$serial->sendMessage("\x1a");

Sould become this:

// construct the msg and send it
$serial->sendMessage("at+cmgs=\"+256782847346\"\r");
$serial->sendMessage("this is a text message from *****");
$serial->sendMessage(chr(26));


I have THIS working with PDU mode: ( Using PDU class )
...
$ATCMGS = "AT+CMGS=" . $pduMessage['cmgslen'] . "\r";
$SMSTxt = trim($pduMessage['pdu']) . chr(26);
...

$serial->sendMessage("AT+CMGF=0\r");
$serial->sendMessage($ATCMGS);
$serial->sendMessage($SMSTxt);



Ctrl+Z ( chr(26) ) for both cases should be the last char.

Not sure about trivial ATCMGS mode ( all my Modems/Phones used for SMS are PDU ( lucky me!? ) ), but PDU mode forbids any \r or \n. Ctrl+Z after the PDU encoded message is a rule.

  8. Re: send sms using phpSerial class   Reply  
Picture of UÍmerson Alves
UÍmerson Alves
2012-03-10 21:31:25 - In reply to message 7 from Mauricio Silveira
How to read messages from the modem?

  9. Re: send sms using phpSerial class   Reply  
Picture of asharunov
asharunov
2013-03-21 10:09:53 - In reply to message 7 from Mauricio Silveira
I'm using php_serial_class and php to send SMS with a simple code like this:

But the received sms begins with an empty row and the second row begins with ">" symbol, like:
___________________


>sms text
___________________

(symbol ' must be removed to a proper understanding in this site)
include "php_serial.class.php";

$serial = new phpSerial;
$serial->deviceSet("/dev/ttyS2");
$serial->confBaudRate(9600);

// Then we need to open it
$serial->deviceOpen();

$serial->sendMessage("ATZ\n\r");
// Wait and read from the port
//$read = $serial -> readPort();

$serial->sendMessage("ATE0\n\r");
// Wait and read from the port
//$read = $serial -> readPort();

// To write into
$serial->sendMessage("AT+cmgf=1;+cnmi=2,1,0,1,0\n\r");//
$serial->sendMessage("AT+cmgs=\"+7912_____\"\n\r");
$serial->sendMessage("sms text\n\r");
$serial->sendMessage(chr(26));

//wait for modem to send message
sleep(7);
$read=$serial->readPort();

$serial->deviceClose();

  10. Re: send sms using phpSerial class   Reply  
Picture of Adam
Adam
2013-03-27 16:05:27 - In reply to message 1 from kyeyune grace
I will share one thing with all Windows users.

There is a problem with Windows Virtual USB COM ports.
I bet if you will try using COM1 (which is usually installed by default) you will see that you can connect.

I tried 5 different scritps / 2 compiled php extensions and still I have no solution for it.