【安信可NB-IoT开发板EC-01F-Kit】二、TCP连接与NATAPP内网穿透
<div class='showpostmsg'><h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">今天测试下</font><font face="Arial">TCP</font><font face="黑体">连接与数据收发</font></span></span></span></span></strong></h6><h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="Arial">1.</font><font face="黑体">首先发送几个基本的</font><font face="Arial">AT</font><font face="黑体">指令注册并激活网络连接:</font></span></span></span></span></strong></h6>
<p class="imagemiddle" style="text-align: center;"><strong></strong></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"> </span></strong></h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="Arial">2.</font><font face="黑体">接下来就</font><font face="Arial">ping</font><font face="黑体">下百度:</font></span></span></span></span></strong></h6>
<p class="imagemiddle" style="text-align: center;"><strong></strong></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"> </span></strong></h6>
<p class="imagemiddle" style="text-align: center;"><strong></strong></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"> </span></strong></h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">左边是我的电脑接的网线,右边是模组,差的还是挺大的,不过我们应用的是物联网小速率传输可以了。</font></span></span></span></span></strong></h6>
<p style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">3.现在正式创建</font><font face="Arial">TCP</font><font face="黑体">连接:</font></span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">①</font></span></span><span style="font-family:Arial"><span style="color:#000000">AT+SKTCREATE </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">创建</font></span></span><span style="font-family:Arial"><span style="color:#000000">Socket </span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">该命令会在</font> </span></span><span style="font-family:Arial"><span style="color:#000000">UE </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">端创建一个基于</font> </span></span><span style="font-family:Arial"><span style="color:#000000">TCP </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">或者</font> </span></span><span style="font-family:Arial"><span style="color:#000000">UDP </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">的</font> </span></span><span style="font-family:Arial"><span style="color:#000000">socket</span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">。</font></span></span><span style="font-family:Arial"><span style="color:#000000">UE </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">支持最多同时创建</font> </span></span><span style="font-family:Arial"><span style="color:#000000">7 </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">个</font> </span></span><span style="font-family:Arial"><span style="color:#000000">TCP </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">或者</font></span></span><span style="font-family:Arial"><span style="color:#000000">UDP socket</span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">,超出会返回如果发生错误</font></span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">我们选择</font>IPV4,TCP协议:</span></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-align:justify"> </p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:left"><strong><span style="font-size:24px;"> <span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">连续创建会返回对应</font></span><span style="font-family:Arial"><span style="color:#000000">Socket</span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">文件描述符</font></span></span></span></span></strong></p>
<p style="text-align:left"> </p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">②</font></span></span><span style="font-family:Arial"><span style="color:#000000">AT+SKTCONNECT </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">连接远程服务器和端口</font> </span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">对于</font> </span></span><span style="font-family:Arial"><span style="color:#000000">TCP, </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">该命令将会执行连接到远程服务器地址和端口。</font> </span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">对于</font></span></span><span style="font-family:Arial"><span style="color:#000000">UDP</span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">,该命令将会保存远程服务器的地址和端口号,用于后续数据的发送。</font> </span></span></span></span></strong></p>
<p style="text-align:left"> </p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">利用安信可提供的服务器连接服务器:</font></span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span class="15"><span style="background:#ffffff"><span style="font-family:Arial"><span style="color:#4d4d4d"><span style="letter-spacing:0.0000pt"><span style="font-weight:bold"><span style="font-style:normal"><font face="Arial">安信可透传云</font></span></span></span></span></span><span style="font-family:宋体"><span style="color:#4d4d4d"><span style="letter-spacing:0.0000pt"><span style="font-weight:bold"><span style="font-style:normal"><font face="宋体">:</font></span></span></span></span></span></span></span><a href="http://tt.ai-thinker.com:8000/ttcloud"><u><span class="16"><span style="font-family:宋体"><span style="color:#0000ff"><span style="text-decoration:underline">http://tt.ai-thinker.com:8000/ttcloud</span></span></span></span></u></a></span></span></strong></p>
<p style="text-align:left"> </p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-align:left"> </p>
<h2 style="margin-top:5px; margin-bottom:8px; text-indent:0.0000pt; padding:0pt 0pt 0pt 0pt ; text-align:left"><strong><span style="font-size:24px;"><span style="background:#ffffff"><span style="font-family:宋体"><span style="font-weight:bold"><span style="font-family:宋体"><span style="font-weight:bold"><font face="宋体">要注意:</font></span></span><span style="background:#f7f7f7"><span style="font-family:'Segoe UI'"><span style="letter-spacing:0.0000pt"><span style="font-weight:bold"><span style="font-style:normal">3分钟内无客户端接入</span></span></span></span><span style="font-family:宋体"><span style="letter-spacing:0.0000pt"><span style="font-weight:bold"><span style="font-style:normal"><font face="宋体">要</font></span></span></span></span><span style="font-family:'Segoe UI'"><span style="letter-spacing:0.0000pt"><span style="font-weight:bold"><span style="font-style:normal"><font face="Segoe UI">刷新重新开启</font></span></span></span></span></span></span></span></span></span></strong></h2>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:justify"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">③</font></span></span><span style="font-family:Arial"><span style="color:#000000">AT+SKTSTATUS </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">获取</font></span></span><span style="font-family:Arial"><span style="color:#000000">socket </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">状态</font> </span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">该命令获取相应文件描述符的</font> </span></span><span style="font-family:Arial"><span style="color:#000000">socket </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">状态</font></span></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">表示已经连接上</font></span></span></span></strong></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">接收数据:</font></span></span></span></span></strong></h6>
<p class="imagemiddle" style="text-align: center;"></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"> </span></strong></h6>
<p class="imagemiddle" style="text-align: center;"></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"> </span></strong></h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">不过接收的是</font><font face="Arial">16</font><font face="黑体">进制还要转</font><font face="Arial">ascii</font><font face="黑体">才行。</font></span></span></span></span></strong></h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">发送数据:</font></span></span></span></span></strong></h6>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">④</font></span></span><span style="font-family:Arial"><span style="color:#000000">AT+SKTSEND </span></span><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">发送数据</font> </span></span></span></span></strong></p>
<p style="text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><font face="宋体">发送一定长度的数据到远程服务器地址和端口中。</font></span></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="Arial">4.</font><font face="黑体">利用</font><font face="Arial">NATAPP</font><font face="黑体">内网穿透进行本地电脑与模块</font><font face="Arial">TCP</font><font face="黑体">通信</font><font face="Arial">:</font></span></span></span></span></strong></h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">就是将我们本地电脑局域网</font><font face="Arial">IP</font><font face="黑体">(</font><font face="Arial">192.168.0.x</font><font face="黑体">)映射到公网</font><font face="Arial">IP</font><font face="黑体">上</font></span></span></span></span></strong></h6>
<h6 style="text-indent:21.0000pt; margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">上文我们用安信可透传云实现电脑和模块通信,实际上是别人的网页,而且端口号刷新完会改变,现在我们要实现本地电脑和模块通信。</font></span></span></span></span></strong></h6>
<h6 style="text-indent:21.0000pt; margin-top:16px; margin-bottom:4px; text-align:left"><strong><span style="font-size:24px;"><span style="132%"><span style="font-family:Arial"><span style="font-family:黑体"><font face="黑体">因为</font><font face="Arial">192.168.x.x</font><font face="黑体">为局域网</font><font face="Arial">ip</font><font face="黑体">,路由器没办法转发这个</font><font face="Arial">ip</font><font face="黑体">的数据到</font><font face="Arial">intermet</font><font face="黑体">,所以不能直接和模块通信,所以我们要先建立一条局域网到公网的链路,内网穿透就是利用有固定公网 </font><font face="Arial">IP </font><font face="黑体">地址的服务器做一个中转站,在互联网上打通一条点对点的专用隧道用来转发数据。</font></span></span></span></span></strong></h6>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">我选择</font><font face="Calibri">NATAPP</font><font face="宋体">:</font></span><a href="http://natapp.cn/"><u><span class="16"><span style="font-family:宋体"><span style="color:#0000ff"><span style="text-decoration:underline"><font face="宋体">http://natapp.cn/</font></span></span></span></span></u></a></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">下载客户端:</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"> </p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">得到两个文件,进入</font><font face="Calibri">config</font><font face="宋体">文件:</font></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">启动穿透:</font></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">这样就建立了本地和公网</font><font face="Calibri">ip</font><font face="宋体">的链路</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">因为模组连接</font><font face="Calibri">TCP</font><font face="宋体">要</font><font face="Calibri">IP</font><font face="宋体">,不能用域名,先域名解析:</font></span></span></span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p class="imagemiddle" style="text-align: center;"> </p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> 如上文建立TCP连接:</span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p class="imagemiddle" style="margin-left: 40px;"><strong><span style="font-size:24px;">接收:</span></strong></p>
<p class="imagemiddle" style="text-align: center;"> </p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> 发送:</span></strong></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"> </span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">至此本地与模组</font><font face="Calibri">TCP</font><font face="宋体">通信完成!!</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"><strong><span style="font-size:24px;"><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">不过这个NATAPP端口还是会改变,毕竟是免费的,有条件可以租个服务器和公网ip就有固定的端口了。</font></span></span></span></strong></p>
<p style="text-indent:21.0000pt; text-align:left"> </p>
<p style="text-indent:21.0000pt; text-align:left"> </p>
<p style="text-align:left"> </p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"> </h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"> </h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"> </h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"> </h6>
<h6 style="margin-top:16px; margin-bottom:4px; text-align:left"> </h6>
</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>
页:
[1]