initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
2.7.4
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gem 'mqtt'
|
||||||
|
gem 'rubocop'
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
ast (2.4.2)
|
||||||
|
mqtt (0.5.0)
|
||||||
|
parallel (1.21.0)
|
||||||
|
parser (3.0.2.0)
|
||||||
|
ast (~> 2.4.1)
|
||||||
|
rainbow (3.0.0)
|
||||||
|
regexp_parser (2.1.1)
|
||||||
|
rexml (3.2.5)
|
||||||
|
rubocop (1.22.1)
|
||||||
|
parallel (~> 1.10)
|
||||||
|
parser (>= 3.0.0.0)
|
||||||
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
|
regexp_parser (>= 1.8, < 3.0)
|
||||||
|
rexml
|
||||||
|
rubocop-ast (>= 1.12.0, < 2.0)
|
||||||
|
ruby-progressbar (~> 1.7)
|
||||||
|
unicode-display_width (>= 1.4.0, < 3.0)
|
||||||
|
rubocop-ast (1.12.0)
|
||||||
|
parser (>= 3.0.1.1)
|
||||||
|
ruby-progressbar (1.11.0)
|
||||||
|
unicode-display_width (2.1.0)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
mqtt
|
||||||
|
rubocop
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.1.4
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
2021-10-19 22:22:08 +0200,Test Sensor,62.97,26.99,972,100,3195,46
|
||||||
|
@@ -0,0 +1,46 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'mqtt'
|
||||||
|
require 'json'
|
||||||
|
require 'CSV'
|
||||||
|
|
||||||
|
# MQTT Server configuration
|
||||||
|
SERVER = '192.168.178.48'
|
||||||
|
|
||||||
|
# Sensor configuration
|
||||||
|
sensors = {
|
||||||
|
'zigbee2mqtt/0x00158d00073a7ba8': {
|
||||||
|
'name': 'Test Sensor',
|
||||||
|
'min_humidity': 61,
|
||||||
|
'max_humidity': 64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Connect to the MQTT broker
|
||||||
|
MQTT::Client.connect(SERVER) do |client|
|
||||||
|
# For each sensor
|
||||||
|
sensors.each_key do |sensor_topic|
|
||||||
|
sensor = sensors[sensor_topic]
|
||||||
|
# Subscribe its topic
|
||||||
|
client.get(sensor_topic.to_s) do |topic, message|
|
||||||
|
# Log the output
|
||||||
|
puts "#{sensor[:name]}: #{message}"
|
||||||
|
|
||||||
|
payload = JSON.parse(message)
|
||||||
|
|
||||||
|
# Log payload in a csv file
|
||||||
|
CSV.open('data.csv', 'wb') do |csv|
|
||||||
|
csv << [Time.now,
|
||||||
|
sensor[:name],
|
||||||
|
topic,
|
||||||
|
payload['humidity'],
|
||||||
|
payload['temperature'],
|
||||||
|
payload['pressure'],
|
||||||
|
payload['battery'],
|
||||||
|
payload['voltage'],
|
||||||
|
payload['linkquality']]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user