Dipesh Parmar
Dipesh Parmar

Reputation: 27364

not sending messages from script

I know i might gonna so many down vote but please help me through this as i nearly there. I have below code.

<?php
exec("mode COM1 BAUD=9600 PARITY=N data=8 stop=1 xon=off");
$fp = fopen ("\\.\com1", "r+");
//$fp = dio_open('COM5:', O_RDWR | O_NOCTTY | O_NONBLOCK);
if (!$fp) 
{
    echo "Uh-oh. Port not opened.";
} 
else 
{

    $string  = "AT+CMGF=1";

    $string  = $string."OK";

    $string  = $string."AT+CMGS='+44XXXXX'";

    $string  = $string."> Hello World?<Ctrl>+<Z>";

    $string  = $string."+CMGS: 44";

    $string  = $string."OK";

    fputs ($fp, $string );
    echo $string."\n";
    fclose ($fp);
}

?>

above code is outputting AT+CMGF=1OKAT+CMGS='+44XXXX'> Hello World?++CMGS: 44OK but not actually sending any message to that number.

I have device is attached with PC which has SIM card in it.

How can I do this?

Upvotes: 1

Views: 749

Answers (1)

Bart Friederichs
Bart Friederichs

Reputation: 33521

From what I know of AT commands, is that it is a dialogue. You have to send AT+CMGF=1 then wait for the modem to send OK, send the next command etcetera.

You are now sending everything, including the modem's responses in one string.

More information (as always) on Wikipedia: http://en.wikipedia.org/wiki/Hayes_command_set

The code should be along the lines of (off the top of my head, not tested):

$string = "AT+CMGF=1";
fputs($fp, $string);
$r = fgets($fp);
if ($r == "OK") {
  $string = "AT+CMGS='+44XXXXX'";
  fputs($fp, $string);
  $r = $fgets($fp);
  ... etc ...
}

Upvotes: 4

Related Questions