0

I'm working with a project to send SMS with Huawei E153 dongle with PHP.But my code is not working with this modem.(It's working with my Samsung mobile phone).To order to solve this problem I need to check respond from modem.Please help.Here is my code.

<?php
$filename ="COM20";

date_default_timezone_set('Asia/Colombo');
 $date = date('Y/m/d H:i:s');
$message="This is a test message 2 .$date.";
$numbers = array("+941234567");
if (!$handle = fopen($filename, 'r+'))
    {
      echo "The device isn't detected";
      exit;
    }
    else
    {

     foreach ($numbers as $value) {
        if (fwrite($handle,"AT+CMGF=1\n\r"))
sleep(5);

     { 
     fwrite($handle, "AT+CMGS=\"$value\"\n\r");
sleep(5);


       fwrite($handle,"$message".chr(26)."\n\r"); 
       sleep(7);
echo "sent to $value <br>";
}
}
fclose($handle);
echo "Port Closed";
}   

?> 
Matt Aldridge
  • 2,037
  • 16
  • 21
  • What exactly is not working? Does the modem connect? If yes what commands does it manage to execute? – Matt Aldridge May 23 '14 at 10:24
  • SMS is only send after disconnect the cable from my phone.But when I use my Huawei Dongle it says "Warning: fopen(COM20): failed to open stream: No such file or directory in C:\xampp\htdocs\gateway\sms.php on line 8 The device isn't detected" – virajekanayake May 26 '14 at 09:07
  • Could it be that your phone and the dongle connect on different COM ports? – Matt Aldridge May 27 '14 at 11:14

1 Answers1

0

Please NEVER use sleep like that when processing AT commands. See this answer for suggestions for how proper parsing should be done.

And with regards to AT+CMGS, you must wait for the ready response from the modem before sending the message content, see the first part of this answer for details.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • I think it would make sense to explain that sleep is necessary after AT Command responses have been received. But not during the reception of AT Command responses. Would be a lot clearer for newbies. – Matt Aldridge May 25 '14 at 09:14
  • What do you mean? Quote from [V.250](http://www.itu.int/rec/T-REC-V.250-200307-I/en): `A final result code indicates the completion of a full DCE action and a willingness to accept new commands from the DTE.`. This willingness is implicitly intimidate here, there is absolutely no delay. If some modem outputs a final result code but is not yet ready to receive a new AT command line that would be a serious bug in the modem. – hlovdal May 25 '14 at 11:02
  • AT Commands are not entirely executed synchronously like it appears. Try entering AT+CPIN and then try execute radio specific AT Commands quickly thereafter. You will find they will fail. All modem manufacturers clearly state what length of delays are required generally and per command. For example Siemens MC55i requires 100ms unless otherwise stated. Sierra Wireless AirPrime modems warn also in their documentation. Of course the modems do follow V.250, but for writing good modem control code you should make use of delays or at least guarding to prevent unexpected results. – Matt Aldridge May 25 '14 at 11:20
  • Also I would recommend reading ETSI GSM 07.07 as it's the GSM variant AT Command specification. – Matt Aldridge May 25 '14 at 14:20
  • I found this answer.But it is not working with my Huawei e173.(Browser Waiting http://stackoverflow.com/questions/16860605/communicating-serial-port-on-windows-with-php?rq=1) – virajekanayake May 26 '14 at 09:01
  • Notice that the 07.07 specification was superceeded by 27.007 many years ago, 07.07 is only relevant as a historical reference. – hlovdal Apr 05 '16 at 13:42