在嵌入式Linux下GPRS上网方案

笔记1

硬/软件环境

基于S3C2410的嵌入式系统,COM1连接PC,COM2连接SIM300 GPRS模块。

该系统运行在Linux 2.6.14操作系统下,使用ppp套件通过SIM300进行PPP拨号。

一。让Linux内核支持PPP

进入Linux内核目录,执行#make menuconfig

Network Device Support à

PPP (point-to-point protocol) support

[*]   PPP multilink support

PPP support for async serial ports

PPP support for sync tty ports

SLIP (serial line) support

[*]   CSLIP compressed headers

二:ppp套件安装

下载ppp:ftp://ftp.samba.org/pub/ppp ×最新版本为2.4.4

将ppp-2.4.4.tar.gz解压至目录

×这里默认ppp源码目录为$(PPP)

#tar zxvf ppp-2.4.4.tar.gz

然后交叉编译ppp:

#cd $(PPP)

#./configure

#make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc ×这里指定交叉编译器

将ppp套件安装至嵌入式系统中:

×这里默认可执行文件在嵌入式系统下的目录为$(EMB_BIN)

#cp $(PPP)/chat/chat $(EMB_BIN)

#cp $(PPP)/pppd/pppd $(EMB_BIN)

#cp $(PPP)/pppdump/pppdump $(EMB_BIN)

#cp $(PPP)/pppstats/pppstats $(EMB_BIN)

×这里默认嵌入式系统的etc目录为$(EMB_ETC)

#mkdir $(EMB_ETC)/ppp

#cp $(PPP)/etc.ppp/* $(EMB_ETC)/ppp

三:ppp套件配置

$(EMB_BIN)/dial-on.sh (GPRS启动脚本)

#!/bin/sh

#define dial_on function

dial_on()

{

#test if pppd is running

pppd_stat=`ifconfig|grep ppp|wc -l|cut -b 7-7`

if [ $pppd_stat -gt 0 ]

then

echo "ppp connection's already started."

else

#close ethernet interface

ifconfig eth0 down

#ppp start

pppd modem /dev/ttyS1 57600 nocrtscts lock connect "chat -v -f /etc/ppp/gprs-connect" user "" noauth debug defaultroute

# pppd配置说明:

# ttyS1:连接GPRS模块SIM300的串口

# 57600:GPRS的拨号速率

# nocrtscts:无流控

# lock:锁定设备

# connect “chat –v –f /etc/ppp/gprs-connect”:GPRS连接脚本文件

# user “”:用户名,这里是无

# noauth:无需认证

# debug:输出调试信息

# defaultroute:此拨号连接作为默认路由

echo "ppp is starting..."

fi

}

#dial on gprs

dial_on

#wait for ppp's init

sleep 5

pppd_stat=`ifconfig|grep ppp|wc -l|cut -b 7-7`

if [ $pppd_stat -eq 0 ]

then

echo "trying 2nd time to call ppp"

dial_on

sleep 5

fi

pppd_stat=`ifconfig|grep ppp|wc -l|cut -b 7-7`

if [ $pppd_stat -eq 0 ]

then

echo "pppd error!"

echo "please check pppd's config files

$(EMB_BIN)/dial-off.sh (关闭GPRS连接脚本)

#!/bin/sh

#get pppd's pid

pid=`pidof pppd`

#if pppd process is running

if [ -n $pid ]

then

#kill pppd

kill $pid

#open the ethernet interface

ifconfig eth0 up

echo "ppp connection is closed."

else

echo "ppp connection isn't existed.

$(EMB_ETC)/ppp/gprs-connect (GPRS连接配置文件)

#GPRS连接超时设置

TIMEOUT 60

#若MODEM遇到BUSY、ERROR、NO CARRIER等信息时,停止拨号

ABORT "BUSY"

ABORT "ERROR"

ABORT "NO CARRIER"

#外送“AT”指令

'' AT

#当得到“OK”回应时,外送AT+CGDCONT=1,"IP","CMNET"命令

"OK" "AT+CGDCONT=1,/042IP/042,/042CMNET/042"

#当得到“OK”回应时,外送ATDT*99***1#命令

"OK" "ATDT*99***1#"

#当得到“CONNECT”回应时,拨号结束,程序退出

"CONNECT"

$(EMB_ETC)/ppp/pap-secrets (GPRS认证配置文件)

# Secrets for authentication using PAP

# client server secret IP addresses

'' * '' *

说明

(1)还需要在$(EMB_ETC)/ppp目录下创建指向$(EMB_ETC)/resolv.conf的链接,用于指定PPP连接的DNS。

(2)在ppp连接时,需要关闭eth连接。在脚本中已经设置好了,首先关闭eth连接,然后进行ppp连接,在ppp连接完成时,再开启eth连接。

(3)最好在系统中开启syslogd进程,这样在/var/log/messages文件中会记录GPRS进行拨号的DEBUG信息,便于调试。

(4)运行拨号脚本后,可以使用#ifconfig查看PPP连接信息。

笔记2:

arm上成功实现ppp拨号的脚本:

ppp-on:

#!/bin/sh

pppd modem -d -detach lock /dev/ttySAC0 19200 kdebug 4 file /etc/ppp/options crtscts noipdefault netmask 255.255.255.0 defaultroute connect /etc/ppp/chat-script

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

chat-script:

#!/bin/sh

exec chat -v /

TIMEOUT 5 /

ABORT "BUSY" /

ABORT "ERROR" /

ABORT "NO CARRIER" /

'' /rAT /

OK 'AT+CGDCONT=1,"IP","CMNET"' /

OK 'ATDT*99***1#' /

CONNECT '' /

设置DNS的resove.conf:

nameserver 211.136.20.203

nameserver 211.136.17.107

笔记3:

GPRS自动拨号脚本(真正的实时监控,断线自动重拨):

开机自动运行,实时监控,断线自动重拨

把文件传到DM里,设置文件属性为755,然后把启动路径加到init文件里即可

原设置为5秒去检测一次,是以1字节去PING

#!/bin/sh

#请把dns1,dns2修改成拼得通的DNS,开机自动运行,实时监控,断线自动重拨

dns1="211.95.193.97"

dns2="211.136.20.203"

sleep 8

#/bin/pppd call gprs-siem &

sleep 12

while true

do

ping -s 1 -c 1 $dns1 #去PING第一个DNS

if [ "$?" != "0" ] #假如PING不通

then

ping -s 1 -c 2 $dns2 #去PING第二个DNS

if [ "$?" != "0" ] #假如PING不通

then

killall pppd #结束PPPD进程

pppd call gprs-siem & #再去拨号

sleep 12 #等待12秒

sleep 5 #如果是PING DNS2通的话就直接等待5秒

fi

else

sleep 5 #如果是PING DNS1通的话就直接等待5秒(一般要设置多长时间去PING请改这里)

fi

done

代码简明!!它相当于在后台时时去PING一个DNS发现真正地掉线,它才会去重新拨号!!此版本经测试通过才发表。

**************************

* *

* The Gemini Project *

* *

**************************

www.tvrofans.org! \' v1 Y# R2 P2 h: K

welcome on your dreambox! - Kernel 2.6.9 (08:14:21).

dreambox login: root

BusyBox v1.01 (2007.10.23-19:23+0000) Built-in shell (ash)

Enter 'help' for a list of built-in commands.

root@dreambox:~> /bin/sh /var/etc/ppp/aa

root@dreambox:~> AT

OK

ATZ

OK

ATH

OK

ATE1

OK

AT+CGDCONT=1,"IP","cmnet"( f$ m0 V3 U' o

OK

ATD*99***1#

CONNECT

Serial connection established.

using channel 2

Using interface ppp0

Connect: ppp0 /dev/tts/0

Warning - secret file /etc/ppp/pap-secrets has world and/or group access

sent [LCP ConfReq id=0x1

]

rcvd [LCP ConfAck id=0x1

rcvd [LCP ConfReq id=0x3

]

sent [LCP ConfNak id=0x3 ]

rcvd [LCP ConfReq id=0x5

]

sent [LCP ConfAck id=0x5

]

Warning - secret file /etc/ppp/pap-secrets has world and/or group access

sent [PAP AuthReq id=0x1 user="beeline" password=]

rcvd [PAP AuthAck id=0x1 ""]

PAP authentication succeeded

sent [CCP ConfReq id=0x1 ]

sent [IPCP ConfReq id=0x1 ]

rcvd [LCP ProtRej id=0x6 80 fd 01 01 00 0f 1a 04 78 00 18 04 78]

sent [IPCP ConfReq id=0x1 ]

sent [IPCP ConfReq id=0x1 ]

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275420253.8 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275420253.8/275420253.8/275420253.8 ms

sent [IPCP ConfReq id=0x1 ]

sent [IPCP ConfReq id=0x1 ]

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275425386.3 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss9

round-trip min/avg/max = 275425386.3/275425386.3/275425386.3 ms

sent [IPCP ConfReq id=0x1 ]

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275430517.7 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275430517.7/275430517.7/275430517.7 ms

sent [IPCP ConfReq id=0x1 ]

sent [IPCP ConfReq id=0x1 ]

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275435653.2 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275435653.2/275435653.2/275435653.2 ms

sent [IPCP ConfReq id=0x1 ]

sent [IPCP ConfReq id=0x1 ]

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275440784.9 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275440784.9/275440784.9/275440784.9 ms

IPCP: timeout sending Config-Requests

sent [LCP TermReq id=0x2 "No network protocols running"]

rcvd [LCP TermAck id=0x2 "No network protocols running"]

Connection terminated.

Sending break to the modem

PDP context detached

Serial link disconnected.

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275445915.2 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275445915.2/275445915.2/275445915.2 ms

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275451048.9 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275451048.9/275451048.9/275451048.9 ms

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275456180.4 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275456180.4/275456180.4/275456180.4 ms

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275461314.4 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275461314.4/275461314.4/275461314.4 m

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275466446.2 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275466446.2/275466446.2/275466446.2 ms

PING 211.95.193.97 (211.95.193.97): 1 data bytes

9 bytes from 211.95.193.97: icmp_seq=0 ttl=244 time=275471577.9 ms

--- 211.95.193.97 ping statistics ---

1 packets transmitted, 1 packets received, 0% packet loss

round-trip min/avg/max = 275471577.9/275471577.9/275471577.9 ms

PING 211.95.193.97 (211.95.193.97): 1 data bytes

大家会问这样一直PING下去担心流量问题,浪费一些流量是垦定的,

不过我们是以1个字节去PING 加上返回的值一共是9个字节,也就是说5秒用9个字节

D1 U% ]& i

一个小时用9*12*60是一个小时6480字节=6。328125K

也就是说这样一个小时加6.33K的流量

大家还是担心的话可以改一下脚本,比如改60秒去PING一次啦,等等,都能有效去省流量!!

linux自动拨号脚本,arm中实现pppd连接GPRS上网的相关笔记,含GPRS自动拨号脚本(真正的实时监控,断线自动重拨)...相关推荐

  1. linux 模块 掉线重拨,arm中实现pppd连接GPRS上网的相关笔记,含GPRS自动拨号脚本(真正的实时监控,断线自动重拨)...

    在嵌入式Linux下GPRS上网方案 笔记1 硬/软件环境 基于S3C2410的嵌入式系统,COM1连接PC,COM2连接SIM300 GPRS模块. 该系统运行在Linux 2.6.14操作系统下, ...

  2. linux 4g wifi切换,Linux 开发板4G转WiFi热点 手机连接热点上网(二 4G模块的移植)...

    接着前一篇,本篇博文记录4G模块的移植. 我使用的模块是中兴ME3630模块,前面说了使用供应商或者官方的资料进行移植即可.一般来说4G模块的驱动,Linux内核也基本都有了,只需要设置一下optio ...

  3. Linux 开发板4G转WiFi热点 手机连接热点上网(三 WiFi模块的移植及AP的建立)

    这里对WiFi模块的驱动就不做详细介绍,本篇文章可能会涉及两款WiFi模块,一个是USB接口的WiFi模块,一个是SDIO接口的wifi模块,即AP6212,平台可能涉及爱特梅尔和三星的4418两个平 ...

  4. Linux 开发板4G转WiFi热点 手机连接热点上网(一 思路)

    很多时候我们需要一个这样的设备,建立一个wifi热点通过4G模块的流量进行上网. 为此这里记录自己实现它的经历. 为了达到目的,需要做下面两大部分: 1.4G模块的联网. 2.WiFi模块的AP热点建 ...

  5. python pandas 讲解ppt_Python中pandas的分析——包括代码实践,相关,解析,含,实战

    该文章代码均在jupyter Notebook中运行,且已安装re包 # 先读取数据 import pandas as pd f = open(r'C:\Users\qingfeng\Desktop\ ...

  6. shell编程实例 — 实现4G开机自动运行,实时监测,断线自动重拨》

    shell编程实例 - 实现4G开机自动运行,实时监测,断线自动重拨> 往事只能回味味道 于 2021-11-20 02:30:53 发布831 收藏 1 分类专栏: shell 文章标签: u ...

  7. 《shell编程实例 — 实现4G开机自动运行,实时监测,断线自动重拨》

    1.GPRS自动拨号脚本(真正的实时监控,断线自动重拨) 功能:开机自动运行,实时监控,断线自动重拨. 原设置为5秒去检测一次,是以1字节去PING. 1.GPRS自动拨号脚本(真正的实时监控,断线自 ...

  8. 【Groovy】Groovy 脚本调用 ( Linux 中调用 Groovy 脚本 | Windows 中调用 Groovy 脚本 )

    文章目录 前言 一.Linux 中调用 Groovy 脚本 二.Windows 中调用 Groovy 脚本 前言 在 命令行 , Groovy 脚本 , Groovy 类 , Java 类中 , 可以 ...

  9. 使用kibana可视化报表实时监控你的应用程序,从日志中找出问题,解决问题

    使用kibana可视化报表实时监控你的应用程序,从日志中找出问题,解决问题 参考文章: (1)使用kibana可视化报表实时监控你的应用程序,从日志中找出问题,解决问题 (2)https://www. ...

最新文章

  1. 第九集(第一部分)思科交换机配置文件及IOS备份还原
  2. 《数据中心设计与运营实战》——2.6 监控基础设施
  3. 沟通篇:产品经理如何与UI进行沟通
  4. 开源 非开源_开源突破“舒适区”
  5. 委托、Lambda表达式、事件系列06,使用Action实现观察者模式,体验委托和事件的区别...
  6. [codevs 1503]愚蠢的宠物(特殊的LCA)
  7. linux常用命令全集sed,Linux常用命令之find详解
  8. Opengl1.1绘图之GL_COLOR_LOGIC_OP
  9. IDEA 更改配色和主题样式
  10. Error(13) 解决LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
  11. 某程序员吐槽:刚过试用期就被辞退,理由竟是不转发朋友圈!
  12. 路由器交换机软件测试,你真的懂集线器、交换机、路由器之间的区别吗?
  13. 通俗易懂理解几何光学(四)光学系统中的光阑与光束限制
  14. 转给你身边的工程师!从零开始搭建一个完整AGV控制系统
  15. 发送邮箱验证码进行注册验证
  16. android 图片字体涂鸦,android 涂鸦功能
  17. 服务器重装系统鼠标没反应,重装系统鼠标键盘不能用怎么解决-重装系统鼠标键盘失灵的解决方法 - 河东软件园...
  18. 一些操作系统安全设置
  19. 2020年12月8日 阴
  20. JavaScript资源大全中文版(Awesome最新版--转载自张果老师博客)

热门文章

  1. 威纶通UI模板,威纶通,HMI模板,触摸屏模板,威纶通触摸屏
  2. 基于JS和vue的sql编辑器功能的实现
  3. BP神经网络的基本思想,一文搞定bp神经网络
  4. 微信小程序导航:官方文档+精品教程+demo集合(5月9日更新)
  5. 好用的开源 API 接口测试工具
  6. 全球及中国色觉传感器行业市场需求预测及发展趋势展望报告2022-2028年
  7. 传说中的猫扑 0 楼
  8. 夜,也可以很多彩——夜景拍摄技巧
  9. 计算机模拟技术在后处理中的应用,火灾模拟论文,关于计算机模拟技术在防火设计中的应用相关参考文献资料-免费论文范文...
  10. r7和i7处理器适合安Linux,R7与i7处理器区别