使用EC20搭配树莓派搭建短信接收服务
物理连接
将EC20模块通过USB接到树莓派的USB口,物理设备连接后查看是否有ttyUSB设备
ls /dev/ttyUSB*
如果有的话则代表物理连接成功
安装依赖
安装gammu
sudo apt-get install gammu
安装gammu-smsd
sudo apt-get install gammu-smsd
安装minicom
sudo apt-get install minicom
配置
# 使用minicom测试哪个设备为短信端口,连接成功后敲at,如果输入ok表示就是该设备
minicom -D /dev/ttyUSB0
# 配置gammu-config,将port填入刚刚的/dev/ttyUSB设备,输出设备信息表示正确
gammu-config
gammu identify
验证短信发送
gammu sendsms TEXT 178XXXXXXXX -text "这是一条测试短信" -unicode
配置短信收取
需要配置正确的/dev/ttyUSB设备,和connecntion,接收的短信配置为最后几个路径,设置接收短信触发程序为RunOnReceive
cat /etc/gammu-smsdrc
# Configuration file for Gammu SMS Daemon
# Gammu library configuration, see gammurc(5)
[gammu]
# Please configure this!
port = /dev/ttyUSB2
connection = at19200
synchronizetime = yes
# Debugging
#logformat = textall
# SMSD configuration, see gammu-smsdrc(5)
[smsd]
RunOnReceive = /path/to/script.sh
service = files
logfile = syslog
commtimeout = 10
sendtimeout = 20
# Increase for debugging information
debuglevel = 0
# Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/
设置开机启动
sudo systemctl start gammu-smsd.service
sudo systemctl enable gammu-smsd.service
gammu-smsd发送邮件命令
gammu-smsd-inject TEXT 178XXXXXXXX -unicode -text "测试短信"
一些巨坑
发现设备一直掉线,经常无法收到消息
解决办法:用dmesg查看是否出现断开连接,将EC20外接一个电源,并且将供电模式按钮打到外接供电上
| 访问量: 次