Skip to content

Commit d3cf466

Browse files
author
3dprogramin
committed
gather voltage even if car is off
1 parent 55c7926 commit d3cf466

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
python-OBD
22
==========
33

4+
**Forked version**
5+
- Added voltage gathering even if car is off
6+
47
A python module for handling realtime sensor data from OBD-II vehicle
58
ports. Works with ELM327 OBD-II adapters, and is fit for the Raspberry
69
Pi.

obd/elm327.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def __init__(self, portname, baudrate, protocol, timeout,
120120
self.__low_power = False
121121
self.timeout = timeout
122122

123+
# custom
124+
self.___voltage = ''
125+
123126
# ------------- open port -------------
124127
try:
125128
self.__port = serial.serial_for_url(portname,
@@ -177,6 +180,8 @@ def __init__(self, portname, baudrate, protocol, timeout,
177180
# -------------------------- AT RV (read volt) ------------------------
178181
if check_voltage:
179182
r = self.__send(b"AT RV")
183+
# save voltage to instance (useful even if car turned off)
184+
self.___voltage = r
180185
if not r or len(r) != 1 or r[0] == '':
181186
self.__error("No answer from 'AT RV'")
182187
return
@@ -565,3 +570,8 @@ def __read(self):
565570
lines = [s.strip() for s in re.split("[\r\n]", string) if bool(s)]
566571

567572
return lines
573+
574+
@property
575+
def voltage(self):
576+
""" return the voltage saved on init """
577+
return self.___voltage

obd/obd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def __init__(self, portstr=None, baudrate=None, protocol=None, fast=True,
5959
self.__last_header = ECU_HEADER.ENGINE # for comparing with the previously used header
6060
self.__frame_counts = {} # keeps track of the number of return frames for each command
6161

62+
# custom vars
63+
self.___voltage = ''
64+
6265
logger.info("======================= python-OBD (v%s) =======================" % __version__)
6366
self.__connect(portstr, baudrate, protocol,
6467
check_voltage, start_low_power) # initialize by connecting and loading sensors
@@ -98,6 +101,7 @@ def __connect(self, portstr, baudrate, protocol, check_voltage,
98101
if self.interface.status() == OBDStatus.NOT_CONNECTED:
99102
# the ELM327 class will report its own errors
100103
self.close()
104+
else: self.___voltage = self.interface.voltage
101105

102106
def __load_commands(self):
103107
"""
@@ -313,3 +317,8 @@ def __build_command_string(self, cmd):
313317
cmd_string = b""
314318

315319
return cmd_string
320+
321+
@property
322+
def voltage(self):
323+
""" get the voltage gathered from interface on init """
324+
return self.___voltage

0 commit comments

Comments
 (0)