【问题标题】:Shell script AT Commands : not able to send sms through serial portShell脚本AT命令:无法通过串口发送短信
【发布时间】:2016-03-03 10:28:33
【问题描述】:

我有以下 shell 脚本(预期),我正在尝试发送 SMS。我参考了许多堆栈溢出引用,发现 ctrl-z 映射到 \x1a。但是,即使将其附加到消息并发送到端口或将 ctrl z 单独发送到端口后,也对我没有帮助。稍后会超时。

编写脚本以发送 pdu 格式的短信。无论如何,我相信这是将 ctrl-z 发送到端口的一般问题。如果您觉得脚本还有其他错误,请分享相同的解决方案。

下面提到的长度 (34) 也是按照规范的 (PDU_LENGTH -2)/2 的长度。此长度不包括 ctrl-z 字符。

at_command = "AT+CMGS=34\r" message_content = "0011000C810056890......"

脚本:

set PROMPT "0"
set timeout "$COMMAND_TIMEOUT"
send "$at_command"
expect {
    "OK" { puts "Command Accepted\n"; }
    "ERROR" { puts "Command Failed\n"; }
    timeout { puts "Unable to connect to $HOSTIP at $HOSTPORT"; exit 1 }
    "*>*" { set PROMPT "1"; }
}

if { "$PROMPT" == "1" } {
    send "$message_content"
    send "\x1a"
    expect {
        "OK" { puts "\nCommand accepted"; }
        "ERROR" { puts "\nCommand failed"; }
        "*>*" { puts "CTRL-Z dint reach UT. Error..."; }
        "*" { puts "Unexpected return value received"; }
    }
}

我很确定脚本将 $message_content" 发送到端口,但在发送"$message_content" 后立即退出。

输出:

AT+CMGS=34

>

【问题讨论】:

  • message_content 结尾有\r 吗?发送消息后您没有收到任何回复吗?
  • @Dinesh:它也可以工作。
  • 发送消息内容后,expect 有事。 (可能会有一些反应)。然后发送尝试发送ctrl+z。删除expect *。我对此表示怀疑。为什么你首先需要它?

标签: shell expect at-command


【解决方案1】:

我在 c# 中使用 SMS-Gateway-Modul 做了类似的事情。

我不得不switch to PDU-Mode first!
之后我必须传输预期的 PDU 长度,最后是 PDU 本身。

每个命令都必须使用回车符ASC[13] 来提交,而 PDU 最终必须使用ASC[26] 来提交。

在这里您可以看到示意图(!)流程,我是如何在c# 中做到的:

1) 创建PDU并获取长度

int len;
var pdu = PDUGenerator.GetPdu(destination, message, "", out len);

2) 切换到 PDU 模式

 SendToCom("AT+CMGF=0" + System.Convert.ToChar(13));

3) 宣布消息长度

SendToCom("AT+CMGS=" + len + System.Convert.ToChar(13));

4) 发送 PDU 并提交

SendToCom(pdu + System.Convert.ToChar(26));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多