如何在Linux下建立GPRS无线MODEM拨号
在Linux下建立GPRS无线MODEM拨号,需要进行以下几个步骤:
1、安装Modem驱动
首先需要在Linux系统中安装GSM/GPRS模块的驱动,通常情况下,可以通过包管理器来安装,在Debian和Ubuntu系统中,可以使用apt-get
命令来安装:
sudo apt-get update sudo apt-get install gsmmodem-3gpp.git
2、配置环境变量
接下来需要配置环境变量,以便系统能够找到Modem驱动,在/etc/profile
文件中添加以下内容:
export PATH=$PATH:/usr/local/lib/modem/gsm-modem/bin
然后执行以下命令使配置生效:
source /etc/profile
3、连接GPRS网络
使用AT指令连接GPRS网络,通过串口线连接MODEM和计算机,打开终端,输入以下命令:
echo "ATD 运营商名称 APN 用户名 密码" > /var/log/syslog
将其中的运营商名称、APN、用户名和密码替换为实际的值。
echo "ATD 46000101 internet user password" > /var/log/syslog
接着,输入以下命令激活GPRS连接:
at+cgsascii="APN" //<-replace "APN" with your APN value from step 3 above at+creg? //<-query for registration status (should return "+CREG: 0,1") at+cgatt? //<-query for general attributes (should return "+CGATT: 1") at+cgscep? //<-query for service context parameters (should return "+CGCSDP: [IP address of the GPRS server]") at+cgdcon? //<-query for data connection parameters (should return "+CGDCONT: IP address of the GPRS server port number") at+cgap? //<-query for access point information (should return "+Cgap: version=2, type=1, period=32") at+csq? //<-query for signal quality (should return "+CSQ: level=50, reg=75, noise=25") at+cii? //<-query for interface information (should return "+CII: [interface name],[UP/DOWN]") at+cif? //<-query for interface frequency (should return "+CIF: [interface name],[frequency]") at+cin? //<-query for network interface status (should return "+CIN: [interface name],[status]") at+cipa? //<-query for IP address configuration parameters (should return "+CIPA: [IP address of the GPRS server]") at+cnet? //<-query for network settings (should return "+CNET: [network type],[address type],[IP address],[gateway address],[DNS server address]") at+cregstart //<-start registration process (should return OK) at+cgattstart //<-start general attributes process (should return OK) at//<-exit AT command mode and enter data transfer mode (should return OK)
4、发送和接收数据
现在已经成功连接到GPRS网络,可以使用AT指令发送和接收数据,要发送一条短信,可以输入以下命令:
echo "<短信内容>">smsto:<收件人号码>@cmnet.example.com;exit;
要接收短信,可以使用以下命令:
set pdu=1000;for i in seq $pdu
;do echo;echo;cat;sleep 1;done | at +CMTI <短信中心号码>;set;exit;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;echo;exit;read < smsbox://<短信存储路径>/<短信文件名>.pdu > sms.txt;cat sms.txt | tr '\r' ' ' > sms.txt.formatted;rm sms.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.ctl > smsctl.txt;cat smsctl.txt | tr '\r' ' ' > smsctl.txt.formatted;rm smsctl.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.dat > smsdat.txt;cat smsdat.txt | tr 'r' ' ' > smsdat.txt.formatted;rm smsdat.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.up > smsup.txt;cat smsup.txt | tr '\r' ' ' > smsup.txt.formatted;rm smsup.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.dn > smsdn.txt;cat smsdn.txt | tr '\r' ' ' > smsdn.txt.formatted;rm smsdn.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.mdn > smsmdn.txt;cat smsmdn.txt | tr 'r' ' ' > smsmdn.txt.formatted;rm smsmdn.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.lcd > smslcd.txt;cat smslcd.txt | tr '\r' ' ' > smslcd.txt.formatted;rm smslcd.txt > /dev/null 2>&1;exit;read < smsbox://<短信存储路径>/<短信文件名>.mlc > mmlcd.txt;cat mmlcd.txt | tr '\r' ' ' > mmlcd.txt.formatted;rm mmlcd.txt > /dev/null 2>&1;exit" & sleep 1000 & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGFILE & wait $! & read < $LOGFILE & cat $LOGIDX >> logfile_idx_$(date +%Y%m%d).log && killall at && killall gsmmodem-3gpp || true && exit && echo "GPRS Modem拨号成功" || false && exit && echo "GPRS Modem拨号失败" || true && exit && echo "GPRS Modem拨号已断开" || true && exit && echo "GPRS Modem拨号正在断开" || true && exit && echo "GPRS Modem拨号已断开并重新连接" || true && exit && echo "
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/210540.html