本文讲解使用blynk app+服务器(本地) + 零知ESP8266硬件的方法,通过手机APP来观察由ESP8266获取的温湿度信息。
一、硬件
1.电脑,windows系统
2.零知ESP8266开发板
3.智能手机一部 + app(Blynk)
4.micro-usb线
5.SHT30温湿度模块
二、连接
2、关于准备工作不再细讲,请查看 Blynk手机APP点灯示例 ,已经对操作步骤进行了详细说明。
3、手机APP端
我们需要两个组件分别显示温度和湿度信息,做好后界面如下:
准备以下代码:
- /* 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上可以观察到如下结果:
更有效果视频,趣味无限 |