【安信可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="宋体"> 今天做的是</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> </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"> <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">{"api":"mtop.common.getTimestamp","v":"*","ret":["SUCCESS::<font face="宋体">接口调用成功</font><font face="Calibri">"],"data":{"t":"1642606022154"}}</font></span></span></strong></span></p>
<p style="text-align:justify"> </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">{"sysTime2":"2022-01-19 23:27:53","sysTime1":"20220119232753"}</span></span></strong></span></p>
<p style="text-align:justify"> </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&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json"><span style="font-family:Calibri">http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&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">{"success":"1","result":{"timestamp":"1642606086","datetime_1":"2022-01-19 23:28:06","datetime_2":"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">","week_1":"3","week_2":"<font face="宋体">星期三</font><font face="Calibri">","week_3":"</font><font face="宋体">周三</font><font face="Calibri">","week_4":"Wednesday"}}</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"> </p>
<p style="text-align:justify"> </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> </strong></span></p>
<p style="text-align:left"> </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> </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">16</font><font face="宋体">进制,这样单片机确实不好处理,还要先转换成</font><font face="Calibri">ascii</font><font face="宋体">比如说返回</font><font face="Calibri">31</font><font face="宋体">,其实是字符“</font><font face="Calibri">3</font><font face="宋体">”“</font><font face="Calibri">1</font><font face="宋体">”,所以还要和“</font><font face="Calibri">0</font><font face="宋体">”作差,然后</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="宋体"> 还有要注意的是</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;"> 今天的HTTP内容比较简单,就是只有几个AT指令获取时间,当然还可以获取天气什么的,除了获取GET还可以POST上传数据。后面几种模式比较少见主要是GET和POST。</span></p>
<p class="imagemiddle"><span style="font-size:24px;"> </span></p>
<p style="text-indent:21.0000pt; text-align:left"><span style="font-size:24px;"><strong> </strong></span></p>
<p style="text-indent:21.0000pt; text-align:left"> </p>
<p style="text-indent:21.0000pt; text-align:left"> </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> <p>天猫接口可以获取时间戳,精度到ms,但是因为网络延时,所以其实到秒级别就差不多课,可以利用time.h库解析出时间,可以作为物联网项目网络时间获取。</p>
<p></p>
<p> </p>
页:
[1]