-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rb
49 lines (41 loc) · 1.3 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'json'
gem 'influxdb'
gem 'byebug'
end
# Change these hosts to match your environment
influxdb_host = '192.168.0.4'
connector_host = '192.168.0.5'
database = 'metrics'
name = 'connector'
influxdb = InfluxDB::Client.new host: influxdb_host, database: database
loop do
begin
response = Net::HTTP.get_response(connector_host,'/api/1/vitals')
body = JSON.parse(response.body, symbolize_names: true)
data = {
values: {
vehicle_connected: body[:vehicle_connected] ? 1 : 0,
vehicle_current_a: body[:vehicle_current_a],
currentA_a: body[:currentA_a],
currentB_a: body[:currentB_a],
currentC_a: body[:currentC_a],
voltageA_v: body[:voltageA_v],
voltageB_v: body[:voltageB_v],
voltageC_v: body[:voltageC_v],
grid_v: body[:grid_v],
grid_hz: body[:grid_hz],
handle_temp_c: body[:handle_temp_c],
mcu_temp_c: body[:mcu_temp_c],
pcba_temp_c: body[:pcba_temp_c],
energy_wh: body[:session_energy_wh]
}
}
resp = influxdb.write_point(name, data)
rescue Exception => e
puts "Error: #{e}"
end
sleep 10
end