tagetage 发表于 2020-9-16 19:45

【树莓派4B测评】树莓派4驱动3G上网卡实现收发短信和无线上网

<div class='showpostmsg'><p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">手里有一个华为E353的3G上网卡,正好利用树莓派4来驱动一下。</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">华为E353参数:</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">网络模式:双模</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">总线接口:USB </span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">天线类型:内置天线 </span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">网络类型:3G:HSPA+,WCDMA </span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">频率范围:HSPA+/HSPA/UMTS:2100MH </span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">数据传输率:下行最大21.6Mbps 上行最大5.76Mbps</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">存储:存储卡支持Micro SD卡,最高可支持32GB</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-size:16.0pt"><span style="font-family:宋体">1</span></span><span style="font-size:16.0pt"><span style="font-family:宋体">,利用E353发送短信</span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">手机卡要取消PIN密码,然后查看一下短信中心号码是否正确。然后将SIM卡插入到上网卡中,在安装完gammu软件后再插入到树莓派的USB3.0的接口中,因为USB3.0的输出电流能大一些,免得供电不足。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后使用lsusb命令查看,看是否可以正确识别。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">lsusb</span><span style="font-family:宋体">后发现可以正确识别</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后打入命令(注意大小写),看是否可以发现三个设备,可以的话就不用安装usb-modeswitch了。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">ls /dev/ttyUSB*</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后安装gammu</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo apt-get install gammu</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">进行配置</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo gammu-config</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">端口选择/dev/ttyUSB0 (注意大小写),然后选择&ldquo;save&rdquo;,回车。</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后查看是否配置成功,成功的话会显示设备,制造商,型号,固件,IMEI,SIM IMSI信息。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo gammu --identify</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">发送短信(注意大小写),使用下列格式。由于编码问题,现在只能发送大小写英文和数字。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">echo &quot;Test SMS&quot; | sudo gammu sendsms TEXT 138xxxxxxxx</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">发送短信成功。</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-size:16.0pt"><span style="font-family:宋体">2</span></span><span style="font-size:16.0pt"><span style="font-family:宋体">,利用E353接收短信</span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">基本的短信发送功能实现后,就要试验接收短信的功能。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">安装 gammu-smsd</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo apt-get install gammu-smsd</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后编辑配置文件,将参数改为以下参数,具体的可参考英文网址https://wammu.eu/docs/manual/smsd/</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo nano /etc/gammu-smsdrc</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># Configuration file for Gammu SMS Daemon</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># Gammu library configuration, see gammurc(5)</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># Please configure this!</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">port = /dev/ttyUSB0</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">connection = at19200</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># Debugging</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">logformat = textall</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">&nbsp;</span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># SMSD configuration, see gammu-smsdrc(5)</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">service = files</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">logfile = syslog</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># Increase for debugging information</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">debuglevel = 0</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">&nbsp;</span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体"># Paths where messages are stored</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">inboxpath = /var/spool/gammu/inbox/</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">outboxpath = /var/spool/gammu/outbox/</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sentsmspath = /var/spool/gammu/sent/</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">errorsmspath = /var/spool/gammu/error/</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">更改后重启系统(重点),可以看到E353的的指示灯间隔几秒闪一下蓝色的指示灯,打电话提示忙,发短信就可以在/var/spool/gammu/inbox/这个路径下看到接收到的短信(默认的pi用户权限不够,可以设置权限或用管理员root权限访问),以年月日时间和电话号码为文件名的txt文件,打开就可以查看短信内容了。至此短信接收试验成功。</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-size:16.0pt"><span style="font-family:宋体">3</span></span><span style="font-size:16.0pt"><span style="font-family:宋体">,利用E353拨号上网</span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">安装PPP协议是用于拨号的必备协议</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo apt-get install ppp</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">安装拨号wvdial</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">这一步是要给你的树莓派安装拨号的管理软件,以便很好的操作拨号联网。 </span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo apt-get install wvdial</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后是配置</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo nano /etc/wvdial.conf</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">必须加入下列命令</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">Init3 = AT+CGDCONT=1,&quot;IP&quot;,&quot;3gnet&quot;</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">下面是可选的命令</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">Init4 = AT+CFUN=1</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后是Phone的号码为</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">Phone = *99#</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">用户名和密码可以随便写,但是不能不填。</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后敲入命令 sudo pon.wvdial 开始连接,耐心等待10秒,会看到3G上网卡的指示灯变为蓝色常亮,就是连接上网络了。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">如果成功, 会输出CONNECT等信息。</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">这时拔掉有线网线,这时3G上网卡是连接到网络了,但树莓派还是不能上网,因为路由没改。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">还需要敲入下列命令。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo route del -net 0.0.0.0</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">sudo route add default dev ppp0</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">然后用sudo route &ndash;n 看一下路由信息。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">这时候在ping一下网络,就能看到返回的数值了,我这里3G网还是太慢。</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:16.0pt"><span style="font-family:宋体">总结:</span></span><span style="font-family:宋体">安装了上网卡树莓派扩大了树莓派的网络使用范围,可以在外面进行联网操作。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">gammu</span><span style="font-family:宋体">接收短信后还可以执行自定义的脚本,可以做为短信控制器使用。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-family:宋体">gammu</span><span style="font-family:宋体">软件的功能非常强大,除了可以连接上网卡,还可以连接手机,将手机变成上网卡,对nokia手机的支持比较好。具体手机支持的列表见:https://wammu.eu/phones</span></span></span></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

freebsder 发表于 2020-9-16 22:07

<p>谢谢分享,3G卡似乎已经没啥用了</p>

okhxyyo 发表于 2020-9-17 09:29

freebsder 发表于 2020-9-16 22:07
谢谢分享,3G卡似乎已经没啥用了

<p>应该还是有一些场合需要使用的吧。毕竟像5G这种都是耗电收费之类的很高的。我觉得3G还是有市场的。</p>

tagetage 发表于 2020-9-17 10:19

freebsder 发表于 2020-9-16 22:07
谢谢分享,3G卡似乎已经没啥用了

<p>呵呵,我手里有什么就试验什么,太穷,没有4G上网卡。哈哈。</p>

freebsder 发表于 2020-9-17 13:44

okhxyyo 发表于 2020-9-17 09:29
应该还是有一些场合需要使用的吧。毕竟像5G这种都是耗电收费之类的很高的。我觉得3G还是有市场的。

<p>没了,要么2G,要么4G。&nbsp;</p>

<p>3G东西都买不到了。</p>

freebsder 发表于 2020-9-17 13:44

tagetage 发表于 2020-9-17 10:19
呵呵,我手里有什么就试验什么,太穷,没有4G上网卡。哈哈。

<p>可以搞搞2G,现在用2G的场景还很多的。</p>
页: [1]
查看完整版本: 【树莓派4B测评】树莓派4驱动3G上网卡实现收发短信和无线上网