-
Notifications
You must be signed in to change notification settings - Fork 0
/
pijuice.chart.py
124 lines (107 loc) · 4.69 KB
/
pijuice.chart.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
# Description: PiJuice netdata collector to monitor battery and voltage, python.d module
# Author: (r-sherwood)
# Source: https://github.com/r-sherwood/PiJuice-netdata
# SPDX-License-Identifier: GPL-3.0-or-later
from bases.FrameworkServices.SimpleService import SimpleService
from pijuice import PiJuice
from pijuice import __version__ as library_version
NETDATA_UPDATE_EVERY=1
priority = 90000
ORDER = [
"charge_current",
"batteryVoltage_current",
"batteryCurrent_current",
"temp_current",
"ioVoltage_current",
"ioCurrent_current"
]
CHARTS = {
"temp_current": {
'options': ['batteryTemperature', 'Battery temperature', 'Celsius', 'battery', 'pijuice.GetBatteryTemperature', 'line'],
'lines': [
['tempHot','hot temperature', 'absolute', 1, 1],
['batteryTemperature','current temperature', 'absolute', 1, 1],
['tempCold','cold temperature', 'absolute', 1, 1],
]
},
"charge_current": {
'options': ['batteryCharge', 'Battery charge level', '%', 'battery', 'pijuice.GetChargeLevel', 'stacked'],
'lines': [
['batteryChargeFull', 'till fully charged'],
['batteryCharge', 'charge level', 'absolute', 1, 1],
]
},
"batteryVoltage_current": {
'options': ['batteryVoltage', 'Battery voltage', 'V', 'battery', 'pijuice.GetBatteryVoltage', 'line'],
'lines': [
['regulationVoltage', 'regulation voltage', 'absolute', 1, 1000],
['batteryVoltage', 'voltage', 'absolute', 1, 1000],
['cutoffVoltage', 'cutoff voltage', 'absolute', 1, 1000],
]
},
"batteryCurrent_current": {
'options': ['batteryCurrent', 'Battery current', 'A', 'battery', 'pijuice.GetBatteryCurrent', 'line'],
'lines': [
['batteryCurrent', 'current', 'absolute', 1, 1000],
]
},
"ioVoltage_current": {
'options': ['ioVoltage', 'Voltage supplied from the GPIO power output from the PiJuice or when charging', 'V', 'power input', 'pijuice.GetIoVoltage', 'line'],
'lines': [
['ioVoltage', 'voltage', 'absolute', 1, 1000]
]
},
"ioCurrent_current": {
'options': ['ioCurrent', 'Current supplied from the GPIO power output from the PiJuice or when charging. Positive current is from PiJuice to Raspberry Pi', 'A', 'power input', 'pijuice.GetIoCurrent', 'line'],
'lines': [
['ioCurrent', 'current', 'absolute', 1, 1000],
]
}
}
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
#values to show at graphs
self.values=dict()
@staticmethod
def check():
return True
def logMe(self,msg):
self.debug(msg)
def get_data(self):
#The data dict is basically all the values to be represented
# The entries are in the format: { "dimension": value}
#And each "dimension" should belong to a chart.
data = dict()
pij_data = dict()
pijuice = PiJuice(1, 0x14) # Instantiate PiJuice interface object
status = pijuice.status.GetStatus()["data"]
profile = pijuice.config.GetBatteryProfile()["data"]
pij_data = {
"batteryCharge": pijuice.status.GetChargeLevel()["data"],
"batteryVoltage": pijuice.status.GetBatteryVoltage()["data"],
"batteryCurrent": pijuice.status.GetBatteryCurrent()["data"],
"batteryTemperature": pijuice.status.GetBatteryTemperature()["data"],
"batteryStatus": status["battery"],
"powerInput": status["powerInput"],
"powerInput5vIo": status["powerInput5vIo"],
"ioVoltage": pijuice.status.GetIoVoltage()["data"],
"ioCurrent": pijuice.status.GetIoCurrent()["data"],
"regulationVoltage": pijuice.config.GetBatteryProfile()["data"],
}
data['batteryCharge'] = pij_data['batteryCharge']
data['batteryChargeFull'] = 100-pij_data['batteryCharge']
data['batteryVoltage'] = pij_data['batteryVoltage']
data['batteryCurrent'] = pij_data['batteryCurrent']
data['batteryTemperature'] = pij_data['batteryTemperature']
data['ioVoltage'] = pij_data['ioVoltage']
data['ioCurrent'] = pij_data['ioCurrent']
data['batteryStatus'] = pij_data['batteryStatus']
data['regulationVoltage'] = profile['regulationVoltage']
data['cutoffVoltage'] = profile['cutoffVoltage']
data['tempHot'] = profile['tempHot']
data['tempCold'] = profile['tempCold']
return data