上次我们介绍了如何通过腾讯的物联网开发平台实现将helium网络中LoRaWAN终端的数据推动到微信公众号和腾讯连连小程序,本篇文档介绍如何通过腾讯云的CVM主机部署Mosquitto MQTT + Telegraf + InfluxDB + Grafana 实现仪表盘监控温湿度数据以及历史数据的分析。
仪表盘:
数据流程:
Rejeee温湿度传感器 --> Helium热点AP --> HeliumConsole --> MQTTBroker --> Telegraf --> InfluxDB --> Grafana
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients
sudo apt-get clean
创建两个MQTT账户密码,分别用在Helium Console 和 Telegraf 修改配置文件:
sudo vim /etc/mosquitto/conf.d/default.con
并增加两行配置,使用这个密码文件要求所有的连接登陆
allow_anonymous false
password_file /etc/mosquitto/passwd
增加helium console MQTT集成使用的账户密码
mosquitto_passwd -b /etc/mosquitto/passwd heliumconsole heliumconsole123
增加telegraf 使用MQTT连接使用账户密码
mosquitto_passwd -b /etc/mosquitto/passwd telegraf telegraf123
重启进程并确认服务已启动
service mosquitto stop
service mosquitto start
service mosquitto status
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
安装并启动 InfluxDB 服务
sudo apt-get update && sudo apt-get install influxdb
sudo service influxdb start
sudo systemctl status influxd.service
create database rejeee_TH
use rejeee_TH<br>
create user rejeee_TH with password 'rejeee_TH123' with all privileges<br>
exit
sudo apt-get update && sudo apt-get install telegraf
sudo service telegraf start
sudo service telegraf status
sudo vim /etc/telegraf/telegraf.conf
urls = ["http://127.0.0.1:8086"]<br>
database = "rejeee_TH"<br>
username = "rejeee_TH"<br>
password = "rejeee_TH123"
sudo vim /etc/telegraf/telegraf.d/mqtt.conf
servers = "tcp://127.0.0.1:1883"
qos = 0
connection_timeout = "30s"
topics = "helium/#"
username = "telegraf"
password = "telegraf123"
data_format = "json"
json_string_fields = "name","hotspot_name","spreading"
sudo systemctl reload telegraf.service
sudo systemctl status telegraf.service
apt-get install grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
sudo systemctl status grafana-server.service
sudo service grafana-server restart
示例:
mqtt://heliumconsole:heliumconsole123@serverIP:1884
用户: heliumconsole
密码: heliumconsole123
设置集成模版:
{
{{#decoded}}{{#payload}}"power": {{power}},
"temp_value": {{temp_value}},
"hum_value": {{hum_value}},{{/payload}}{{/decoded}}
"name": "{{name}}",
{{#hotspots}}"hotspot_name": "{{name}}",
"rssi": {{rssi}},
"snr": {{snr}},
"channel": {{channel}},
"fcnt":{{fcnt}},
"spreading": "{{spreading}}"{{/hotspots}}
}
MQTT Broker 采集到数据:
{
"power": 30,
"temp_value": 25.6,
"hum_value": 58,
"name": "Rejeee_TH",
"hotspot_name": "inxxxsting-honexxxuckle-gxxse",
"rssi": -86.0,
"snr": 12.199999809265137,
"channel": 399,
"fcnt":1712,
"spreading": "SF7BW125"
}
influx -username rejeee_TH -password rejeee_TH123
use rejeee_TH
select * from mqtt_consumer limit 5
确认influxDB采集到传感器数据
本文系外文翻译,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系外文翻译,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。