本帖最后由 roc2 于 2019-6-19 10:54 編輯
本次將使用blynk app+服務器(本地) + 零知ESP8266開發(fā)板的組合方式,通過手機APP來觀察由ESP8266獲取的溫濕度情況。 1、準備 (1)零知ESP8266開發(fā)板 (2)SHT30溫濕度模塊 (3)零知開源開發(fā)工具 2、電路連接 線路連接很簡單,按下圖連接即可: 實物連接:
3、手機APP端 設置手機端Blynk可參考: 我們需要兩個組件分別顯示溫度和濕度信息,做好后界面如下: 頁面組件可掃描下方二維碼復制我共享的demo:
4、ESP8266端 核心代碼如下: - /* 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開發(fā)板板上即可。 5、驗證測試 在手機blynk app上可以觀察到如下結果: 可以很直觀的看到溫濕度的曲線分布,可用于實時監(jiān)測。 更多詳細資料可到零知實驗室官網(wǎng)免費獲取。
|