RuuviBridge icon indicating copy to clipboard operation
RuuviBridge copied to clipboard

No data in Influxdb

Open rollecode opened this issue 4 years ago • 11 comments

I'm trying to save data from Ruuvi Gateway MQTT to InfluxDB, but I see no data saved.

$ ./ruuvibridge
[2022-7-4 22:55:59] [info] RuuviBridge starting up, version: v0.1.14
[2022-7-4 22:55:59] [info] Starting data sources
[2022-7-4 22:55:59] [info] Starting MQTT subscriber, mqtt_subscription: ruuvi/+, target: tcp://localhost:1883, topic_prefix: ruuvi
[2022-7-4 22:55:59] [info] Starting data sinks
[2022-7-4 22:55:59] [info] Starting InfluxDB sink, target: http://127.0.0.1:8086, bucket: ruuvi, measurement_name: ruuvi_measurements, minimum_interval: 0s
[2022-7-4 22:55:59] [info] Starting MQTT sink, topic_prefix: ruuvitag, minimum_interval: 5s, target: tcp://localhost:1883
[2022-7-4 22:55:59] [info] Starting processing
$ cat config.yml
# Easiest option: let RuuviBridge poll the gateway for measurements
gateway_polling:
  # Flag to enable or disable gateway polling
  enabled: false
  gateway_url: http://ip.or.hostname.of.the.gateway
  interval: 10s

# Recommended option: Have the gateway send the measurements to a MQTT server and let RuuviBridge subscribe to updates in real time
mqtt_listener:
  # Flag to enable or disable subscribing to a topic on a MQTT server
  enabled: true
  # MQTT broker url, including scheme (tcp, ssl or ws), hostname or IP address, and port
  broker_url: tcp://localhost:1883
  # Client ID, required for persistent sessions and has to be unique on the MQTT server
  client_id: RuuviBridgeListener
  username: <obfuscated>
  password: <obfuscated>
  # Topic prefix to subscribe to, expecting RuuviTag measurements to be published as <topic_prefix>/<mac>
  # You can use + character as a single-level wildcard, for example if you have the gateway mac address in the topic
  # for example: ruuvi/+ as the topic prefix would match the topic ruuvi/<gateway_mac>/<tag_mac>
  topic_prefix: ruuvi

# Third option: Configure Ruuvi Gateway to send measurements here via the custom http server setting
http_listener:
  # Flag to enable or disable the http listener
  enabled: false
  # Port to listen on. Cannot be the same as prometheus listen port if enabled
  port: 8080

# Extra processing of the values
processing:
  # Extended values are enabled by default but can be disabled by changing extended_values to false
  extended_values: true
  # Filter which tags are considered. Valid options:
  # none - no filtering is done, all tags are processed (default)
  # named - only tags which have a name configured will be processed
  # allowlist - only mac addresses listed in filter_list will be processed
  # denylist - mac addresses listed in filter_list will be skipped
  filter_mode: none
  # List of mac addresses to allow or deny if filter_mode is either allowlist or denylist
  filter_list:
    - FFEEDDCCBBAA
    - F0E1D2C3B4A5

# Supports both InfluxDB 1.8 and 2.x
influxdb_publisher:
  # Flag to enable or disable publishing the processed data to InfluxDB
  enabled: true
  # Minimum interval for measurements to publish per tag. InfluxDB handles frequent updates very efficiently due to delta compression so the default is no limit
  minimum_interval: 0s
  # URL for InfluxDB, including scheme, hostname and port
  url: http://127.0.0.1:8086
  # For InfluxDB 1.8 the auth_token is username and password in format "username:password"
  auth_token: <obfuscated>:<obfuscated>
  # This is ignored for InfluxDB 1.8
  org: ""
  # For InfluxDB 1.8 the bucket is the database name, with optional retention policy in format "database/retentionpolicy"
  bucket: ruuvi
  # Measurement name to use
  measurement: ruuvi_measurements
  # Uncomment to add additional tags to a series
  #additional_tags:
  #  mytag: myvalue
  #  myothertag: myothervalue

# Prometheus exporter for data
prometheus:
  # Flag to enable or disable exporting the measurements and RuuviBridge diagnostics in prometheus exposition format
  enabled: false
  # Port to listen on. Cannot be the same as http listener port if enabled
  port: 8081

# Publish the parsed and processed data back to MQTT. Can be the same server or a different one.
mqtt_publisher:
  # Flag to enable or disable publishing the processed data to a MQTT server
  enabled: true
  # Minimum interval for measurements to publish per tag. Accepts values in go duration format ( https://pkg.go.dev/time#ParseDuration ), for example 1m30s
  minimum_interval: 5s
  # MQTT broker url, including scheme (tcp, ssl or ws), hostname or IP address, and port
  broker_url: tcp://localhost:1883
  # Client ID, required for persistent sessions and has to be unique on the MQTT server
  client_id: RuuviBridgePublisher
  username: <obfuscated>
  password: <obfuscated>
  # Topic prefix where to publish, in format <topic_prefix>/<mac>
  # If you use the same server for a source, be sure to use a different topic prefix to avoid conflicts!
  topic_prefix: ruuvitag
  # Uncomment to enable creating Home Assistant MQTT discovery topics
  #homeassistant_discovery_prefix: homeassistant

# Optional names for the tags with the key being the mac address and value being the desired name
tag_names:
  <obfuscated>: Makuuhuone
  <obfuscated>: Parveke
  <obfuscated>: Sauna
  <obfuscated>: Olohuone

# Logging options for RuuviBridge itself
logging:
  # Type can be either "structured", "json" or "simple"
  type: simple
  # Valid logging levels from most verbose to least verbose: trace, debug, info, warn, error, fatal, panic
  level: info
  # Include timestamp in the log line. Can be useful to turn off with certain logging systems which add their own timestamps
  timestamps: true
  # Whether to include the log caller in the logs. This will increase the size of logs but it helps in troubleshooting in some cases
  with_caller: false

# Enable or disable debug mode. This will print all received measurements to the console among other debuggy things, useful for development, testing and troubleshooting purposes.
debug: false
$ influx -username <obfuscated> -password <obfuscated>
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> use ruuvi
Using database ruuvi
> SELECT * FROM ruuvi_measurements
>

Data is shown when running:

mosquitto_sub -u <obfuscated> -P <obfuscated> -h 127.0.0.1 -p 1883 -t 'ruuvi/<obfuscated>/<obfuscated>'

Any tips?

rollecode avatar Jul 04 '22 20:07 rollecode

it looks like your topic_prefix under mqtt_listener is incorrect for the topic pattern you're using, topic_prefix: ruuvi/+ should work in your case (see the comment above the topic_prefix in the example config about that)

Scrin avatar Jul 04 '22 21:07 Scrin

Thanks! I just followed the sample config and overlooked that bit. Why not have it as default? Sent a PR if that's okay.

rollecode avatar Jul 04 '22 21:07 rollecode

By default the "custom MQTT server" option when configuring the gateway doesn't have the "Use Ruuvi Gateway's MAC address on the topic prefix" option checked, which makes the gateway publish the raw data at ruuvi/<tag_mac> by default in which case the current default of ruuvi is the one to use in the config. Or at least this was the case a while ago when I set up my gateway. If the default has changed on the gateway, then it makes sense to change the default value in the config as well

Scrin avatar Jul 04 '22 21:07 Scrin

That's true. Perhaps better to honor the gateway default then, good point.

rollecode avatar Jul 04 '22 21:07 rollecode

Hi, I am also having some issues with MQTT that may be similar to this.

We are running the RuuviBridge in a Docker container and gateway polling, influxdb_publisher as well as mqtt_publsisher are working fine. Unfortunately, I am not able to get the mqtt_listener to work.

Maybe you can give me a hint by providing the config.yml?

# Easiest option: let RuuviBridge poll the gateway for measurements
gateway_polling:
  # Flag to enable or disable gateway polling
  enabled: true
  gateway_url: <obfuscated>
  # If you have enabled authentication on the gateway, specify the API key (bearer token) from the gateway Access Settings configuration page
  bearer_token: <obfuscated>
  interval: 300s

# Recommended option: Have the gateway send the measurements to a MQTT server and let RuuviBridge subscribe to updates in real time
mqtt_listener:
  # Flag to enable or disable subscribing to a topic on a MQTT server
  enabled: false
  # MQTT broker url, including scheme (tcp, ssl or ws), hostname or IP address, and port
  broker_url: <obfuscated>
  # Client ID, required for persistent sessions and has to be unique on the MQTT server
  client_id: <obfuscated>
  username: ruuvibridge
  password: ruuvipassword
  # Topic prefix to subscribe to, expecting RuuviTag measurements to be published as <topic_prefix>/<mac>
  # You can use + character as a single-level wildcard, for example if you have the gateway mac address in the
  # topic by checking the "Use Ruuvi Gateway's MAC address on the topic prefix" option in the Ruuvi Gateway config
  # for example: ruuvi/+ as the topic prefix would match the topic ruuvi/<gateway_mac>/<tag_mac>
  topic_prefix: ruuvi/+
  # Topic where to publish LWT "status messages" on connect/disconnect. Empty means disabled.
  # Note that the mqtt_listener and mqtt_publisher have their own distinct connections and you should not use the same lwt topic for both.
  lwt_topic: ""
  # Payload that will be published to lwt_topic when RuuviBridge connects
  lwt_online_payload: '{"state":"online"}'
  # Payload that will be published to lwt_topic when RuuviBridge disconnects
  lwt_offline_payload: '{"state":"offline"}'

# Extra processing of the values
processing:
  # Extended values are enabled by default but can be disabled by changing extended_values to false
  extended_values: true
  # Filter which tags are considered. Valid options:
  # none - no filtering is done, all tags are processed (default)
  # named - only tags which have a name configured will be processed
  # allowlist - only mac addresses listed in filter_list will be processed
  # denylist - mac addresses listed in filter_list will be skipped
  filter_mode: none
  # List of mac addresses to allow or deny if filter_mode is either allowlist or denylist
  #filter_list:
  #  - FFEEDDCCBBAA
  #  - F0E1D2C3B4A5

# Publish the parsed and processed data back to MQTT. Can be the same server or a different one.
mqtt_publisher:
  # Flag to enable or disable publishing the processed data to a MQTT server
  enabled: true
  # Minimum interval for measurements to publish per tag. Accepts values in go duration format ( https://pkg.go.dev/time#ParseDuration ), for example 1m30s
  minimum_interval: 30s
  # MQTT broker url, including scheme (tcp, ssl or ws), hostname or IP address, and port
  broker_url: <obfuscated>
  # Client ID, required for persistent sessions and has to be unique on the MQTT server
  client_id: <obfuscated>
  username: ruuvibridge
  password: ruuvipassword
  # Topic prefix where to publish, in format <topic_prefix>/<mac>
  # If you use the same server for a source, be sure to use a differnet topic prefix to avoid conflicts!
  topic_prefix: ruuvitag
  # Topic where to publish LWT "status messages" on connect/disconnect. Empty means disabled.
  # Note that the mqtt_listener and mqtt_publisher have their own distinct connections and you should not use the same lwt topic for both.
  lwt_topic: ""
  # Payload that will be published to lwt_topic when RuuviBridge connects
  lwt_online_payload: '{"state":"online"}'
  # Payload that will be published to lwt_topic when RuuviBridge disconnects
  lwt_offline_payload: '{"state":"offline"}'

# Supports both InfluxDB 1.8 and 2.x
influxdb_publisher:
  # Flag to enable or disable publishing the processed data to InfluxDB
  enabled: true
  # Minimum interval for measurements to publish per tag. InfluxDB handles frequent updates very efficiently due to delta compression so the default is no limit
  minimum_interval: 0s
  # URL for InfluxDB, including scheme, hostname and port
  url: <obfuscated>
  # For InfluxDB 1.8 the auth_token is username and password in format "username:password"
  auth_token: <obfuscated>
  # This is ignored for InfluxDB 1.8
  org: <obfuscated>
  # For InfluxDB 1.8 the bucket is the database name, with optional retention policy in format "database/retentionpolicy"
  bucket: ruuvi
  # Measurement name to use
  measurement: ruuvi_measurements
  # Uncomment to add additional tags to a series
  #additional_tags:
  #  mytag: myvalue
  #  myothertag: myothervalue

# Optional names for the tags with the key being the mac address and value being the desired name
tag_names:

# Logging options for RuuviBridge itself
logging:
  # Type can be either "structured", "json" or "simple"
  type: simple
  # Valid logging levels from most verbose to least verbose: trace, debug, info, warn, error, fatal, panic
  level: trace
  # Include timestamp in the log line. Can be useful to turn off with certain logging systems which add their own timestamps
  timestamps: true
  # Whether to include the log caller in the logs. This will increase the size of logs but it helps in troubleshooting in some cases
  with_caller: false

# Enable or disable debug mode. This will print all received measurements to the console among other debuggy things, useful for development, testing and troubleshooting purposes.
debug: true
[2023-2-21 08:40:46] [debug] Config loaded, configfile: ./config.yml
[2023-2-21 08:40:46] [info] RuuviBridge starting up, version: git-afac08b2c9d09730362f71afd2a1d8497c63917d
[2023-2-21 08:40:46] [info] Starting data sources
[2023-2-21 08:40:46] [info] Starting MQTT subscriber, target: tcp://192.168.178.6:1883, topic_prefix: ruuvi/+, mqtt_subscription: ruuvi/+/+
[2023-2-21 08:40:46] [info] Starting data sinks
[2023-2-21 08:40:46] [info] Starting debug sink
[2023-2-21 08:40:46] [info] Starting InfluxDB sink, target: http://192.168.178.2:8086/, bucket: ruuvi, measurement_name: ruuvi_measurements, minimum_interval: 0s
[2023-2-21 08:40:46] [info] Starting MQTT sink, minimum_interval: 30s, target: tcp://192.168.178.6:1883, topic_prefix: ruuvitag
[2023-2-21 08:40:46] [info] Starting processing

dat422 avatar Feb 21 '23 13:02 dat422

How is your gateway configured? The mqtt_listener.topic_prefix that you currently have (ruuvi/+) means the listener subscribes to ruuvi/+/+ (as seen in the log). This should work if you have the gateway configured to publish to ruuvi/<gateway mac>/<ruuvitag mac> like so: image

On the other hand if your gateway was configured like this: image then the appropriate config for mqtt_listener.topic_prefix would be just ruuvi (like it's by default)

Scrin avatar Feb 21 '23 14:02 Scrin

This is exactly what I had taken from the config samlple. I configured the gateways like so: ruuvi

dat422 avatar Feb 21 '23 14:02 dat422

In that case the topic config seems correct, although in the config that you posted the listener is disabled, but the log shows it did start with the right config.

Have you checked that the gateway actually publishes the data under that topic? (for example MQTT-Explorer is a convenient tool for checking these kinds of things)

Another thing to check is that the client_id is different for the subscriber and publisher if you use the same MQTT server for both (like you seem to use based on the log), since RuuviBridge opens a separate connection for both and most MQTT servers disallow duplicate concurrent client ID's.

Scrin avatar Feb 21 '23 15:02 Scrin

Thanks for your quick reply. Sorry, I posted the config after reenabling the gateway polling (after trying to get mqtt listener running). First I thought that my mosquitto broker was not working, but I checked it with MQTT-Explorer and the mqtt_publisher works great. mqttexplorer

I also use different client_id like so: mqtt_listener: RuuviBridge_F1_12 mqtt_publisher: RuuviBridgePublisher_F1_12

the only thing that stays the same is the broker_url, username and password.

dat422 avatar Feb 21 '23 15:02 dat422

From your screenshot it looks like your gateway is not publishing under ruuvi topic. With the setup in your ruuvi gateway config screenshot it should look like this if the gateway is publishing data to MQTT: image the topics under ruuvi are the ones published by the gateway, and the topics under ruuvitag are the ones published by RuuviBridge

Scrin avatar Feb 21 '23 20:02 Scrin

Hi Scrin,

I was able to find out why it was not working. While configuring the gateway I used the hostname instead of the IP. Now everything works perfect.

dat422 avatar Feb 23 '23 17:02 dat422