一叶孤沙 发表于 2019-12-10 11:01

【RT-Thread软件包应用作品】多功能天气时钟

<p style="text-align: center;"><span style="font-size:20px;"><strong>多功能天气时钟-微信小程序版</strong></span></p>

<p>&nbsp;</p>

<p style="margin-left:36px"><span style="font-size:11.0pt"><strong><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">一、项目背景</span></strong><br />
&nbsp;&nbsp;&nbsp; <span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">在不久前的一个早晨,我被一阵闹铃叫醒后,像往常一样去上班,到公司后发现很多同事都带了伞,于是乎打开了兜里的砖块</span><span lang="zh-CN" style="font-family:Calibri">(</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">手机</span><span lang="zh-CN" style="font-family:Calibri">)</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">,晚上回去的时候果然被淋了,虽然雨不是很大,但是被淋总是不爽,于是乎开始思考是否能做一个天气时钟,来拯救下我和像我一样出门不看天气的朋友,吧啦吧啦</span><span lang="zh-CN" style="font-family:Calibri">......</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">。</span><br />
<br />
<strong><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">二、项目技能点</span></strong><br />
<span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;&nbsp;&nbsp;&nbsp;本项目使用</span><span lang="zh-CN" style="font-family:Calibri">RT_Thread</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">国产操作系统开发,其丰富的软件包大大缩短了开发周期,本项目主要使用如下软件包</span><span lang="zh-CN" style="font-family:Calibri">:<br />
&nbsp;&nbsp;&nbsp; 1.onenet:</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">设备通过</span><span lang="zh-CN" style="font-family:Calibri">mqtt</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">连接</span><span lang="zh-CN" style="font-family:Calibri">onenet<br />
&nbsp;&nbsp;&nbsp; 2.webClient:</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">获取天气</span><br />
<span lang="zh-CN" style="font-family:Calibri">&nbsp;&nbsp;&nbsp; 3.ntp:</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">同步网络时间</span><br />
<span lang="zh-CN" style="font-family:Calibri">&nbsp;&nbsp;&nbsp; 4.cJSON:</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">解析小程序下发数据</span><br />
<br />
<strong><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">三、项目框架</span></strong><br />
1.总体交互逻辑图如下所示:</span><br />
<span style="font-size:11.0pt">2.设备框图如下:</span></p>

<p style="margin-left:36px"></p>

<p style="margin-left:36px"><span style="font-size:11.0pt">2.1.LCD显示</span></p>

<p style="margin-left:36px"><span style="font-size:11.0pt">&nbsp; &nbsp; LCD显示DHT11采集的温湿度和当前时间</span><br />
</p>

<p style="margin-left:36px"><span style="font-size:11.0pt">2.2.蜂鸣器</span></p>

<p style="margin-left:36px"><span style="font-size:11.0pt">&nbsp; &nbsp; 定时时间到了蜂鸣器一直发出声音,直到用户按下K0按键,停止发声。</span></p>

<p style="margin-left:36px"><br />
<br />
<span style="font-size:11.0pt"><strong>&nbsp;<span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">四、项目核心技术点</span></strong><br />
<span lang="zh-CN" style="font-family:Calibri">1.</span><span lang="en-US" style="font-family:Calibri">mqtt</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">连接</span><span lang="en-US" style="font-family:Calibri">onenet</span></span></p>

<p style="margin-left:36px"><span style="font-size:11.0pt">&nbsp;&nbsp;&nbsp;&nbsp;<span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">理论上</span><span lang="en-US" style="font-family:Calibri">mqtt</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">连接</span><span lang="en-US" style="font-family:Calibri">onenet</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">应该是本项目比较</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">有挑战性的地方,好在</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">rt_thread官方提供</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">了软件包,使用</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">env工具配置后直接使用即可</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">。</span></span></p>

<p lang="en-US" style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">2.定时逻辑处理</span></span></p>

<p style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;&nbsp;&nbsp;&nbsp;本项目创建了一个时间处理线程,线程起来后首先等待连网成功,然后调用ntp接口同步网络时间,接下来进入while(1)循环,每500ms获取当前时间,和本地存储的定时器进行对比,如果当前时间等于保存的时间,开始执行闹钟动作,蜂鸣器发声。</span></span></p>

<p lang="en-US" style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">3.天气获取逻辑处理</span></span></p>

<p style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;&nbsp;&nbsp;&nbsp;创建一个天气处理线程,线程起来后首先等待连网成功,然后获取一次天气情况,并发给onenet,小程序获取并显示。然后每隔一小时获取一次天气情况和同步ntp网络时间</span></span></p>

<pre>
<code>void weather_task_thread(void* arg)
{
    int a =0;
        uint8_t *p = &amp;a;
        USER_TIME_S current_time = { 0x00 };

    // user_dev_time_flash_read();
    while (4 != user_get_connect_status()-&gt;connect_status)
    {
      rt_thread_delay(1);
    }
   
    rt_thread_delay(3);
    rt_kprintf("################################### start to get weather");
    weather();

        while ( 1 )
        {
                user_get_time(&amp;current_time);
      if ((0 == current_time.hour)&amp;&amp; (0 == current_time.minute) &amp;&amp; (0 == current_time.second) )
      {
            rt_kprintf("########################## sync weather and ntp time #####################\r\n");
            weather();
            user_sntp_time_synced();
      }

      rt_thread_mdelay(1000);
        }
}</code></pre>

<p style="margin-left:36px">4.小程序访问onenet</p>

<p lang="en-US" style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;&nbsp; &nbsp; 小程序使用http访问onenet,每隔3秒获取onenet数据,更新设备状态,直接操作onenet如下API接口控制和获取设备状态:</span></span><br />
</p>

<p lang="en-US" style="margin-left:36px"><span style="font-size:11.0pt"><strong>&nbsp;五<span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">、项目效果演示</span></strong></span></p>

<p lang="en-US" style="margin-left:36px"><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?aid=78712582&amp;page=1" style="background:#eee;margin-bottom:10px;" width="100%"></iframe></p>

<p lang="en-US"><strong>&nbsp;六、程序源码</strong></p>

<p lang="en-US">&nbsp;&nbsp;&nbsp;&nbsp;小程序:<a href="https://github.com/solitary-sand/wechat_miniprogram_demos/tree/master/wechat_smart_clock">https://github.com/solitary-sand/wechat_miniprogram_demos/tree/master/wechat_smart_clock</a></p>

<p>&nbsp; &nbsp; 设备端:<a href="https://github.com/solitary-sand/rt_thread_w601_app_rgb_smart_clock">https://github.com/solitary-sand/rt_thread_w601_app_rgb_smart_clock</a></p>

<p><br />
<b><font color="#5E7384">此内容由EEWORLD论坛网友<font size="3">一叶孤沙</font>原创,如需转载或用于商业用途需征得作者同意并注明出处</font></b></p>

wudianjun2001 发表于 2019-12-11 14:31

<p>用8266做天气预报的比较多</p>

btty038 发表于 2019-12-12 15:15

<p>厉害厉害&#128077;</p>

一叶孤沙 发表于 2019-12-12 15:24

wudianjun2001 发表于 2019-12-11 14:31
用8266做天气预报的比较多

<p>嗯嗯,是的。其实只要是WIFI都可以做的</p>

rgbgirl 发表于 2019-12-15 11:37

<p>好厉害的样子,不错!</p>

Fillmore 发表于 2020-1-6 16:36

<p>hihi 您的作品获得了三等奖,记得观众今晚RTT的公众号</p>

一叶孤沙 发表于 2020-1-8 19:26

Fillmore 发表于 2020-1-6 16:36
hihi 您的作品获得了三等奖,记得观众今晚RTT的公众号

<p>多谢~</p>
页: [1]
查看完整版本: 【RT-Thread软件包应用作品】多功能天气时钟