本文講解使用blynk app+服務器(本地) + 零知ESP8266硬件的方法,通過手機APP來觀察由ESP8266獲取的溫濕度信息。
一、硬件
1.電腦,windows系統(tǒng)
2.零知ESP8266開發(fā)板
3.智能手機一部 + app(Blynk)
4.micro-usb線
5.SHT30溫濕度模塊
二、連接
1.jpg (120.91 KB, 下載次數(shù): 54)
下載附件
2019-11-15 10:27 上傳
2.jpg (88.15 KB, 下載次數(shù): 46)
下載附件
2019-11-15 10:27 上傳
2、關于準備工作不再細講,請查看 Blynk手機APP點燈示例 ,已經對操作步驟進行了詳細說明。
3、手機APP端
我們需要兩個組件分別顯示溫度和濕度信息,做好后界面如下:
3.jpg (83.32 KB, 下載次數(shù): 50)
下載附件
2019-11-15 10:27 上傳
準備以下代碼:
- /* Comment this out to disable prints and save space */
- #define BLYNK_PRINT Serial
-
-
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
-
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "xx";
-
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "xx";
- char pass[] = "xx";
-
- char local_domain[] = "192.168.0.111";
-
- /*SHT3X 傳感器
- * 使用軟I2C接口
- */
- #define SHT3X_SDA D5
- #define SHT3X_SCL D6
-
- #include "SHT3X.h"
- SlowSoftWire shtWire(SHT3X_SDA,SHT3X_SCL,true);
-
- HTU3X myHumidity;
-
- BlynkTimer timer;
- void myTimerEvent()
- {
-
- float humd, temp;
- myHumidity.readTempAndHumi(&temp, &humd);
-
- Serial.print("時間:");
- Serial.print(millis());
- Serial.print(" 溫度:");
- Serial.print(temp, 1);
- Serial.print(" °C");
- Serial.print(" 濕度:");
- Serial.print(humd, 1);
- Serial.print("%");
- Serial.println();
-
- Blynk.virtualWrite(V0, temp);
- Blynk.virtualWrite(V1, humd);
- }
-
- void setup()
- {
- // Debug console
- Serial.begin(9600);
-
- Blynk.begin(auth, ssid, pass, local_domain,8080);
-
- myHumidity.begin(shtWire);
-
- timer.setInterval(1000L, myTimerEvent);
- }
-
- void loop()
- {
- Blynk.run();
- timer.run(); // Initiates BlynkTimer
- }
復制代碼
更改代碼中的IP、token等信息,然后驗證并上傳到零知-ESP8266板上。
5、驗證測試
在手機blynk app上可以觀察到如下結果:
4.jpg (67.27 KB, 下載次數(shù): 45)
下載附件
2019-11-15 10:27 上傳
更有效果視頻,趣味無限 |