WORK IN PROGRESS BY: H. Pandit
This document provides a comprehensive, end‑to‑end technical specification and usage guide for the n.Tec‑5 Front‑End web application.
- System Architecture
- Component Breakdown
- Development Environment Setup
- Detailed Installation
- Build & Distribution
- Runtime Configuration
- Code Walkthrough
- Error Handling & Logging
- Performance & Profiling
- Security Considerations
- Troubleshooting Guide
- Appendices
The n.Tec‑5 Front‑End is a Flask-based microservice providing a responsive web interface for visualizing real-time sensor data and model outputs. Key subsystems:
- RESTful Flask API backend
- CAN bus reader thread using
python-can - AI inference pipeline (TensorFlow)
- Static configuration (YAML)
- Web UI using Bootstrap + D3.js
The system reads sensor values from a CAN interface, buffers the data, passes it to a deep learning model for predictions, and updates the UI in real time using asynchronous fetches and EventSource streams.
- Flask app factory:
create_app() - Blueprints:
/api— Sensor data and AI predictions/ui— UI template rendering
- WS integration for streaming updates
- Class:
CanSensor - Interfaces with
python-can - Reads and decodes CAN frames into structured data
- Runs as a daemon thread
- Uses
cantoolsto parse DBC files
- Loads TensorFlow SavedModel
- Preprocessing: Normalization, window slicing
- Inference: Callable function returning anomaly scores or predictions
- Designed to support multiple output targets (e.g. heat, pressure)
- id: 0x0C
name: rpm
unit: rev/min
scale: 0.25
offset: 0- Sensor metadata and UI layout
- Sampling configuration
- Model normalization stats
templates/index.html: Bootstrap + Jinja2static/js/main.js: D3.js + EventSourcestatic/css/main.css: Custom layout
- Flask 2.2+
- python-can 4.2.2+
- tensorflow 2.11+
- cantools, PyYAML, gunicorn
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtsudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0git clone https://github.com/MykeHaunt/n.Tec-5---FRONT-END.git
cd n.Tec-5---FRONT-END/NTec_Web├── app.py
├── sensors.py
├── ai_model.py
├── base_map.yam
├── requirements.txt
├── static/
└── templates/
pip install -r requirements.txt- Create
app.specwith templates and static folders included indatas. - Build with:
pyinstaller --clean --onefile app.spec- Output binary at:
dist/NTec5_FrontEnd.exeordist/ntec5_frontend
FROM python:3.10-slim
RUN apt-get update && apt-get install -y can-utils
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
ENTRYPOINT ["python", "app.py"]version: '3.8'
services:
frontend:
build: .
ports: ["5000:5000"]
devices:
- "/dev/vcan0:/dev/vcan0"
privileged: trueCI pipeline runs tests, packages the binary, and pushes artifacts or Docker images to GitHub Packages.
CAN_CHANNEL— Defaults tocan0CAN_BITRATE— Defaults to500000MODEL_PATH— Path to TensorFlow model
- Initializes server
- Defines
/api/data,/api/predict,/routes - Injects
base_mapinto Jinja templates
class CanSensor:
def __init__(self, config):
self.bus = can.interface.Bus(**config)
self.buffer = deque(maxlen=config['buffer_size'])- Background thread reads from bus
- Catches errors and retries with backoff
- Loads model only on first call
- Preprocesses data (normalization, windowing)
- Returns dictionary of prediction scores
import logging
handler = logging.StreamHandler()
handler.setFormatter(JsonFormatter())SensorErrorModelErrorApiError
pip install locust
locust -f locustfile.pycProfilepy-spy- TensorBoard
- Use HTTPS + reverse proxy in production
- Sanitize all inputs to
/api/*routes - Restrict CORS origins
- Set Flask
SECRET_KEYsecurely
| Symptom | Cause | Fix |
|---|---|---|
| CAN data missing | Interface not configured | ip link set can0 up type can ... |
| Model is slow | TensorFlow batch too large | Reduce sliding window size |
| UI crashes | Invalid YAML or JavaScript bug | Validate base_map.yam and console logs |
| PyInstaller fails | Missing static/ or templates/ |
Include in .spec file |
Flask==2.2.2
python-can==4.2.2
cantools==36.2.0
PyYAML==6.0
tensorflow==2.11.0
gunicorn==20.1.0
version: '3.8'
services:
frontend:
build: .
ports:
- "5000:5000"
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
privileged: trueThis project is licensed under the MIT License — see the LICENSE file for details.
WORK IN PROGRESS BY: H. Pandit






