GPRS 拨号上网

     这几天做了一下gprs拨号上网,模块是西门子的mc39i。我的系统是fedora core 6。其实很简单,我又有高手指导,:-)。
 
    首先从/usr/share/doc/ppp-2.4.4/scripts中cp ppp-on,ppp-off,ppp-on-dialer三个脚本到/home/a/ppp。然后做如下修改:
在ppp-on里
1.改电话号码为*99***1#
2.将账号与密码清除
3.修改DIALER_SCRIPT的路径为/home/a/ppp/ppp-on-dialer
4.把下设备改成/dev/ttyS0,速率改为115200
5.将crtscts参数去掉,
6.在ppp-on-dialer里把帐号密码那块去掉。
 
下面是对脚本的一些说明。当然都是网上搜来的了。:-)
/home/a/ppp/ppp-on
#!/bin/sh
#
# Script to initiate a ppp connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command.  However, it is simple.
#
# These are the parameters. Change as needed.
#
TELEPHONE=*99***1#     # The telephone number for the connection
ACCOUNT=               # The account name for logon (as in 'George Burns')
PASSWORD=              # The password for this account (and 'Gracie Allen')
LOCAL_IP=0.0.0.0       # Local IP address if known. Dynamic = 0.0.0.0
REMOTE_IP=0.0.0.0      # Remote IP address if desired. Normally 0.0.0.0
NETMASK=255.255.255.0  # The proper netmask if needed
#
# Export them so that they will be available at 'ppp-on-dialer' time.
export TELEPHONE ACCOUNT PASSWORD
#
# This is the location of the script which dials the phone and logs
# in.  Please use the absolute file name as the $PATH variable is not
# used on the connect option.  (To do so on a 'root' account would be
# a security hole so don't ask.)
#
DIALER_SCRIPT=/home/a/ppp/ppp-on-dialer
#
# Initiate the connection
#
# I put most of the common options on this command. Please, don't
# forget the 'lock' option or some programs such as mgetty will not
# work. The asyncmap and escape will permit the PPP link to work with
# a telnet or rlogin connection. You are welcome to make any changes
# as desired. Don't use the 'defaultroute' option if you currently
# have a default route to an ethernet gateway.
#
exec /usr/sbin/pppd debug lock modem /dev/ttyS0 115200 /
 asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP /
 noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT

exec /usr/sbin/pppd debug lock modem /dev/ttyS0 115200 /
 asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP /
 noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT这个命令的作用是:(可以使用man pppd查看帮助)运行/usr/sbin/pppd程序,给它传入命令行参数的意义是:
/dev/ttyS0: 拨号所用的MODEM所连接的串口(ttyS0是串口1,ttyS1是串口2...)
115200 : MODEM的通信速率(57600 BPS)
modem  : 用MODEM进行拨号。
nocrtscts : 无流控
lock  : 锁定这个设备
debug  :输出调试信息
defaultroute : 此拨号连接作为默认路由
connect /home/a/ppp/ppp-on-dialer:使用/home/a/ppp/ppp-on-dialer进行拨号

/home/a/ppp/ppp-on-dialer
#!/bin/sh
#
# This is part 2 of the ppp-on script. It will perform the connection
# protocol for the desired connection.
#
exec chat -v      /
 TIMEOUT  3    /
 ABORT  '/nBUSY/r'   /
 ABORT  '/nNO ANSWER/r'   /
 ABORT  '/nRINGING/r/n/r/nRINGING/r' /
 ''  /rAT    /
 'OK-+++/c-OK' ATH0    /
 TIMEOUT  30    /
 OK  AT+IPR=115200   /
 OK  AT+CGDCONT=1,"IP","CMNET"   /
 OK  AT+CGACT=1,1   /
 OK  ATDT*99***1#   /
 CONNECT  ''    /
# ogin:--ogin: $ACCOUNT   /
# assword: $PASSWORD
chat命令的帮助请参考man -a chat查看。
ABORT BUSY
ABORT ERROR
ABORT NO CARRIER
ABORT NO DIALTONE
ABORT RING<--------如果遇到MODEM回应"BUSY","ERROR","NO CARRIER","NO DIALTONE"则立即报错并退出拨号。

"" AT<--------外送"AT"命令。

OK  AT+IPR=115200<--------设置波特率。

"OK" "AT+CGDCONT=1,“ip”,“cmnet”<---当判到“OK"回应时,外送AT+CGDCONT=1,"ip","cmnet" 命令。设置GPRS接人网关。其中CMNET为移动梦网的接人网关。

OK  AT+CGACT=1,1<--------激活GPRS功能,如果返回OK,则GPRS连接成功;如果返回ERROR则意味着GPRS失败。这时候应该检查一下SIM卡的GPRS业务是否已经开通,GPRS模块天线是否安装正确等问题。

"OK" "ATDT*99***1#" <---当判到“OK"回应时,外送拨号ATDT*99***1# 命令。

"CONNECT" <---当判到“CONNECT"回应时,拨号结束,程序退出。

/home/a/ppp/ppp-off

#!/bin/sh
##############################################
# Determine the device to be terminated.
#
if [ "$1" = "" ]; then
 DEVICE=ppp0
else
 DEVICE=$1
fi
###############################################
# If the ppp0 pid file is present then the program is #running. Stop it.
if [ -r /var/run/$DEVICE.pid ]; then
        kill -INT `cat /var/run/$DEVICE.pid`
#
# If the kill did not work then there is no process running for this
# pid. It may also mean that the lock file will be left. You may wish
# to delete the lock file at the same time.
        if [ ! "$?" = "0" ]; then
                rm -f /var/run/$DEVICE.pid
                echo "ERROR: Removed stale pid file"
                exit 1
        fi
#
# Success. Let pppd clean up its own junk.
        echo "PPP link to $DEVICE terminated."
        exit 0
fi
#
# The ppp process is not running for ppp0
echo "ERROR: PPP link is not active on $DEVICE"
exit 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STM32是一款广泛应用于嵌入式系统的微控制器,而EC200S是一款支持GSM/GPRS/EDGE/UMTS/HSPA+/LTE等多种网络技术的无线模块。要在STM32上通过EC200S拨号上网,可以按照以下步骤进行: 1. 硬件接线:将EC200S无线模块与STM32微控制器进行连接。具体连接方式可以参考EC200S和STM32的开发板手册或者电路图。 2. 配置串口通信:在STM32的软件开发环境中,配置一个串口通信通道,用于与EC200S进行数据通信。通常情况下,EC200S使用AT指令进行控制和通信,因此选择一个串口作为EC200S的通信端口,并配置相应的参数,例如波特率、数据位数、校验位等。 3. 编写软件代码:在STM32的开发环境中,编写相应的软件代码。首先,通过串口向EC200S发送AT指令,例如AT+CGDCONT指令用于设置移动网络接入点;然后使用ATD*99#指令拨号上网;最后,通过串口接收和解析EC200S返回的数据,以确定拨号是否成功。 4. 处理网络连接状态:在程序中处理网络连接状态。一旦成功拨号上网,STM32可以通过发送和接收数据来与互联网进行通信。如果网络连接中断或者拨号失败,STM32可以尝试重新拨号或者处理错误情况。 需要注意的是,具体的实现可能还需要针对EC200S模块的功能特性和STM32的硬件限制进行适当调整和优化。此外,还需要参考相关的技术文档和开发资料,以确保正确配置和操作各个模块和接口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值