×

使用NodeMCU进行温度/湿度测量

消耗积分:0 | 格式:zip | 大小:0.13 MB | 2023-01-05

526774

分享资料个

描述

介绍

我没有智能家居,但我想了解我们家中几个房间的温度/湿度统计数据。因此,我开始在 Raspberry Pi 3B+ 上放置一些带有 BME280 的 NodeMCU,并使用 MQTT、InfluxDB、Telegraf 和 Grafana 安装监控。在我看来,最好的部分是:您不需要任何互联网服务,您的数据就在家里......

我们需要什么步骤

  • 安装 mosquitto (mqtt)
  • 安装 InfluxDB
  • 安装电报
  • 安装grafana
  • 用 micropython 准备 NodeMCU
  • 自定义boot.py
  • 上传boot.py到 NodeMCU
  • 在 Grafana 中创建仪表板

安装蚊子

非常简单,只需输入:

 sudo apt install mosquitto mosquitto-clients

Themqtt-daemon 自动启动。

安装 InfluxDB 和 Telegraf

sudo apt update
sudo apt install influxdb telegraf
sudo systemctl enable influxdb
sudo systemctl start influxdb 
influx
CREATE USER admin WITH PASSWORD 'password' WITH ALL PRIVILEGES
CREATE DATABASE telegraf
CREATE DATABASE rooms

编辑 influxdb 配置文件

sudo nano /etc/influxdb/influxdb.conf

删除前面的“#”

[http]
 # Determines whether HTTP endpoint is enabled.
  enabled = true
 # The bind address used by the HTTP service.
  bind-address = ":8086"
 # Determines whether user authentication is enabled over HTTP/HTTPS.
  auth-enabled = true

之后你必须重新启动服务:

sudo systemctl restart influxdb

编辑 Telegraf 配置文件:

sudo nano /etc/telegraf/telegraf.conf
omit_hostname = true
[[outputs.influxdb]]
 ## The target database for metrics; will be created as needed.
  database = "telegraf"
# we create a seperate database for our measurements, so we don't want the 
#  data in the telegraf-database
  namedrop = ["sensors*"]
 ## HTTP Basic Auth
  username = "admin"
  password = "password"

现在我们数据的配置文件:

sudo nano /etc/telegraf/telegraf.d/sensors.conf
# Input data as json-String
[[inputs.mqtt_consumer]]
 servers = ["tcp://localhost:1883"]
 topics = [
   "sensors/#",
 ]
 client_id = "telegraf"
 data_format = "json"
 name_prefix = "sensors_"
 json_name_key = "location"
 tag_keys = ["temperature","humidity"]
 json_string_fields = ["location"]
# Output for influxdb
[[outputs.influxdb]]
 urls = ["http://127.0.0.1:8086"]
 username = "admin"
 password = "password"
 database = "rooms"
 namepass = ["sensors*"]

安装 Grafana

检查是否有更新版本:下载Grafana

sudo dpkg -i grafana_5.4.1_armhf.deb 

使用 micropython 准备 NodeMCU

下载 ESP8266 的二进制固件:esp8266-20180511-v1.9.4.bin

按照此处所述部署固件

按照此处所述安装ampy

使用 ampy 将boot.py上传到您的 NodeMCU:

ampy -p ttyUSB0 -b 115200 put boot.py

之后,您应该重置 NodeMCU,以便它可以开始将测量值发送到您的数据库。

按照此处所述制作您的第一个 Grafana 仪表板


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !