通过MQTT接收到的重复数据流入数据库
dooblr的Python项目详细描述
dooblr-数据倍增器
用于将通过mqtt接收的数据复制到infloxdb的实用程序。
安装
在不久的将来,dooblr将能够通过pypi/pip安装。在那之前,或者如果你想要最新的, 最新版本,您可以通过克隆或下载repo并在 根目录:
pip install ./
然后您应该能够运行dooblr:
dooblr
Docker
dooblr也方便对接!
您需要将配置装载或复制到位于`/root/.dooblr`目录的容器中。makers local 256如何使用dooblr的示例可以在[makerslocal/dooblr prod](https://github.com/makerslocal/dooblr-prod)repo中找到。
示例:
docker run -v $(pwd)/config:/root/.dooblr makerslocal/dooblr:latest
配置
dooblr是使用yaml文件配置的,这些文件存储在用户的主目录中。基于linux 系统它们需要在如下目录中:
/home/<username>/.dooblr/
在Windows上,它们是从如下位置加载的:
C:\Users\<username>\.dooblr\
第一次运行dooblr之后,将创建此目录,并在其中包含一些默认配置文件。 dooblr需要定义mqtt和infloxdb连接的主dooblr.yml,以及一个或多个度量 配置。
默认设置dooblr.ymlconfig文件将如下所示:
# dooblr.yaml global: config-dir: /home/<username>/.dooblr/measurements # Directory that contains dooblr's measurement configs mqtt: host: localhost # Host, domain name, or IP address of the MQTT broker port: 1883 # Port number of the MQTT broker influxdb: host: localhost # Host, domain name, or IP address of the InfluxDB instance port: 8086 # Port number of the InfluxDB instance username: root # Username for the InfluxDB instance password: root # Password for the InfluxDB instance database: dooblr # Database to use in InfluxDB (will be created if it doesn't exist already)
默认情况下,dooblr在.dooblr/measurements/目录中查找*.yml测量配置。测量 configs用于告诉dooblr哪些主题和数据片段需要从mqtt中提取并推送到infloxdb。 dooblr期望mqtt消息在其有效负载中包含单个值或简单的json数据。
单值mqtt消息
如果您有一个设备发布到home/garage/humidity主题,其中包含单个浮点值,如12.3, 您需要创建一个类似于humidity.yml:
# humidity.yml humidity: parser: single-value value_type: float # Valid value_types are integer, float, boolean, and string field_name: humidity # If no field_name is provided, the default is 'value' topics: - home/garage/humidity
简单的json mqtt消息
假设有一个设备发布到home/kitchen/fridge/temperature,并且 home/kitchen/freezer/temperature包含数据的主题:
{"temperature": 40.1, "units":"F", "humidity": 0.12, "label": "blue"}
您可能需要创建一个名为temperature.yml的测量配置,它看起来像:
# temperature.yml temperature: topics: - home/kitchen/fridge/temperature - home/kitchen/freezer/temperature - home/kitchen/+/temperature # Standard MQTT wildcards also apply here fields: - temperature - humidity tags: - units optional_tags: - label # Maybe not every message on these topics have a "label" property!
注意,可以有多个主题、字段和标记。标记和字段是指 涌入。如果在mqtt消息中没有定义可选标记,则它们不会引发错误,而常规标记将引发错误。