Skip to content

Commit 1c277ba

Browse files
pimpalemaheshesp
authored and
esp
committed
Add diagnostic parser in temperature measurement app
Add readme and requirements.txt file for diagnostics parser tool Restyled changes Readme update
1 parent 98dd18b commit 1c277ba

File tree

4 files changed

+1063
-0
lines changed

4 files changed

+1063
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Matter TLV Log Visualizer
2+
3+
This tool provides a web-based interface for visualizing and analyzing TLV
4+
(Tag-Length-Value) log data from Matter devices. It consists of a Python Flask
5+
server for parsing TLV files and a web app for visualization.
6+
7+
## Features
8+
9+
- Upload and parse TLV log files
10+
- Interactive charts and visualizations
11+
- Timeline view of PAKE/Sigma messages
12+
- Statistical analysis of log data
13+
- Detailed table view of all entries
14+
15+
## Requirements
16+
17+
- Python 3.6+
18+
- Matter SDK (CHIP)
19+
- Flask web server
20+
21+
## Installation
22+
23+
1. Create python environment
24+
25+
```
26+
python -m venv venv
27+
source venv/bin/activate
28+
```
29+
30+
2. Install the required Python packages:
31+
32+
```
33+
pip install -r requirements.txt
34+
```
35+
36+
3. Set the `CHIP_HOME` environment variable to point to your Matter (CHIP) SDK
37+
installation:
38+
```
39+
export CHIP_HOME=/path/to/connectedhomeip
40+
```
41+
42+
## Usage
43+
44+
1. Start the server:
45+
46+
```
47+
python tlv_server.py
48+
```
49+
50+
2. Open a web browser and navigate to:
51+
52+
```
53+
http://localhost:8000
54+
```
55+
56+
3. Upload a TLV log file or paste log data manually.
57+
58+
4. View visualizations across different tabs:
59+
- Overview: Summary of message types
60+
- Timeline: PAKE/Sigma message sequence
61+
- All Entries: Complete table of log entries
62+
- Statistics: Detailed analysis of the data
63+
64+
## Data Format
65+
66+
The tool expects TLV data with the following structure:
67+
68+
- Timestamp (tag 0)
69+
- Label (tag 1)
70+
- Value (tag 2)
71+
72+
## Troubleshooting
73+
74+
If you encounter import errors related to `chip.tlv`, ensure:
75+
76+
1. The `CHIP_HOME` environment variable is set correctly
77+
2. The Matter SDK is properly installed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask==2.0.1
2+
werkzeug==2.0.1
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import sys
3+
4+
from flask import Flask, jsonify, request, send_from_directory
5+
from werkzeug.utils import secure_filename
6+
7+
CHIP_HOME = os.getenv("CHIP_HOME")
8+
9+
if not CHIP_HOME:
10+
print("Error: Please set the CHIP_HOME environment variable.")
11+
sys.exit(1)
12+
13+
sys.path.insert(0, os.path.join(CHIP_HOME, 'src/controller/python'))
14+
try:
15+
from chip.tlv import TLVReader
16+
except ImportError:
17+
print("chip.tlv module not found. Ensure CHIP_HOME is set correctly.")
18+
sys.exit(1)
19+
20+
app = Flask(__name__)
21+
22+
UPLOAD_FOLDER = '/tmp'
23+
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
24+
25+
26+
@app.route('/')
27+
def index():
28+
"""Serve the HTML page"""
29+
return send_from_directory('.', 'tlv_viewer.html')
30+
31+
32+
@app.route('/parse_tlv', methods=['POST'])
33+
def parse_tlv():
34+
"""Handle TLV file uploads and return parsed data"""
35+
if 'tlv_file' not in request.files:
36+
return jsonify({'error': 'No file part'}), 400
37+
38+
file = request.files['tlv_file']
39+
if file.filename == '':
40+
return jsonify({'error': 'No selected file'}), 400
41+
42+
filename = secure_filename(file.filename)
43+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
44+
file.save(file_path)
45+
46+
try:
47+
with open(file_path, 'rb') as f:
48+
binary_data = f.read()
49+
50+
binary_data = bytes([0x17]) + binary_data + bytes([0x18])
51+
52+
t = TLVReader(binary_data)
53+
data = t.get()
54+
55+
entries = []
56+
for tag, entry in data['Any']:
57+
entries.append(entry)
58+
59+
formatted_entries = []
60+
for entry in entries:
61+
formatted_entries.append({
62+
'timestamp': entry.get(0, 0),
63+
'label': entry.get(1, ''),
64+
'value': entry.get(2, '')
65+
})
66+
67+
return jsonify(formatted_entries)
68+
except Exception as e:
69+
return jsonify({'error': str(e)}), 500
70+
71+
72+
if __name__ == '__main__':
73+
app.run(host='0.0.0.0', port=8000, debug=True)

0 commit comments

Comments
 (0)