Last active
May 5, 2017 13:14
-
-
Save eltonvs/504cc86fa828eda27a74f34c7eb9aaa4 to your computer and use it in GitHub Desktop.
Retrieve data from obd with python-OBD api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import obd | |
# Configure cli parser | |
parser = argparse.ArgumentParser() | |
parser.add_argument('port', help='enter the OBD port to retrieve data') | |
parser.add_argument( | |
'-d', | |
'--debug', | |
help='show debug messages', | |
action="store_true") | |
args = parser.parse_args() | |
# Enable debug messages | |
if args.debug: | |
obd.logger.setLevel(obd.logging.DEBUG) | |
# Set connection port | |
PORT = args.port | |
# Stablish a connection | |
conn = obd.OBD(PORT) | |
# Create a commands list | |
commands = [ | |
obd.commands.RPM, | |
obd.commands.SPEED, | |
obd.commands.THROTTLE_POS, | |
obd.commands.COOLANT_TEMP] | |
# Get responses | |
responses = [conn.query(command) for command in commands] | |
# Print responses | |
print('\n'.join(['{}: {}'.format(command.name, response.value) | |
for command, response in zip(commands, responses)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment