Tire Pressure Monitoring System Python Library
Project description
TPMS
Tyre Pressure Monitoring System Python Library
Overview
The TPMS (Tyre Pressure Monitoring System) Python library is designed to monitor tyre pressure and temperature for vehicles equipped with generic (aliexpress) TPMS sensors. This library has only been tested on the TY06 hardware type but should also work with TY05.
Despite looking obvious in thethe dongle casing in no way indicates what hardware is inside.
Features
- Supports TY06 and should also work with TY05 hardware versions (No idea for N variants)
- Serial port can be auto-detected or specified
- Temperature units: Celsius, Fahrenheit
- Pressure units: kPa, psi, bar
- Continuous monitoring of tyre pressure and temperature or oneshot function
Installation
Install the TPMS library using pip:
pip install tpms
Usage
You can run the TPMS library with default settings or customize the serial port, baud rate, temperature unit, pressure unit There are two methods of retreiving data, 'oneshot' which returns a dict containing data for each tyre and 'stream_updates' which returns data at a configurable update interval (defaulted to 0.5 seconds)
Example Code
oneshot
from tpms import TPMS
import time
def data_received(data):
"""
Callback function to display data received from the TPMS device.
This function could also log data to a file or database, send notifications, etc.
"""
print("Data received:")
for tyre, info in data.items():
print(f"Tyre Position: {tyre}")
print(f" Pressure: {info['Pressure']} psi") # Assuming psi for example
print(
f" Temperature: {info['Temperature']}° Fahrenheit"
) # Assuming Fahrenheit for example
status_messages = []
if info["Status"]["low_power"]:
status_messages.append("low power")
if info["Status"]["leakage"]:
status_messages.append("leakage")
if info["Status"]["no_signal"]:
status_messages.append("no signal")
print(
f" Status: {', '.join(status_messages) if status_messages else 'Normal'}"
)
print("")
def main():
"""
Main function to initialize the TPMS system and perform a oneshot data retrieval.
"""
# Initialize the TPMS system with full configuration
tpms_system = TPMS(
# port="/dev/ttyUSB0", # Adjust this to the correct serial port
baudrate=19200, # Set baud rate according to your device specifications
temp_unit="Fahrenheit", # Convert temperature readings to Fahrenheit
pressure_unit="psi", # Convert pressure readings to psi
debug=True, # Enable debug mode for detailed logging
)
# Perform a single data retrieval using the oneshot method
print("Performing a single data retrieval...")
single_data = tpms_system.oneshot()
if single_data:
print("Oneshot Data Retrieval Results:")
data_received(single_data)
else:
print("No data retrieved. Check device connection and settings.")
if __name__ == "__main__":
main()
stream
import time
from tpms import TPMS
def update_dashboard(data):
"""
Update the dashboard or console with the latest tyre data.
Args:
data (list): A list of dictionaries, each containing tyre data.
"""
for tyre_data in data:
if tyre_data:
print(f"Update for {tyre_data['Position']}:")
print(f" Pressure: {tyre_data['Pressure']} kPa")
print(f" Temperature: {tyre_data['Temperature']} Celsius")
print(
f" Status: {', '.join([k for k, v in tyre_data['Status'].items() if v]) or 'Normal'}"
)
print("")
def main():
# Initialize the TPMS system with a callback function
tpms_system = TPMS(
# port="/dev/ttyUSB0", # Adjust to your serial port
baudrate=19200,
temp_unit="Celsius",
pressure_unit="kPa",
callback=update_dashboard,
debug=False,
update_interval=0.3,
)
# Start the continuous streaming of updates
try:
tpms_system.stream_updates()
except Exception as e:
print(f"An error occurred: {e}")
finally:
print("Monitoring stopped or failed to start.")
if __name__ == "__main__":
main()
TLDR
pip install TPMS
from tpms import TPMS
import time
tpms_system = TPMS(
# port="/dev/ttyUSB0", # Adjust this to the correct serial port (optional)
temp_unit="Fahrenheit", # Convert temperature readings to Fahrenheit
pressure_unit="psi", # Convert pressure readings to psi
debug=False, # Enable debug mode for detailed logging
)
data = tpms_system.oneshot()
for tyre, info in data.items():
print(tyre, info)
TODO
Tyre exchange & sensor pairing functions
Issues or pull requests gladly recieved
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tpms-1.0.1.tar.gz
.
File metadata
- Download URL: tpms-1.0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c26e4139fab9269ba58ac9229379d63764b6197ed0727d4d1856991e8176370 |
|
MD5 | 9d6e666442f4727bb451bdab9ad72768 |
|
BLAKE2b-256 | 53172ec48c2d252ff7e084f389b18d01fc62e5df821cb8c1784d802d35c28ba4 |
File details
Details for the file tpms-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: tpms-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4fd169de3e267e60f7d5c3ed1d99ebc766aadb3e187419d6149dffb93eb9507 |
|
MD5 | d6352ec302484d3508384b8115bb1a87 |
|
BLAKE2b-256 | 6e0e87c42d705854d9470bc2b3dc24c7fb9533e3bb47ea6391dcb8a6e2238532 |