【RT-Thread软件包应用作品】多功能天气时钟
<p style="text-align: center;"><span style="font-size:20px;"><strong>多功能天气时钟-微信小程序版</strong></span></p><p> </p>
<p style="margin-left:36px"><span style="font-size:11.0pt"><strong><span lang="zh-CN" style="font-family:"Microsoft YaHei"">一、项目背景</span></strong><br />
<span lang="zh-CN" style="font-family:"Microsoft YaHei"">在不久前的一个早晨,我被一阵闹铃叫醒后,像往常一样去上班,到公司后发现很多同事都带了伞,于是乎打开了兜里的砖块</span><span lang="zh-CN" style="font-family:Calibri">(</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">手机</span><span lang="zh-CN" style="font-family:Calibri">)</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">,晚上回去的时候果然被淋了,虽然雨不是很大,但是被淋总是不爽,于是乎开始思考是否能做一个天气时钟,来拯救下我和像我一样出门不看天气的朋友,吧啦吧啦</span><span lang="zh-CN" style="font-family:Calibri">......</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">。</span><br />
<br />
<strong><span lang="zh-CN" style="font-family:"Microsoft YaHei"">二、项目技能点</span></strong><br />
<span lang="zh-CN" style="font-family:"Microsoft YaHei""> 本项目使用</span><span lang="zh-CN" style="font-family:Calibri">RT_Thread</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">国产操作系统开发,其丰富的软件包大大缩短了开发周期,本项目主要使用如下软件包</span><span lang="zh-CN" style="font-family:Calibri">:<br />
1.onenet:</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">设备通过</span><span lang="zh-CN" style="font-family:Calibri">mqtt</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">连接</span><span lang="zh-CN" style="font-family:Calibri">onenet<br />
2.webClient:</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">获取天气</span><br />
<span lang="zh-CN" style="font-family:Calibri"> 3.ntp:</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">同步网络时间</span><br />
<span lang="zh-CN" style="font-family:Calibri"> 4.cJSON:</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">解析小程序下发数据</span><br />
<br />
<strong><span lang="zh-CN" style="font-family:"Microsoft YaHei"">三、项目框架</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"> 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"> 定时时间到了蜂鸣器一直发出声音,直到用户按下K0按键,停止发声。</span></p>
<p style="margin-left:36px"><br />
<br />
<span style="font-size:11.0pt"><strong> <span lang="zh-CN" style="font-family:"Microsoft YaHei"">四、项目核心技术点</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:"Microsoft YaHei"">连接</span><span lang="en-US" style="font-family:Calibri">onenet</span></span></p>
<p style="margin-left:36px"><span style="font-size:11.0pt"> <span lang="en-US" style="font-family:"Microsoft YaHei"">理论上</span><span lang="en-US" style="font-family:Calibri">mqtt</span><span lang="en-US" style="font-family:"Microsoft YaHei"">连接</span><span lang="en-US" style="font-family:Calibri">onenet</span><span lang="en-US" style="font-family:"Microsoft YaHei"">应该是本项目比较</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">有挑战性的地方,好在</span><span lang="en-US" style="font-family:"Microsoft YaHei"">rt_thread官方提供</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">了软件包,使用</span><span lang="en-US" style="font-family:"Microsoft YaHei"">env工具配置后直接使用即可</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">。</span></span></p>
<p lang="en-US" style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:"Microsoft YaHei"">2.定时逻辑处理</span></span></p>
<p style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:"Microsoft YaHei""> 本项目创建了一个时间处理线程,线程起来后首先等待连网成功,然后调用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:"Microsoft YaHei"">3.天气获取逻辑处理</span></span></p>
<p style="margin-left:36px"><span style="font-size:11.0pt"><span style="font-family:"Microsoft YaHei""> 创建一个天气处理线程,线程起来后首先等待连网成功,然后获取一次天气情况,并发给onenet,小程序获取并显示。然后每隔一小时获取一次天气情况和同步ntp网络时间</span></span></p>
<pre>
<code>void weather_task_thread(void* arg)
{
int a =0;
uint8_t *p = &a;
USER_TIME_S current_time = { 0x00 };
// user_dev_time_flash_read();
while (4 != user_get_connect_status()->connect_status)
{
rt_thread_delay(1);
}
rt_thread_delay(3);
rt_kprintf("################################### start to get weather");
weather();
while ( 1 )
{
user_get_time(&current_time);
if ((0 == current_time.hour)&& (0 == current_time.minute) && (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:"Microsoft YaHei""> 小程序使用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> 五<span lang="zh-CN" style="font-family:"Microsoft YaHei"">、项目效果演示</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&page=1" style="background:#eee;margin-bottom:10px;" width="100%"></iframe></p>
<p lang="en-US"><strong> 六、程序源码</strong></p>
<p lang="en-US"> 小程序:<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> 设备端:<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>
<p>用8266做天气预报的比较多</p>
<p>厉害厉害👍</p>
wudianjun2001 发表于 2019-12-11 14:31
用8266做天气预报的比较多
<p>嗯嗯,是的。其实只要是WIFI都可以做的</p>
<p>好厉害的样子,不错!</p>
<p>hihi 您的作品获得了三等奖,记得观众今晚RTT的公众号</p>
Fillmore 发表于 2020-1-6 16:36
hihi 您的作品获得了三等奖,记得观众今晚RTT的公众号
<p>多谢~</p>
页:
[1]