Beispiel #1
0
//open the serial port
ser_setDTR(false);
ser_setRTS(false);
if (ser_isopen()) {
    //while(ser_inputcount() <= 0) {sleep(1);echo('-');}
    sleep(10);
    //let the hardware initialize first.
    $ch = curl_init();
    while (1) {
        // get the data from MonArd server
        curl_setopt($ch, CURLOPT_URL, $MONARD_SERVER_URL);
        //warning: don't use so many clients at a time with keepalives on
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Keep-Alive', 'Keep-Alive: 300'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($ch);
        ser_write(trim($res));
        echo $res;
        sleep(3);
    }
    curl_close($ch);
    //everything else below just used for debugging.
    sleep(10);
    echo ser_inputcount() . " -<br>";
    while (ser_inputcount() > 0) {
        $data = chr(ser_readbyte());
        echo $data;
        echo '---';
    }
} else {
    echo "no connection";
}
Beispiel #2
0
<?php

$str = ser_version();
echo "Version: {$str}";
ser_open("COM5", 9600, 8, "None", "1", "None");
if (ser_isopen()) {
    echo "Port is open!";
}
ser_setDTR(True);
ser_write("AT+CMGF=1\r\n");
sleep(1);
// wait a while
$str = ser_read();
echo $str;
ser_write("AT+CMGL=\"ALL\"\r\n");
sleep(2);
// wait a while, if list is long we must wait longer
$str = ser_read();
echo $str;
 function sendPDUSms($phone_num, $sms_text)
 {
     // 短信中心号码
     $smsc = SMS_SMSC;
     //		$cmd_log = $smsc;
     //		$cmd_log .= $sms_text;
     // 短信最大长度70个汉字,Unicode表示需要280个字节
     $max_len = 280;
     $invert_smsc = StringHelper::InvertNumbers($smsc);
     $len = 1;
     $s = chr(13);
     $phone_num = "86" . $phone_num;
     $sms_text = $sms_text;
     $pdu_text = StringHelper::hex2str(StringHelper::gb2unicode($sms_text));
     //		$cmd_log .= StringHelper::gb2unicode($sms_text);
     $invert_msisdn = StringHelper::InvertNumbers($phone_num);
     // 拆分发送超过70汉字的短信(todo: 没有判断全英文的情况)
     $pdu_len = strlen($pdu_text);
     if ($pdu_len > $max_len) {
         $pdu_text1 = substr($pdu_text, 0, $max_len);
         $pdu_text = substr($pdu_text, $max_len, $pdu_len - $max_len);
     } else {
         $pdu_text1 = $pdu_text;
         $pdu_text = "";
     }
     $pdu_len1 = sprintf("%02X", strlen($pdu_text1) / 2);
     $pdu_text1 = $pdu_len1 . $pdu_text1;
     $pdu_text1 = "11000D91" . $invert_msisdn . "000800" . $pdu_text1;
     $atcmd = "AT+CMGS=" . sprintf("%d", strlen($pdu_text1) / 2) . chr(13);
     $l = strlen($atcmd);
     //		$cmd = NOKIA_QD_CMGF_AT_COMMAND."0".chr(13);
     //		ser_write($cmd);
     //		$cmd_log .= $cmd;
     ser_write($atcmd);
     $cmd_log = $atcmd;
     ser_write(" " . chr(26) . chr(13));
     $pdu_text1 = "0891" . $invert_smsc . $pdu_text1 . chr(26) . chr(13);
     $l = strlen($pdu_text1);
     ser_write($pdu_text1);
     $cmd_log .= $pdu_text1;
     ser_write("AT+CMGS: 88 " . chr(13));
     //		$fp = fopen("pud_log.txt","w+");
     //		fwrite($fp, $cmd_log);
     //		fclose($fp);
 }