【项目介绍】
1.项目背景
物联网、人工智能以及机器学习在近几年中一直是最重要的趋势之一。其中物联网一直以惊人的速度发展,从用智能手机控制的智能恒温器到装有数百个传感器的先进无人驾驶汽车,从某种意义上来说改变了人类的生活形态。此外物联网正式被列入新课标中。
物联网作为一个新兴的工程实践性很强的专业,涉及的学科和专业知识较复杂,想更好的开展物联网教学,还需依托新技术和新产品。因此蘑菇云基于物联网解决方案推出多款产品,包括云雀气象仪、SCI数据采集模块、Mind+数据可视化等,有幸加入此次比赛,通过近几天的学习和摸索,决定配合行空板K10进行物联网可视化大屏的案例制作。
【制作过程】
一、硬件准备:
行空板K10是一款专为快速体验和学习人工智能而设计的开发学习板,100%采用国产芯片,知识产权自主可控,符合信息科技课程中编程学习、物联网及人工智能等教学需求。该板集成LCD彩屏、WiFi蓝牙、摄像头、麦克风、扬声器、RGB指示灯、多种传感器及丰富的扩展接口。凭借高度集成的板载资源,教学过程中无需额外连接其他设备,便可轻松实现传感器控制、物联网应用以及人脸识别、语音识别、语音合成等人工智能项目。
二、设计过程
1.注册天气API,获取数据
2.Mind+在线模式解析数据,获取天气数值不带引号的结果
3.导出结果并编号,保留有用数据,为上传模式做准备
4.MQTT设置
5.Mind+上传模式设置
6.Mind+可视化设置
步骤1 注册天气API,获取数据
1.打开http://www.tianqiapi.com/进行注册
2.用户登录,打开API文档,选择免费基础七日天气
3.复制天气数据
打开请求示例链接后,复制天气情况信息
步骤2 Mind+在线模式解析数据,获取天气数值不带引号的结果
1.打开Mind+软件,选择在线模式
2.编写程序如下(在天气情况里面粘贴上面复制的天气情况信息)
3.点击运行,获取天气字典列表和天气数据不带引号结果,如下
4.导出天气字典列表和天气数值不带引号结果
步骤3 导出结果复制到Excel中并编号,保留有用数据,为上传模式做准备
打开Excel,把导出的天气字典列表和天气数值不带引号结果的数值复制到Excel中并进行编号,如下图,红色部分是为上传模式里面的项做准备。
步骤4 MQTT设置
1.下载SIoT V2版本 :
下载链接:
腾讯微云下载(推荐):
链接: https://share.weiyun.com/6SFhgLQj
百度云盘下载:
链接:https://pan.baidu.com/s/17clVjJXWTZh02FteKy3mcA?pwd=mind
提取码:mind
阿里云盘下载:
https://www.aliyundrive.com/s/tCqwJwGtZzL
提取码: 3h4x
谷歌云盘下载:
链接: 点击下载
2.启动SIoT V2
在电脑上运行SIoT,在Windows上运行时容易出现网络连接问题,不推荐,优点是不依赖其他硬件。下载后win版本的SIoT V2解压,双击start SIoT.bat**即可启动新版SIoT,启动之后会弹出小黑窗启动服务器。注意运行的是start SIoT.bat而不是main.exe。
注意:启动时需要将SIoT添加到允许应用通过防火墙,勾选专用网络和公用网络,否则外部设备可能无法访问
打开后的界面
3.在浏览器输入 192.168.1.104:8080 即可打开网页端口,登录账号依然为siot,密码为dfrobot,打开后可以新建Topic或查看消息。
新建主题如下:
步骤5 Mind+上传模式设置
1.打开Mind+,选择上传模式,扩展中选择主控板里面的K10
2.设置解析天气字符串函数,编程如下:
3.主程序设置
(1)添加扩展—网络服务中的MQTT、Wi—Fi、HTTP、NTP
(2)Wi-Fi设置
(3)MQTT设置
(4)K10屏幕显示设置
效果如下:
(5)天气API获取
(6)MQTT可视化相关设置
步骤6 Mind+可视化设置
可视化编程设置如下:
可视化面板效果
附可视化面板里面的地图组件设置
经纬度的查询:打开https://lbs.amap.com/,点击开发支持,找到坐标拾取器打开
打开坐标拾取器网页以后,在搜索里面输入关键字,例如临沂红旗小学,点击搜索,就会在坐标获取结果里面出现坐标位置:118.31(经度),(纬度)35.06。
经度纬度获取以后,填写到地图组件对应的经度纬度输入框里面,地图就显示出你所在需要的位置了。当你拖动位置时候,经纬度会有微调。
完整程序如下:
/*!
* MindPlus
* esp32s3bit
*
*/
#include <DFString.h>
#include <SimpleList.h>
#include <DFRobot_Iot.h>
#include "unihiker_k10.h"
#include <DFRobot_HTTPClient.h>
// 动态变量
String mind_s_TianQi, mind_s_GaoDiWen1, mind_s_GaoDiWen2, mind_s_GaoDiWen3,
mind_s_GaoDiWen4, mind_s_GaoDiWen5, mind_s_GaoDiWen6, mind_s_GaoDiWen7,
mind_s_WenDu1, mind_s_WenDu2, mind_s_WenDu3, mind_s_WenDu4, mind_s_WenDu5,
mind_s_WenDu6, mind_s_WenDu7, mind_s_FengXiangFengLi1, mind_s_FengXiangFengLi2,
mind_s_FengXiangFengLi3, mind_s_FengXiangFengLi4, mind_s_FengXiangFengLi5,
mind_s_FengXiangFengLi6, mind_s_FengXiangFengLi7, mind_s_ZanShiJieGuo;
volatile float mind_n_JiShu, mind_n_KaiShiZiFuWeiZhi, mind_n_JiShu2;
SimpleList<String> mind_l_TianQiShuZhiBuDaiYinHaoJieGuo, mind_l_TianQiShuZhiJieGuo,
mind_l_TianQiZiDianLieBiao;
// 函数声明
void DF_JieXiTianQiZiFuChuan();
// 静态常量
const String topics[5] = {"","","","",""};
// 创建对象
DFRobot_Iot myIot;
DFRobot_HTTPClient http;
UNIHIKER_K10 k10;
uint8_t screen_dir=2;
AHT20 aht20;
// 主程序开始
void setup() {
k10.begin();
http.init();
k10.initScreen(screen_dir);
k10.creatCanvas();
myIot.wifiConnect("Hq123456", "Hq123456");
while (!myIot.wifiStatus()) {}
myIot.init("192.168.1.104","siot","9821932497609831","dfrobot", topics, 1883);
myIot.connect();
while (!myIot.connected()) {}
myIot.subscribeTopic("siot/预报日期1");
myIot.subscribeTopic("siot/预报日期2");
myIot.subscribeTopic("siot/预报日期3");
myIot.subscribeTopic("siot/预报日期4");
myIot.subscribeTopic("siot/预报日期5");
myIot.subscribeTopic("siot/预报日期6");
myIot.subscribeTopic("siot/预报日期7");
myIot.subscribeTopic("siot/天气情况1");
myIot.subscribeTopic("siot/天气情况2");
myIot.subscribeTopic("siot/天气情况3");
myIot.subscribeTopic("siot/天气情况4");
myIot.subscribeTopic("siot/天气情况5");
myIot.subscribeTopic("siot/天气情况6");
myIot.subscribeTopic("siot/天气情况7");
myIot.subscribeTopic("siot/温度1");
myIot.subscribeTopic("siot/温度2");
myIot.subscribeTopic("siot/温度3");
myIot.subscribeTopic("siot/温度4");
myIot.subscribeTopic("siot/温度5");
myIot.subscribeTopic("siot/温度6");
myIot.subscribeTopic("siot/温度7");
myIot.subscribeTopic("siot/风向风力1");
myIot.subscribeTopic("siot/风向风力2");
myIot.subscribeTopic("siot/风向风力3");
myIot.subscribeTopic("siot/风向风力4");
myIot.subscribeTopic("siot/风向风力5");
myIot.subscribeTopic("siot/风向风力6");
myIot.subscribeTopic("siot/风向风力7");
myIot.subscribeTopic("siot/室内温度");
myIot.subscribeTopic("siot/室内湿度");
myIot.subscribeTopic("siot/室内光强度");
myIot.subscribeTopic("siot/7天温度变化");
http.GET("http://v1.yiketianqi.com/free/week?unescape=1&appid=29988737&appsecret=Jipy6ZPN", 10000);
mind_s_TianQi = http.getString();
DF_JieXiTianQiZiFuChuan();
k10.canvas->canvasClear();
k10.canvas->canvasText("红旗小学在线气象站", 10, 30, 0x0000FF, k10.canvas->eCNAndENFont24, 50, true);
k10.canvas->canvasText("WIFI OK", 60, 100, 0x0000FF, k10.canvas->eCNAndENFont24, 50, false);
k10.canvas->canvasText("MQTT OK", 60, 175, 0x0000FF, k10.canvas->eCNAndENFont24, 50, false);
k10.canvas->canvasText(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[6-1], 55, 250, 0x0000FF, k10.canvas->eCNAndENFont24, 50, false);
k10.canvas->updateCanvas();
mind_s_GaoDiWen1 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[9-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[10-1]))));
mind_s_GaoDiWen2 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[16-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[17-1]))));
mind_s_GaoDiWen3 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[23-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[24-1]))));
mind_s_GaoDiWen4 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[30-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[31-1]))));
mind_s_GaoDiWen5 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[37-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[38-1]))));
mind_s_GaoDiWen6 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[44-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[45-1]))));
mind_s_GaoDiWen7 = (String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[51-1]) + String((String("|") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[52-1]))));
mind_s_WenDu1 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[9-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[10-1]))));
mind_s_WenDu2 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[16-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[17-1]))));
mind_s_WenDu3 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[23-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[24-1]))));
mind_s_WenDu4 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[30-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[31-1]))));
mind_s_WenDu5 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[37-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[38-1]))));
mind_s_WenDu6 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[44-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[45-1]))));
mind_s_WenDu7 = (String((String("最高温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[51-1]))) + String((String(" 最低温度:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[52-1]))));
mind_s_FengXiangFengLi1 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[11-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[12-1]))));
mind_s_FengXiangFengLi2 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[18-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[19-1]))));
mind_s_FengXiangFengLi3 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[25-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[26-1]))));
mind_s_FengXiangFengLi4 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[32-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[33-1]))));
mind_s_FengXiangFengLi5 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[39-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[40-1]))));
mind_s_FengXiangFengLi6 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[46-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[47-1]))));
mind_s_FengXiangFengLi7 = (String((String("风向:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[53-1]))) + String((String(" 风力等级:") + String(mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[54-1]))));
}
void loop() {
myIot.publish("siot/预报日期1", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[6-1], 1);
myIot.publish("siot/预报日期2", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[13-1]);
myIot.publish("siot/预报日期3", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[20-1]);
myIot.publish("siot/预报日期4", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[27-1]);
myIot.publish("siot/预报日期5", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[34-1]);
myIot.publish("siot/预报日期6", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[41-1]);
myIot.publish("siot/预报日期7", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[48-1]);
myIot.publish("siot/天气情况1", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[7-1]);
myIot.publish("siot/天气情况2", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[14-1]);
myIot.publish("siot/天气情况3", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[21-1]);
myIot.publish("siot/天气情况4", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[28-1]);
myIot.publish("siot/天气情况5", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[35-1]);
myIot.publish("siot/天气情况6", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[42-1]);
myIot.publish("siot/天气情况7", mind_l_TianQiShuZhiBuDaiYinHaoJieGuo[49-1]);
myIot.publish("siot/温度1", mind_s_WenDu1);
myIot.publish("siot/温度2", mind_s_WenDu2);
myIot.publish("siot/温度3", mind_s_WenDu3);
myIot.publish("siot/温度4", mind_s_WenDu4);
myIot.publish("siot/温度5", mind_s_WenDu5);
myIot.publish("siot/温度6", mind_s_WenDu6);
myIot.publish("siot/温度7", mind_s_WenDu7);
myIot.publish("siot/风向风力1", mind_s_FengXiangFengLi1);
myIot.publish("siot/风向风力2", mind_s_FengXiangFengLi2);
myIot.publish("siot/风向风力3", mind_s_FengXiangFengLi3);
myIot.publish("siot/风向风力4", mind_s_FengXiangFengLi4);
myIot.publish("siot/风向风力5", mind_s_FengXiangFengLi5);
myIot.publish("siot/风向风力6", mind_s_FengXiangFengLi6);
myIot.publish("siot/风向风力7", mind_s_FengXiangFengLi7);
myIot.publish("siot/7天温度变化", (String(mind_s_GaoDiWen1) + String((String(",") + String((String(mind_s_GaoDiWen2) + String((String(",") + String((String(mind_s_GaoDiWen3) + String((String(",") + String((String(mind_s_GaoDiWen4) + String((String(",") + String((String(mind_s_GaoDiWen5) + String((String(",") + String((String(mind_s_GaoDiWen6) + String((String(",") + String(mind_s_GaoDiWen7)))))))))))))))))))))))), 1);
myIot.publish("siot/室内温度", aht20.getData(AHT20::eAHT20TempC));
myIot.publish("siot/室内湿度", aht20.getData(AHT20::eAHT20HumiRH));
myIot.publish("siot/室内光强度", k10.readALS());
delay(1000);
}
// 自定义函数
void DF_JieXiTianQiZiFuChuan() {
mind_l_TianQiShuZhiJieGuo.clear();
mind_l_TianQiZiDianLieBiao.clear();
mind_n_JiShu = 1;
mind_n_KaiShiZiFuWeiZhi = 2;
for (int index = 0; index < (String(mind_s_TianQi).length()); index++) {
if (((String((String(String(mind_s_TianQi).charAt(mind_n_JiShu-1)))).indexOf(String(",")) != -1))) {
mind_l_TianQiZiDianLieBiao.push_back((dfstring.substring(mind_s_TianQi,0,mind_n_KaiShiZiFuWeiZhi,0,(mind_n_JiShu - 1))));
mind_n_KaiShiZiFuWeiZhi = (mind_n_JiShu + 1);
}
mind_n_JiShu += 1;
}
mind_l_TianQiZiDianLieBiao.push_back((dfstring.substring(mind_s_TianQi,0,mind_n_KaiShiZiFuWeiZhi,0,((String(mind_s_TianQi).length()) - 1))));
mind_n_JiShu = 1;
for (int index = 0; index < mind_l_TianQiZiDianLieBiao.size(); index++) {
mind_n_JiShu2 = 1;
for (int index = 0; index < (String(mind_l_TianQiZiDianLieBiao[mind_n_JiShu-1]).length()); index++) {
if (((String((String(String(mind_l_TianQiZiDianLieBiao[mind_n_JiShu-1]).charAt(mind_n_JiShu2-1)))).indexOf(String(":")) != -1))) {
if (((String((String(String(mind_l_TianQiZiDianLieBiao[mind_n_JiShu-1]).charAt((mind_n_JiShu2 - 1)-1)))).indexOf(String("\"")) != -1))) {
mind_l_TianQiShuZhiJieGuo.push_back((dfstring.substring(mind_l_TianQiZiDianLieBiao[mind_n_JiShu-1],0,(mind_n_JiShu2 + 1),0,(String(mind_l_TianQiZiDianLieBiao[mind_n_JiShu-1]).length()))));
}
}
mind_n_JiShu2 += 1;
}
mind_n_JiShu += 1;
}
mind_l_TianQiShuZhiBuDaiYinHaoJieGuo.clear();
mind_n_JiShu = 1;
for (int index = 0; index < mind_l_TianQiShuZhiJieGuo.size(); index++) {
if (((String((String(String(mind_l_TianQiShuZhiJieGuo[mind_n_JiShu-1]).charAt(1-1)))).indexOf(String("\"")) != -1))) {
mind_s_ZanShiJieGuo = (dfstring.substring(mind_l_TianQiShuZhiJieGuo[mind_n_JiShu-1],0,2,0,((String(mind_l_TianQiShuZhiJieGuo[mind_n_JiShu-1]).length()) - 1)));
for (int index = 0; index < 2; index++) {
if ((((String((String(String(mind_s_ZanShiJieGuo).charAt((String(mind_s_ZanShiJieGuo).length())-1)))).indexOf(String("\"")) != -1)) || ((String((String(String(mind_s_ZanShiJieGuo).charAt((String(mind_s_ZanShiJieGuo).length())-1)))).indexOf(String("}")) != -1)))) {
mind_s_ZanShiJieGuo = (dfstring.substring(mind_s_ZanShiJieGuo,0,1,0,((String(mind_s_ZanShiJieGuo).length()) - 1)));
}
}
mind_l_TianQiShuZhiBuDaiYinHaoJieGuo.push_back(mind_s_ZanShiJieGuo);
}
else {
mind_l_TianQiShuZhiBuDaiYinHaoJieGuo.push_back(mind_l_TianQiShuZhiJieGuo[mind_n_JiShu-1]);
}
mind_n_JiShu += 1;
}
}
最终可视化大屏如下图
附件
评论