标题: 【零知ESP8266】 Blynk手机APP教程:监控室内温湿度 [打印本页]

作者: roc2    时间: 2019-6-13 16:19
标题: 【零知ESP8266】 Blynk手机APP教程:监控室内温湿度
本帖最后由 roc2 于 2019-6-19 10:54 编辑

本次将使用blynk app+服务器(本地) + 零知ESP8266开发板的组合方式,通过手机APP来观察由ESP8266获取的温湿度情况。
1、准备
(1)零知ESP8266开发板
(2)SHT30温湿度模块
(3)零知开源开发工具

2、电路连接
线路连接很简单,按下图连接即可:

实物连接:

3、手机APP端
设置手机端Blynk可参考:
我们需要两个组件分别显示温度和湿度信息,做好后界面如下:

页面组件可扫描下方二维码复制我共享的demo:

4、ESP8266端
核心代码如下:
  1. /* Comment this out to disable prints and save space */
  2. #define BLYNK_PRINT Serial


  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>

  5. // You should get Auth Token in the Blynk App.
  6. // Go to the Project Settings (nut icon).
  7. char auth[] = "xx";

  8. // Your WiFi credentials.
  9. // Set password to "" for open networks.
  10. char ssid[] = "xx";
  11. char pass[] = "xx";

  12. char local_domain[] = "192.168.0.111";

  13. /*SHT3X 传感器
  14. *   使用软I2C接口
  15. */
  16. #define SHT3X_SDA D5
  17. #define SHT3X_SCL D6

  18. #include "SHT3X.h"
  19. SlowSoftWire shtWire(SHT3X_SDA,SHT3X_SCL,true);

  20. HTU3X myHumidity;

  21. BlynkTimer timer;
  22. void myTimerEvent()
  23. {

  24.     float humd, temp;
  25.     myHumidity.readTempAndHumi(&temp, &humd);
  26.      
  27.     Serial.print("时间:");
  28.     Serial.print(millis());
  29.     Serial.print(" 温度:");
  30.     Serial.print(temp, 1);
  31.     Serial.print(" °C");
  32.     Serial.print(" 湿度:");
  33.     Serial.print(humd, 1);
  34.     Serial.print("%");
  35.     Serial.println();
  36.      
  37.     Blynk.virtualWrite(V0, temp);
  38.     Blynk.virtualWrite(V1, humd);
  39. }

  40. void setup()
  41. {
  42.   // Debug console
  43.   Serial.begin(9600);

  44.   Blynk.begin(auth, ssid, pass, local_domain,8080);
  45.      
  46.     myHumidity.begin(shtWire);
  47.      
  48.     timer.setInterval(1000L, myTimerEvent);
  49. }

  50. void loop()
  51. {
  52.   Blynk.run();
  53.     timer.run(); // Initiates BlynkTimer
  54. }
复制代码
更改代码中的IP、token等信息,然后把代码验证并上传到零知-ESP8266开发板板上即可。
5、验证测试
在手机blynk app上可以观察到如下结果:

可以很直观的看到温湿度的曲线分布,可用于实时监测。
更多详细资料可到零知实验室官网免费获取。


作者: sgsg11    时间: 2020-2-15 22:11
牛皮,啊大佬
作者: ch29    时间: 2020-4-5 15:52
大佬  APP用什么做的





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1