xiyue521 发表于 2022-1-20 00:09

【安信可NB-IoT开发板EC-01F-Kit】三、HTTP获取时间

<div class='showpostmsg'><p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;今天做的是</font><font face="Calibri">EC01</font><font face="宋体">的</font><font face="Calibri">HTTP</font><font face="宋体">的</font><font face="Calibri">AT</font><font face="宋体">指令获取天气和时间,</font><font face="Calibri">HTTP</font><font face="宋体">是</font></span><span style="font-family:Calibri"><font face="宋体">超文本传输协议(</font>HyperText Transfer Protocol)<font face="宋体">是互联网上应用最为广泛的一种网络协议。</font></span><span style="font-family:宋体"><font face="Calibri">EC01</font><font face="宋体">模块集成了</font><font face="Calibri">http</font><font face="宋体">的一些</font><font face="Calibri">AT</font><font face="宋体">指令。</font></span></span></strong></span></p>

<p class="imagemiddle" style="text-align: center;"><span style="font-size:24px;"><strong></strong></span></p>

<p align="center" style="text-align:center"><span style="font-size:24px;"><strong>&nbsp;</strong></span></p>

<p style="text-align:left"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">主要有</font><font face="Calibri">7</font><font face="宋体">个指令,前四个是创建和开启连接获取数据指令,后面几个是服务器回复的消息头还有错误状态指示。</font></span></span></strong></span></p>

<p style="text-align:left"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">以下是几个时间和天气接口:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">时间获取:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:Calibri"><font face="宋体">天猫接口:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri">&nbsp;<a href="http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp"><span style="font-family:Calibri">http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp</span></a></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">示例:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:Calibri">{&quot;api&quot;:&quot;mtop.common.getTimestamp&quot;,&quot;v&quot;:&quot;*&quot;,&quot;ret&quot;:[&quot;SUCCESS::<font face="宋体">接口调用成功</font><font face="Calibri">&quot;],&quot;data&quot;:{&quot;t&quot;:&quot;1642606022154&quot;}}</font></span></span></strong></span></p>

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

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:Calibri"><font face="宋体">苏宁接口:</font></span><a href="http://quan.suning.com/getSysTime.do"><span style="font-family:Calibri">http://quan.suning.com/getSysTime.do</span></a></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">示例:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:Calibri">{&quot;sysTime2&quot;:&quot;2022-01-19 23:27:53&quot;,&quot;sysTime1&quot;:&quot;20220119232753&quot;}</span></span></strong></span></p>

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

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">其他:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><a href="http://api.k780.com:88/?app=life.time&amp;appkey=10003&amp;sign=b59bc3ef6191eb9f747dd4e83c99f2a4&amp;format=json"><span style="font-family:Calibri">http://api.k780.com:88/?app=life.time&amp;appkey=10003&amp;sign=b59bc3ef6191eb9f747dd4e83c99f2a4&amp;format=json</span></a></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">示例:</font></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:Calibri">{&quot;success&quot;:&quot;1&quot;,&quot;result&quot;:{&quot;timestamp&quot;:&quot;1642606086&quot;,&quot;datetime_1&quot;:&quot;2022-01-19 23:28:06&quot;,&quot;datetime_2&quot;:&quot;2022<font face="宋体">年</font><font face="Calibri">01</font><font face="宋体">月</font><font face="Calibri">19</font><font face="宋体">日 </font><font face="Calibri">23</font><font face="宋体">时</font><font face="Calibri">28</font><font face="宋体">分</font><font face="Calibri">06</font><font face="宋体">秒</font><span style="color:#000000"><span style="letter-spacing:0.0000pt"><span style="font-style:normal">&quot;,&quot;week_1&quot;:&quot;3&quot;,&quot;week_2&quot;:&quot;<font face="宋体">星期三</font><font face="Calibri">&quot;,&quot;week_3&quot;:&quot;</font><font face="宋体">周三</font><font face="Calibri">&quot;,&quot;week_4&quot;:&quot;Wednesday&quot;}}</font></span></span></span></span></span></strong></span></p>

<p style="text-align:justify"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><span style="color:#000000"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="宋体">可见获取的都是</font><font face="Calibri">json</font><font face="宋体">在单片机可以很好解析的。</font></span></span></span></span></span></strong></span></p>

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

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

<p class="imagemiddle" style="text-align: center;"><span style="font-size:24px;"><strong></strong></span></p>

<p style="text-align:left"><span style="font-size:24px;"><strong>&nbsp;</strong></span></p>

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

<p style="text-align:left"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">由于返回的是</font><font face="Calibri">16</font><font face="宋体">进制所以还要处理变为</font><font face="Calibri">ASCII</font></span></span></strong></span></p>

<p class="imagemiddle" style="text-align: center;"><span style="font-size:24px;"><strong></strong></span></p>

<p style="text-align:left"><span style="font-size:24px;"><strong>&nbsp;</strong></span></p>

<p style="text-align:left"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;其他两个类似,就是返回的都是</font><font face="Calibri">16</font><font face="宋体">进制,这样单片机确实不好处理,还要先转换成</font><font face="Calibri">ascii</font><font face="宋体">比如说返回</font><font face="Calibri">31</font><font face="宋体">,其实是字符&ldquo;</font><font face="Calibri">3</font><font face="宋体">&rdquo;&ldquo;</font><font face="Calibri">1</font><font face="宋体">&rdquo;,所以还要和&ldquo;</font><font face="Calibri">0</font><font face="宋体">&rdquo;作差,然后</font><font face="Calibri">3*16+1=0x31</font><font face="宋体">才是真正的数据。。</font></span></span></strong></span></p>

<p style="text-indent:21.0000pt; text-align:left"><span style="font-size:24px;"><strong><span style="font-family:Calibri"><span style="font-family:宋体"><font face="宋体">&nbsp;&nbsp;&nbsp;还有要注意的是</font><font face="Calibri">http</font><font face="宋体">只能创建一个实例就是只支持一个</font><font face="Calibri">http</font><font face="宋体">连接,要连接其他的线断开当前连接才行,还有这个连接存在时间限制,一会儿会自动断开,只要再次启动服务器连接就行了。</font></span></span></strong></span></p>

<p class="imagemiddle" style="text-align: center;"><span style="font-size:24px;"></span></p>

<p class="imagemiddle"><span style="font-size:24px;">&nbsp;&nbsp;&nbsp;&nbsp;今天的HTTP内容比较简单,就是只有几个AT指令获取时间,当然还可以获取天气什么的,除了获取GET还可以POST上传数据。后面几种模式比较少见主要是GET和POST。</span></p>

<p class="imagemiddle"><span style="font-size:24px;"> &nbsp;</span></p>

<p style="text-indent:21.0000pt; text-align:left"><span style="font-size:24px;"><strong>&nbsp;</strong></span></p>

<p style="text-indent:21.0000pt; text-align:left">&nbsp;</p>

<p style="text-indent:21.0000pt; text-align:left">&nbsp;</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>

xiyue521 发表于 2022-1-20 00:17

<p>天猫接口可以获取时间戳,精度到ms,但是因为网络延时,所以其实到秒级别就差不多课,可以利用time.h库解析出时间,可以作为物联网项目网络时间获取。</p>

<p></p>

<p> &nbsp;&nbsp;&nbsp;</p>
页: [1]
查看完整版本: 【安信可NB-IoT开发板EC-01F-Kit】三、HTTP获取时间