/ESP32_DHT11_Get_temp_humi

ESP32链接DHT11获取温湿度数据,显示在OLED屏幕上,通过中间层将数据上传到mysql数据库并且通过网页显示出来

Primary LanguageHTMLGNU General Public License v3.0GPL-3.0

ESP32_DHT11_Get_temp_humi

ESP32连接DHT11获取温湿度数据,显示在OLED屏幕上,通过中间层将数据上传到mysql数据库并且通过网页显示出来

网页展示

image

部署方式:

一、ESP32部分

1、刷入micropython固件
2、安装库文件:(使用Thonny进行开发)
点击 工具——>管理包,搜索安装如下库
image

3、将代码保存为main.py到ESP32,这样ESP32上电以后会自动运行
image

二、中间层部署(使用中间层去访问数据可以增加安全性)

1、安装库文件

pip install request  
pip install flask  
pip install pymysql
pip install flask_cors
pip install jsonify
pip install logging  

2、分别启动两个中间层(一个用来处理ESP32的请求,上传数据到数据库,另一个接受网页的请求,从数据库中读取数据,并且返回json给网页)

运行如下
image

image

请一定一定确保两个中间层的端口不要冲突

三、网页的部署(以Ubuntu服务器为例)

1、安装基础web服务

sudo apt-get update
sudo apt-get install apache2  

2、上传网页到服务器的/var/www/html文件夹下,并且命名为index.html

image

四、数据库生成

create table temp_moisture
(
    id       int auto_increment
        primary key,
    time     varchar(64) not null,
    temp     double      not null,
    moisture double      not null
);