91在线观看视频-91在线观看视频-91在线观看免费视频-91在线观看免费-欧美第二页-欧美第1页

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

如何使用ESP32創建一個氣象站

科技觀察員 ? 來源:八色木 ? 作者:八色木 ? 2022-04-12 15:56 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

在這個項目中,我們將使用ESP32創建一個氣象站。基本原理是通過讀取DHT22和BMP180傳感器的數據,然后使用ESP32傳輸創建的網頁上,在網頁上顯示氣象數據。

電路圖

poYBAGJVMCaAOFi4AAJF76tzN-U325.png

首先,將DHT22和ESP32連接起來。DHT22與ESP32的連接如下:

DHT22 引腳1 VCC —–>ESP32 / 3.3V;

DHT22 引腳2 DATA—–>ESP32 / D15;

DHT22引腳4 GND —–>ESP32 /GND.

然后將BMP180壓力傳感器連接到ESP32上。連接如下:

BMP180 Vin —–> ESP32 / 3.3V;

BMP180 GND —–> ESP32 /GND;

BMP180SCL —–> ESP32 / pin 22;(ESP32的22號引腳是SCL.)

BMP180SDA —–> ESP32 / pin 21;(ESP32的21號引腳是SDA.)

ESP32的22和21號引腳是I2C通信接口。詳見下圖ESP32的引腳圖

pYYBAGJVMCuAF3VnAASJjiG1i4M778.png

氣象站C代碼

#include

#include

#include

#include

#define DHTPIN 15

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

Adafruit_BMP085 bmp;

char pressure_value[4];

const char* wifi_name = "Asus_2.4G"; //Your Wifi name

const char* wifi_pass = "basemu.com"; //Your Wifi password

WiFiServer server(80); //Port 80

void setup()

{

Serial.begin(115200);

dht.begin();

bmp.begin();

// Let's connect to wifi network

Serial.print("Connecting to ");

Serial.print(wifi_name);

WiFi.begin(wifi_name, wifi_pass); //Connecting to wifi network

while (WiFi.status() != WL_CONNECTED) //Waiting for the responce of wifi network

{

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.println("Connection Successful");

Serial.print("IP address: ");

Serial.println(WiFi.localIP()); //Getting the IP address at which our webserver will be created

Serial.println("Type the above IP address into a browser search bar");

server.begin(); //Starting the server

}

void loop()

{

String pressure = String(bmp.readPressure());

// convert the reading to a char array

pressure.toCharArray(pressure_value, 4);

float hum = dht.readHumidity();

float temp = dht.readTemperature();

float fah = dht.readTemperature(true);

float heat_index = dht.computeHeatIndex(fah, hum);

float heat_indexC = dht.convertFtoC(heat_index);

WiFiClient client = server.available(); //Checking for incoming clients

if (client)

{

Serial.println("new client");

String currentLine = ""; //Storing the incoming data in the string

while (client.connected())

{

if (client.available()) //if there is some client data available

{

char c = client.read(); // read a byte

if (c == '\n') // check for newline character,

{

if (currentLine.length() == 0) //if line is blank it means its the end of the client HTTP request

{

client.print("

");

client.print("

);

client.print("

);

client.print(temp);

client.print("
Temperature in fah: ");

client.print(fah);

client.print("
Humidity is: ");

client.print(hum);

client.print("
Heat Index in C: ");

client.print(heat_indexC);

client.print("
Heat Index in fah: ");

client.print(heat_index);

client.print("
Pressure is: ");

client.print(pressure_value);

client.print("hpa");

client.print("

");

break; // break out of the while loop:

}

else

{ // if you got a newline, then clear currentLine:

currentLine = "";

}

}

else if (c != '\r')

{ // if you got anything else but a carriage return character,

currentLine += c; // add it to the end of the currentLine

}

}

}

}

}

氣象站項目代碼釋義

首先,確保項目所需的所有庫均 include 了,然后定義連接DHT22溫度和濕度傳感器的引腳,再創建實例:

#include

#include

#include

#include

#define DHTPIN 15

#define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE);

Adafruit_BMP085 bmp;

接著存儲Wi-Fi名稱和密碼,同時定義并創建服務器的端口

const char* wifi_name = "Asus_2.4G"; //Your Wifi name const char*

wifi_pass = "basemu.com"; //Your Wifi password

WiFiServer server(80); //Port 80

在setup函數中,會使用上面的Wi-Fi信數據將ESP32連接到的Wi-Fi網絡。如果連接到網絡成功,那么“connection successful”將顯示在串口監視器上。否則,程序將繼續嘗試,直到連接到Wi-Fi網絡。

Serial.print("Connecting to ");

Serial.print(wifi_name);

WiFi.begin(wifi_name, wifi_pass); //Connecting to wifi network

while (WiFi.status() != WL_CONNECTED) { //Waiting for the response of wifi network

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.println("Connection Successful");

下面的命令會將IP地址顯示在串口監視器上。

Serial.println(WiFi.localIP());

然后程序將啟動服務器,以便程序能夠接收和發送數據到瀏覽器上。

server.begin();

在loop函數中,程序能夠從傳感器讀取數據并存儲在變量中,這樣就可以在網頁上顯示數據了。

String pressure = String(bmp.readPressure());

pressure.toCharArray(pressure_value, 4);

float hum = dht.readHumidity();

float temp = dht.readTemperature();

float fah = dht.readTemperature(true);

float heat_index = dht.computeHeatIndex(fah, hum);

float heat_indexC = dht.convertFtoC(heat_index);

然后檢查客戶端是否有發送HTTP請求,如果有客戶端請求可用,那么程序將存儲并顯示結果在串行監視器上。在請求結束時,程序將發送HTML命令,在網頁上顯示傳感器的數據。

WiFiClient client = server.available(); //Checking for incoming clients

if (client){

Serial.println("new client");

String currentLine = ""; //Storing the incoming data in the string

while (client.connected()){

if (client.available()) //if there is some client data available

{

char c = client.read(); // read a byte

if (c == '\n') // check for newline character,

{

if (currentLine.length() == 0) //if line is blank it means it’s the end of the client HTTP

request { client.print("");

client.print("

ESP32 Weather Station

");

client.print("Temperature in C: ");

client.print(temp);

client.print(" Temperature in fah: ");

client.print(fah);

client.print(" Humidity is: ");

client.print(hum);

氣象站如何使用

首先,將代碼中的Wi-Fi名稱和密碼信息替換為你自己的。然后上傳代碼并打開串口監視器。串口監視器將顯示如下圖所示的IP地址。

poYBAGJVMD6AevTtAAEX2X1WMBw112.png

在瀏覽器中輸入這個IP地址。輸入IP地址后,網頁會顯示如下圖所示。

poYBAGJVMEKASlNGAAB5kV5QdpM722.png

現在傳感器數據就從氣象站上傳到網頁上了。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 氣象站
    +關注

    關注

    1

    文章

    775

    瀏覽量

    16210
  • DHT22
    +關注

    關注

    2

    文章

    51

    瀏覽量

    7476
  • ESP32
    +關注

    關注

    21

    文章

    1017

    瀏覽量

    19239
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    如何使用miniprog3設置氣象站

    你好,可以請人幫我,我想計劃的cy3271-exp1 PSoC氣象站板采用miniprog3這樣我可以把周圍的光強讀數然后發送閱讀通過串行命令我寫的應用程序并存儲的數據畫成了GR促性腺激素釋放
    發表于 04-15 08:32

    基于機智云gokit4.0(G)和MDM9206的 小型智能氣象站

    和關閉,以便根據土壤濕度進行灌溉控制。硬件說明本氣象站以MDM9206模塊作為SOC控制器,使用機智云平臺提供的軟硬件平臺開發工具進行開發本項目。也可以使用esp8266/ESP32或具有GPRS功能
    發表于 07-19 16:18

    怎樣去設計基于ESP32的家庭氣象站系統

    或 畢業設計技術解答畢設幫助:7468760412 主要器件本項目學長將使用ESP32創建氣象站。基本原理是通過讀取DHT22和BMP
    發表于 12-13 07:38

    DIY基于ESP8266的wifi氣象站

    描述氣象站ESP8266 E12帶 ESPHome 的 DIY WiFi 停止處理不斷變化的天氣軟件和 API,自己獲取傳感器數據
    發表于 06-24 07:26

    分享氣象站項目

    描述氣象站 | 風向
    發表于 07-11 07:16

    使用ESP8266和ST7735 TFT顯示屏設計氣象站

    描述基于 ESP8266 Nodemcu 和 ST7735 TFT 顯示屏的氣象站什么是氣象站氣象站種使用不同傳感器收集與天氣和環境相
    發表于 09-01 06:52

    帶有BME280的ESP32 Web服務器的高級氣象站

    介紹款帶有BME280的ESP32 Web服務器的高級氣象站
    發表于 03-17 11:15 ?18次下載
    帶有BME280的<b class='flag-5'>ESP32</b> Web服務器的高級<b class='flag-5'>氣象站</b>

    ESP32氣象站接口PCB屏蔽

    電子發燒友網站提供《ESP32氣象站接口PCB屏蔽.zip》資料免費下載
    發表于 07-18 10:36 ?3次下載
    <b class='flag-5'>ESP32</b><b class='flag-5'>氣象站</b>接口PCB屏蔽

    帶有esp8266和Python Flask的桌面氣象站

    電子發燒友網站提供《帶有esp8266和Python Flask的桌面氣象站.zip》資料免費下載
    發表于 11-09 10:26 ?0次下載
    帶有<b class='flag-5'>esp</b>8266和Python Flask的桌面<b class='flag-5'>氣象站</b>

    小型氣象站是什么?文淺談

    小型氣象站又叫自動氣象站、農業氣象站、校園氣象站
    的頭像 發表于 11-16 13:15 ?2015次閱讀

    基于ESP8266的自動氣象站

    小型氣象站,帶有我們的ESP8266 NodeMCU,它將向全球社區報告溫度,濕度和露點。通過這個氣象站,我們可以對我們居住的城市進行更
    發表于 12-02 14:25 ?1次下載

    基于ESP8266的自動氣象站

    小型氣象站,帶有我們的ESP8266 NodeMCU,它將向全球社區報告溫度,濕度和露點。通過這個氣象站,我們可以對我們居住的城市進行更
    發表于 12-05 16:56 ?1次下載

    WIoT2氣象站之Nextion TFT with ESP8266/ESP32

    電子發燒友網站提供《WIoT2氣象站之Nextion TFT with ESP8266/ESP32.zip》資料免費下載
    發表于 01-30 11:58 ?2次下載
    WIoT2<b class='flag-5'>氣象站</b>之Nextion TFT with <b class='flag-5'>ESP</b>8266/<b class='flag-5'>ESP32</b>

    使用Wio Terminal和Tensorflow Lite創建智能氣象站

    電子發燒友網站提供《使用Wio Terminal和Tensorflow Lite創建智能氣象站.zip》資料免費下載
    發表于 06-25 10:30 ?0次下載
    使用Wio Terminal和Tensorflow Lite<b class='flag-5'>創建</b>智能<b class='flag-5'>氣象站</b>

    什么是氣象站氣象站的簡介

    什么是氣象站氣象站的簡介
    的頭像 發表于 09-14 16:14 ?1897次閱讀
    主站蜘蛛池模板: 免费亚洲一区 | 69日本xxxxxxxxx56| 欧美精品首页 | 国产精品三级 | 日本黄大乳片免费观看 | 日本特级黄录像片 | 台湾三级毛片 | 天天躁夜夜躁狠狠躁2024 | 天堂在线免费 | 亚洲欧美日韩一区 | 日本加勒比高清一本大道 | 欧美精品四虎在线观看 | 免费看黄色片网站 | 欧美一区二区三区不卡视频 | 精品久久免费观看 | 欧美视频精品在线 | 日本丰满毛茸茸熟妇 | 日本免费一区视频 | 深爱婷婷 | 亚洲精品九色在线网站 | 国产三级毛片视频 | 欧美一级欧美三级在线观看 | 午夜影院官网 | 亚洲 欧美 丝袜 制服 在线 | 国产免费卡1卡2卡 | 中文字幕在线色 | 免费a级网站| 国产福利在线观看一区二区 | 人人九九精 | 日日干天天草 | 夭天干天天做天天免费看 | 欧美在线黄色 | 夜夜骑天天操 | 日韩精品卡4卡5卡6卡7卡 | 羞涩妩媚玉腿呻吟嗯啊销魂迎合 | 狠狠色噜噜狠狠狠狠97老肥女 | 亚洲国产情侣偷自在线二页 | 大量真实偷拍情侣视频野战 | 男人的j桶女人的j视频 | 在线视频免费播放 | 日本不卡视频在线观看 |