关注分享主机优惠活动
国内外VPS云服务器

由ESP3zhujipindao串口屏幕(ESP32网络摄像机)组成的疫情监控平台

摘要:采用硬件组件作为主控。该模型是用于显示的连续屏幕。模型到模型模块用于调试。第二,在官网设置和下载开发环境。

一、硬件组成

Esp32用作主机。(型号:esp32_devkitc_v4)串行屏幕用于显示。(型号:TJC3224T024_011)Usb转ttl模块用于调试。二、开发环境(Arduino IDE)

去https://www.arduino.cc/en/software,官网下载Arduino IDE。安装后,界面如下:构建esp32开发环境:点击文件/首选项:

输入:https://dl.espressif.com/dl/package_esp32_index.json保存并重启Arduino。

选择工具/开发板管理器

搜索esp32并下载安装。

完成后,您可以看到esp32

3.向api接口发送HTTP请求并解析它

1.在Arduino中安装所需的库文件:单击工具/管理库。

在搜索框中输入WiFi,选择要安装的库文件。

2.设备初始化代码

#include //用于连接WiFi网络#include //用于向服务器请求数据信息#include //用于解析返回的json数据const char * dssid = " ssid//您的网络名称const char * password = " password//你的网络密码void setup() {//做设备初始化serial . begin(115200);//将串口波特率初始化为115200 serial . println(" ");//打印一个空行WiFi.begin(dssid,password);//连接指定wifi while (WiFi.status()!= WL _连接){延迟(500);Serial.print(" . ");}//连接返回...Serial.println("WiFi已连接!");//WiFi连接成功//把你的设置代码放在这里,要运行一次:} 3。请求数据并返回。

void loop(){ http client http;//建立HTTPClient对象http . begin(" https://lab . isaaclin . cn/ncov/API/overall ");//发送http数据请求int httpCode = http。GET()到此URL//保存返回的状态码//把你的主代码放在这里,要重复运行:If(HTTP CODE > 0)//如果状态码大于0,则请求过程没有异常{if (httpCode == HTTP_CODE_OK) //请求被服务器正常响应,相当于HTTP CODE = = 200 { string payload = HTTP . getstring();//读取服务器返回的响应体数据serial . println(payload);//串口打印返回的数据}} else {//没有得到响应,返回错误码serial.printf ("[http] get...失败,错误:% s/n ",http.errortostring (httpcode)。c _ str());} http . end();//结束当前连接延迟(1200000);//每两分钟发送一次请求,过于频繁可能导致ip被接口阻塞} 4。下载验证:开发板型号选择:

PS:端口根据自身情况选择。

串行端口打印结果如下:

返回的数据是:

5.json解析返回的数据:定义结构。

Struct ncov_data{ //此结构用于保存数据long currentConfirmedCount//现有已确认的long currentConfirmedIncr//对比昨天的long confirmedCountlong confirmedIncr累计诊断;//long curedCount对比昨天;//长期固化的累积固化;//与昨天的long seriousCount相比;//现有的无症状长seriousIncr//相比昨天的长deadCount//累计死亡长deadIncr//String updateTime与昨天相比;//更新时间};Json初始化

ncov_data中国_ data;//国内疫情数据ncov _ data World _ data//国外疫情数据DynamicJsonDocument doc(1000);//创建DynamicJsonDocument对象deserializeJson(doc,payload);//反序列化数据JSON object results _ 0 = doc[" results "][0];解析数据分配

China _ data . currentConfirmedCount = results _ 0[" currentConfirmedCount "]。as();China _ data . currentconfirmed incr = results _ 0[" currentconfirmed incr "]。as();China _ data . confirmed count = results _ 0[" confirmed count "]。as();China _ data . confirmed incr = results _ 0[" confirmed incr "]。as();China _ data . cured count = results _ 0[" cured count "]。as();China _ data . cured incr = results _ 0[" cured incr "]。as();China _ data . dead count = results _ 0[" dead count "]。as();China _ data . dead incr = results _ 0[" dead incr "]。as();China _ data . serious count = results _ 0[" serious count "]。as();China _ data . serious incr = results _ 0[" serious incr "]。as();world _ data . currentConfirmedCount = results _ 0[" global statistics "][" currentConfirmedCount "]。as();world _ data . currentconfirmed incr = results _ 0[" global statistics "][" currentconfirmed incr "]。as();world _ data . confirmed count = results _ 0[" global statistics "][" confirmed count "]。as();world _ data . confirmed incr = results _ 0[" global statistics "][" confirmed incr "]。as();world _ data . cured count = results _ 0[" global statistics "][" cured count "]。as();world _ data . cured incr = results _ 0[" global statistics "][" cured incr "]。as();world _ data . dead count = results _ 0[" global statistics "][" dead count "]。as();world _ data . dead incr = results _ 0[" global statistics "][" dead incr "]。as();串行端口打印

serial . println(" ");serial . println(" --------------------------------------------------4 serial . print("现有诊断:");serial . println(China _ data . currentconfirmed count);Serial.print("累积诊断:");serial . println(China _ data . confirmed count);Serial.print("累积固化:");serial . println(China _ data . cured count);Serial.print("无症状存在:");serial . println(China _ data . serious count);Serial.print("累计死亡:");serial . println(China _ data . dead count);serial . println(" ----------------------------------------serial . print("现有诊断:");serial . println(World _ data . currentconfirmed count);Serial.print("累积诊断:");serial . println(World _ data . confirmed count);Serial.print("累积固化:");serial . println(World _ data . cured count);Serial.print("累计死亡:");serial . println(World _ data . dead count);

4.将数据发送到串行屏幕并显示。

1.下载USART HMI串行屏幕软件,构建您喜欢的ui。你可以自己跳过这个过程。

2.Arduino代码:串行端口定义

#定义TJC Serial2 //串口屏幕将发送和接收串口定义为串口2初始化。

tjc . begin(115200);//将发送和接收串口的波特率初始化为115200 while(tjc . read()> = 0);//等待串口屏幕连接成功的字符串定义。

char str 1[20];char str 2[20];char str 3[20];char str 4[20];char str 5[20];char str 6[20];char str 7[20];char str 8[20];char str 9[20];char str 10[20];Sprintf格式拼接

sprintf(str1," n0.val=%d/xff/xff/xff ",China _ data . current confirmed count);sprintf(str6," n5.val=%d/xff/xff/xff ",China _ data . current confirmed incr);sprintf(str2," n1.val=%d/xff/xff/xff ",China _ data . confirmed count);sprintf(str7," n6.val=%d/xff/xff/xff ",China _ data . confirmed incr);sprintf(str3," n2.val=%d/xff/xff/xff ",China _ data . cured count);sprintf(str8," n7.val=%d/xff/xff/xff ",China _ data . cured incr);sprintf(str4," n3.val=%d/xff/xff/xff ",China _ data . dead count);sprintf(str9," n8.val=%d/xff/xff/xff ",China _ data . dead incr);sprintf(str5," n4.val=%d/xff/xff/xff ",China _ data . serious count);sprintf(str10," n9.val=%d/xff/xff/xff ",China _ data . serious incr);数据传输

tjc . print(str 1);tjc . print(str 2);tjc . print(str 3);tjc . print(str 4);tjc . print(str 5);tjc . print(str 6);tjc . print(str 7);tjc . print(str 8);tjc . print(str 9);tjc . print(str 10);3.将esp32的rx和tx引脚分别连接到串行屏幕的tx和rx引脚。

4.参考文章:疫情监测三部曲——在STM32F103 MCU(裸机版)-云+社区-腾讯云(tencent.com)上的实现

动词 (verb的缩写)完全码

#include //用于连接WiFi网络#include //用于向服务器请求数据信息#include //用于解析返回的json数据#定义TJC串口2 //串口屏幕发送和接收串口定义为串口2const char * dssid = " DOG//您的网络名称constchar * password = " 6666666//您的网络密码结构ncov_data{ //该结构用于存储数据long currentConfirmedCount//现有已确认的long currentConfirmedIncr//对比昨天的long confirmedCountlong confirmedIncr累计诊断;//long curedCount对比昨天;//长期固化的累积固化;//与昨天的long seriousCount相比;//现有的无症状长seriousIncr//相比昨天的长deadCount//累计死亡长deadIncr//String updateTime与昨天相比;//更新时间};Void setup() {//做设备初始化serial . begin(115200);//将串口波特率初始化为115200 tjc . begin(115200);//初始化发送和接收串口的波特率为115200 while(tjc . read()> = 0);//等待串口屏幕连接成功serial . println(" ");//打印一个空行WiFi.begin(dssid,password);//连接指定wifi while (WiFi.status()!= WL _连接){延迟(500);Serial.print(" . ");}//连接返回...Serial.println("WiFi已连接!");//WiFi连接成功//把你的设置代码放在这里,要运行一次:} void loop () {http客户端http;//建立HTTPClient对象http . begin(" https://lab . isaaclin . cn/ncov/API/overall ");//发送http数据请求int httpCode = http。GET()到此URL//保存返回的状态码//把你的主代码放在这里,要重复运行:If(HTTP CODE > 0)//如果状态码大于0,则请求过程没有异常{if (httpCode == HTTP_CODE_OK) //请求被服务器正常响应,相当于HTTP CODE = = 200 { string payload = HTTP . getstring();//读取服务器返回的响应体数据serial . println(payload);//串口打印返回的数据ncov _ data China _ data//国内疫情数据ncov _ data World _ data//国外疫情数据DynamicJsonDocument doc(1000);//创建DynamicJsonDocument对象deserializeJson(doc,payload);//反序列化数据JSON object results _ 0 = doc[" results "][0];//将解析后的数据赋给结构China _ data . current confirmidcount = results _ 0[" current confirmidcount "]。as();China _ data . currentconfirmed incr = results _ 0[" currentconfirmed incr "]。as();China _ data . confirmed count = results _ 0[" confirmed count "]。as();China _ data . confirmed incr = results _ 0[" confirmed incr "]。as();China _ data . cured count = results _ 0[" cured count "]。as();China _ data . cured incr = results _ 0[" cured incr "]。as();China _ data . dead count = results _ 0[" dead count "]。as();China _ data . dead incr = results _ 0[" dead incr "]。as();China _ data . serious count = results _ 0[" serious count "]。as();China _ data . serious incr = results _ 0[" serious incr "]。as();world _ data . currentConfirmedCount = results _ 0[" global statistics "][" currentConfirmedCount "]。as();world _ data . currentconfirmed incr = results _ 0[" global statistics "][" currentconfirmed incr "]。as();world _ data . confirmed count = results _ 0[" global statistics "][" confirmed count "]。as();world _ data . confirmed incr = results _ 0[" global statistics "][" confirmed incr "]。as();world _ data . cured count = results _ 0[" global statistics "][" cured count "]。as();world _ data . cured incr = results _ 0[" global statistics "][" cured incr "]。as();world _ data . dead count = results _ 0[" global statistics "][" dead count "]。as();world _ data . dead incr = results _ 0[" global statistics "][" dead incr "]。as();//string定义char str 1[20];char str 2[20];char str 3[20];char str 4[20];char str 5[20];char str 6[20];char str 7[20];char str 8[20];char str 9[20];char str 10[20];char str 11[20];char str 12[20];char str 13[20];char str 14[20];char str 15[20];char str 16[20];char str 17[20];char str 18[20];//使用sprintf进行格式拼接Sprintf (str1," n0.val =% d/xff/xff/xff ",China _ data . current confirmed count);sprintf(str6," n5.val=%d/xff/xff/xff ",China _ data . current confirmed incr);sprintf(str2," n1.val=%d/xff/xff/xff ",China _ data . confirmed count);sprintf(str7," n6.val=%d/xff/xff/xff ",China _ data . confirmed incr);sprintf(str3," n2.val=%d/xff/xff/xff ",China _ data . cured count);sprintf(str8," n7.val=%d/xff/xff/xff ",China _ data . cured incr);sprintf(str4," n3.val=%d/xff/xff/xff ",China _ data . dead count);sprintf(str9," n8.val=%d/xff/xff/xff ",China _ data . dead incr);sprintf(str5," n4.val=%d/xff/xff/xff ",China _ data . serious count);sprintf(str10," n9.val=%d/xff/xff/xff ",China _ data . serious incr);//发送数据tjc . print(str 1);tjc . print(str 2);tjc . print(str 3);tjc . print(str 4);tjc . print(str 5);tjc . print(str 6);tjc . print(str 7);tjc . print(str 8);tjc . print(str 9);tjc . print(str 10);tjc . print(" page 1/xff/xff/xff ");sprintf(str11," n10.val=%d/xff/xff/xff ",World _ data . current confirmed count);sprintf(str12," n11.val=%d/xff/xff/xff ",World _ data . current confirmed incr);sprintf(str13," n12.val=%d/xff/xff/xff ",World _ data . confirmed count);sprintf(str14," n13.val=%d/xff/xff/xff ",World _ data . confirmed incr);sprintf(str15," n14.val=%d/xff/xff/xff ",World _ data . cured count);sprintf(str16," n15.val=%d/xff/xff/xff ",World _ data . cured incr);sprintf(str17," n16.val=%d/xff/xff/xff ",World _ data . dead count);sprintf(str18," n17.val=%d/xff/xff/xff ",World _ data . dead incr);tjc . print(str 11);tjc . print(str 12);tjc . print(str 13);tjc . print(str 14);tjc . print(str 15);tjc . print(str 16);tjc . print(str 17);tjc . print(str 18);tjc . print(" page 0/xff/xff/xff ");//串口打印//serial . println(" ");//serial . println(" --------------------------------------------4//serial . print("现有诊断:");serial . println(China _ data . currentconfirmed count);// Serial.print("累积诊断:");serial . println(China _ data . confirmed count);// Serial.print("累积治愈:");serial . println(China _ data . cured count);// Serial.print("无症状存在:");serial . println(China _ data . serious count);// Serial.print("累计死亡:");serial . println(China _ data . dead count);//serial . println(" --------------------------------------------4//serial . print("现有诊断:");serial . println(World _ data . currentconfirmed count);// Serial.print("累积诊断:");serial . println(World _ data . confirmed count);// Serial.print("累积治愈:");serial . println(World _ data . cured count);// Serial.print("累计死亡:");serial . println(World _ data . dead count);}} else {//没有得到响应,返回了错误代码serial.printf ("[http] get...失败,错误:% s/n ",http.errortostring (httpcode)。c _ str());} http . end();//结束当前连接延迟(1200000);//每两分钟发送一次请求,过于频繁可能导致ip被接口} VI阻塞。展示效果。

未经允许不得转载:主机频道 » 由ESP3zhujipindao串口屏幕(ESP32网络摄像机)组成的疫情监控平台

评论 抢沙发

评论前必须登录!