为什么我会随SMS一起收到命令? [英] Why I'm receiving at-commands along with the SMS?

查看:162
本文介绍了为什么我会随SMS一起收到命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过USB调制解调器使用AT命令通过PHP发送短信.我可以将SMS从PHP服务器发送到特定的电话号码.但是问题是,当我向电话发送一些文本时,我还会收到用于发送SMS的命令.

I'm trying to send SMS via PHP using AT commands via USB modem. I can send SMS from PHP server to specific phone numbers. But the problem is, when I'm sending some text to a phone, I'm also getting at commands that I have used to send the SMS.

server.php

$fp = fopen('COM4', 'r+');
$writtenBytes = fputs($fp, "AT\r\n");
$writtenBytes = fputs($fp, "AT+CMGF=1\r\n");
$writtenBytes = fputs($fp, "WAIT=1\r\n");
$writtenBytes = fputs($fp, "AT+CSCS=\"GSM\"\n\r");
$writtenBytes = fputs($fp, "WAIT=1\r\n");
$writtenBytes = fputs($fp, "AT+CMGS=\"+91xxxxxxxxxx\"\r\n");
$writtenBytes = fputs($fp, "sample text here\n\r");
$writtenBytes = fputs($fp, chr(26));

预期输出:

此处为示例文本

sample text here

但是我收到的短信是:

AT

AT + CMGF = 1

AT+CMGF=1

WAIT = 1

AT + CSCS ="GSM"

AT+CSCS="GSM"

WAIT = 1

AT + CMGS ="+ 91xxxxxxxxxx"

AT+CMGS="+91xxxxxxxxxx"

此处为示例文本

如何以没有AT命令发送到手机的方式发送SMS?

How can I send SMS in such a way that no AT commands are send to the phone?

推荐答案

您的代码包含三个基本的误解,即如果不修复,将永远无法成功进行AT命令通信.

Your code contains three fundamental misconceptions that if you do not fix, you will never be able to have successful AT command communication.

最重要的一点:您必须 阅读并解析调制解调器发送回给您的所有信息.有时人们错误地使用delaysleep等而不是解析响应,但是在这里您甚至没有这样做,而是尽可能快地调用fput.那是灾难,不会离有时可靠地工作很遥远.我强烈建议您放弃/取消订阅任何显示此类代码示例 1 的博客/网站/视频频道.

First the most important ting: You must read and parse everything the modem sends back to you. Sometimes people incorrectly use delay, sleep etc instead of parsing the response, but here you are not even doing that but instead calling fputs as fast as possible. That is a disaster recipy and will not be even remotely close to sometimes working reliably. I highly recommend abandoning/unsubscribing from any blog/website/video channel that shows such code examples1.

然后问一个问题.如果您担心回声是否打开,请您做错了.

Then the one the question is asking about. If you care about whether echo is on or not, you're doing it wrong.

特别是对于AT+CMGS,您还必须 等待准备接收有效载荷数据"提示发送SMS有效负载之前.

And specifically for AT+CMGS you also MUST wait for the "ready to receive payload data" prompt before sending the SMS payload.

1 就像有人建议用肥皂和水清洗汽车发动机内部一样,那个人您永远都不应听与汽车保养有关的任何事情.他们可能仍会在其他领域提供有价值的信息(例如食物食谱和烹饪建议),但不会从中获取汽车机械师的提示.

1 In the same way that if someone recommends cleaning the inside of a car engine with soap and water, that is someone you never should listen to for anything related to car maintenance. They might still provide valuable information in other areas (say food recipes and cooking advice), but do not pick up car mechanics tips from them.

这篇关于为什么我会随SMS一起收到命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆