Skip to content

Commit

Permalink
Add plug poll time to influx data
Browse files Browse the repository at this point in the history
  • Loading branch information
bmhughes committed Jan 24, 2021
1 parent b981668 commit e3a302e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion influx_hs110_energy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
threads << Thread.new do
debug_message("Creating processing thread for plug #{plug_name}.") if options[:verbose]
begin
time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC) if options[:debug]
time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
plug = TpLinkSmartplugInflux::Plug.new(name: plug_name, address: config['address'])
%i(debug= verbose=).each { |opt| plug.send(opt, config[opt]) }

Expand All @@ -119,6 +119,7 @@
measurement_string = ''
measurement_string.concat("#{measurement},")
measurement_string.concat(plug.influx_line)
measurement_string.concat(",polltime=#{milliseconds_since(time_start)}")

measurement_strings.push(measurement_string)

Expand Down
7 changes: 7 additions & 0 deletions lib/tp_link_smartplug_influx/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def seconds_since(time)
(Process.clock_gettime(Process::CLOCK_MONOTONIC) - time).round(2)
end

# Get the number of milliseconds elapsed since the provided time.
# @param time [Float] Previous time input.
# @return [Integer] Milliseconds elapsed.
def milliseconds_since(time)
((Process.clock_gettime(Process::CLOCK_MONOTONIC) - time) * 1000).round
end

module TpLinkSmartplugInflux
# Module containing helper methods to be included within the base class.
#
Expand Down

0 comments on commit e3a302e

Please sign in to comment.