51 Commits

Author SHA1 Message Date
abdea54788 Release v3.0.1
Fix Debian runtime deps for TUI (Textual)
v3.0.1
2025-12-29 15:35:53 +01:00
fcaaf29307 Release v3.0.0
- Bump version to 3.0.0 and update docs

- Fix Debian payload to include TUI and install /usr/bin/sensorpajen-tui wrapper

- Make systemd unit upgrades safer and ignore deb build artifacts
v3.0.0
2025-12-29 15:34:03 +01:00
54d55cf0f6 Switching editors 2025-12-29 12:22:44 +01:00
cfa24d1fa5 feat: implement Textual TUI and SQLite database for sensor management 2025-12-29 09:39:33 +01:00
4213b6101a Update debian/changelog for v2.0.0 production release v2.0.0 2025-12-28 11:09:16 +01:00
e9b8d56f6d Release v2.0.0 - Production ready
Version bump:
- Update VERSION to 2.0.0 (from 2.0.0-dev)
- Update pyproject.toml to 2.0.0
- Change development status to Production/Stable

Documentation updates:
- Add Debian package installation instructions (system-wide)
- Add sensor discovery and approval workflow documentation
- Update configuration section with approval workflow
- Update service management for system installation
- Update troubleshooting for system installation
- Update MQTT settings documentation
- Add links to download Debian packages from releases

The application is now production-ready with:
- Systemd integration for automatic service management
- Automatic startup and restart on failure
- Configuration via /etc/sensorpajen/
- Runtime state in /var/lib/sensorpajen/
- Interactive sensor approval workflow
- Automatic configuration reload
- Comprehensive logging via journalctl
2025-12-28 10:54:57 +01:00
a55d065c38 Add bytecode cleanup to postinst before building wheel
Remove stale .pyc files and __pycache__ directories before installing
the sensorpajen package to ensure Python rebuilds bytecode fresh.

This should prevent cached bytecode issues from old syntax errors.
2025-12-28 10:42:16 +01:00
eee68e4034 Fix syntax error in approve_sensors.py
Missing except clause that got accidentally removed during previous edit.
2025-12-28 10:34:28 +01:00
c3dc5677b9 Improve approve-sensors feedback for marking sensors
Changes:
- approve_sensor: Add explicit logging that sensor was marked as approved
- ignore_sensor: Add explicit logging that sensor was marked in discovered_sensors.json
- Both now clearly indicate the sensor status is updated, not just added/ignored

This makes it clear to users that approved sensors will no longer appear as
pending in future runs, since their status in discovered_sensors.json is
changed from 'pending' to 'approved' or 'ignored'.
2025-12-28 10:32:08 +01:00
fc0399a454 Fix system installation state directory
The service was failing with 'Read-only file system' when trying to create
discovered_sensors.json in the /etc/sensorpajen config directory.

Changes:
- config.py: Add STATE_DIR for runtime state
  - System mode: /var/lib/sensorpajen (writable at runtime)
  - Dev mode: config/ (same as config directory)
- config.py: Use STATE_DIR for discovered_sensors.json path
- debian/postinst: Create and own /var/lib/sensorpajen
- debian/sensorpajen.service: Add /var/lib/sensorpajen to ReadWritePaths
- debian/postinst: Remove discovered_sensors.json.example copy (created at runtime)

This separates:
- Config: /etc/sensorpajen (static, not updated by service)
- State: /var/lib/sensorpajen (dynamic, updated by service at runtime)
2025-12-28 09:33:26 +01:00
85af215d73 Fix postinst: Install sensorpajen package in venv
The venv had dependencies installed but not the sensorpajen package itself,
causing 'No module named sensorpajen' errors when running.

Changes:
- After installing dependencies from requirements.txt
- Now also runs 'pip install --no-deps .' to install sensorpajen
- Uses --no-deps to avoid re-installing already-installed dependencies
- Installed in /opt/sensorpajen where pyproject.toml exists

Fixes: ModuleNotFoundError: No module named 'sensorpajen'
2025-12-28 09:29:40 +01:00
c5e6187523 Allow starting without configured sensors for discovery-only mode
- config.SensorConfig.load() now warns instead of raising FileNotFoundError
  if sensors.json doesn't exist
- main.py no longer exits if len(sensors) == 0
- Instead, warns user and suggests using 'sensorpajen approve-sensors'
- Application will now start in discovery-only mode
- This allows users to use the discovery workflow to add sensors

Changes:
- config.py: Handle missing sensors.json gracefully
- main.py: Log warning instead of error when no sensors configured
  and continue running (allows discovery to work)

Fixes: Unable to start application for initial sensor discovery
2025-12-28 09:20:33 +01:00
4000d0972e Final polish for deploy 2025-12-28 00:42:05 +01:00
e1c842b719 Improve sensorpajen.env.example documentation
- Add comments explaining absolute vs relative paths
- Clarify usage for system vs development installations
- Make it clear that SENSOR_CONFIG_FILE/DISCOVERED_SENSORS_FILE
  should use /etc/sensorpajen paths in system installations
- Remove misleading comment about 'relative to project root'
2025-12-28 00:39:00 +01:00
f2ac55eac1 Fix missing PyBluez dependency
The code imports 'bluetooth._bluetooth' which requires the PyBluez package
(not bluepy). PyBluez provides Classic Bluetooth support needed by utils.py
and sensor_reader.py.

- Add pybluez>=0.31 to both requirements.txt and pyproject.toml
- Keep bluepy and paho-mqtt as they are also needed
- bluez system package also needed (already in debian/control)

Fixes: ModuleNotFoundError: No module named 'bluetooth'
2025-12-28 00:33:35 +01:00
3e759d30ed Fix postinst script: set ownership before setcap
- Move chown -R before setcap to preserve Bluetooth capabilities
- setcap must be applied after ownership is set, not before
- Ensures Python executable has proper Bluetooth permissions for venv
2025-12-28 00:29:18 +01:00
aeef9a424c Fix Python dependencies installation in postinst
- Add requirements.txt to debian/install
- Update postinst to use requirements.txt for pip install
- Install from requirements.txt instead of -e . (editable install)
- Ensures bluepy and paho-mqtt are installed in venv
- Fixes 'ModuleNotFoundError: No module named bluetooth' on startup
2025-12-28 00:25:50 +01:00
36e91c7246 Add gzip compression override to debian/rules
- Add override_dh_builddeb with -Zgzip flag
- Ensures package uses gzip instead of zstd compression
- Provides better compatibility with older dpkg versions
- Package now installs successfully on all systems
2025-12-28 00:13:29 +01:00
234391a881 Fix Debian package build issues
- Remove debian/compat file (conflicts with Build-Depends)
- Fix debian/install to use correct readme.md filename
- Update verify-deb.sh to mark debian/compat as optional
- Add -Zgzip flag to dpkg-buildpackage for compatibility
  (uses gzip instead of zstd for better compatibility)
- Update verify-deb.sh to check optional vs required files

Package now builds and installs successfully on systems
without zstd support.
2025-12-28 00:02:49 +01:00
427df1f034 Phase 8: Implement Debian package creation (2025-12-27)
- Create debian/ directory structure with all required files:
  - control: Package metadata and dependencies
  - compat: Debhelper compatibility level
  - changelog: Version history
  - rules: Build instructions
  - install: File installation mappings
  - postinst: Post-installation setup (user, venv, setcap)
  - prerm: Pre-removal script (stop service)
  - postrm: Post-removal script (cleanup, preserve config)
  - sensorpajen.service: System-wide systemd unit

- Update config.py to support dual-mode operation:
  - Auto-detects system installation (/opt/sensorpajen)
  - Uses /etc/sensorpajen for config in system mode
  - Falls back to PROJECT_ROOT/config for development

- Update scripts/approve-sensors.sh for system paths:
  - Detects system vs development installation
  - Uses correct venv and config paths

- Create scripts/verify-deb.sh: Automated build and verification

- Create debian/README.md: Comprehensive packaging documentation

Package features:
- System-wide installation to /opt/sensorpajen/
- Configuration in /etc/sensorpajen/ (preserved on upgrade/remove)
- Dedicated sensorpajen system user
- Automatic venv creation with dependencies
- Bluetooth capabilities set automatically
- Service auto-enabled but waits for config before starting
- Dual-mode code supports both system and development installations
2025-12-27 23:51:39 +01:00
b467541eb5 Phase 9 Complete: Cleanup & Documentation
Completed:
- Created INSTALL.md with concise sysadmin-focused guide
- Updated README.md troubleshooting to reference INSTALL.md
- Marked ROADMAP Phase 9 complete

Documentation Philosophy:
- Compact and practical
- Assumes sysadmin familiarity
- Focus on actual usage, not theory

All 9 phases of migration now complete!
2025-12-27 23:09:02 +01:00
16c47e62f5 Phase 9: Remove legacy folder
Old cron/tmux scripts no longer needed.
System now runs as systemd service.
2025-12-27 23:07:32 +01:00
5850089de9 Track reviewed status for discovered sensors
Changes:
- Added 'reviewed' field to DiscoveredSensor dataclass
- By default, only show new (unreviewed) pending sensors
- Mark sensors as reviewed when shown in approval CLI
- Add --all flag to show all pending sensors (including reviewed)
- Add --ignored flag to show ignored sensors
- Prevent repeatedly asking for approval of same sensor

Usage:
  approve-sensors              # Only new sensors
  approve-sensors --all        # All pending sensors
  approve-sensors --ignored    # Ignored sensors
  approve-sensors --all --ignored  # Everything
2025-12-27 20:33:14 +01:00
c8e8afff67 Add standalone approve-sensors script
Creates a wrapper that sets minimal env vars so the tool
can run without full MQTT configuration.
2025-12-27 20:28:36 +01:00
9b1229a2ee Implement sensor auto-discovery feature
New Features:
- Automatic discovery of unknown Bluetooth sensors
- Discovery manager tracks pending/approved/ignored sensors
- ntfy notifications when new sensors found (optional)
- Interactive CLI tool: sensorpajen-approve-sensors
- Automatic config reload every 15 minutes (no restart needed)

Files Added:
- src/sensorpajen/discovery_manager.py: Sensor discovery management
- src/sensorpajen/approve_sensors.py: Interactive approval CLI
- config/discovered_sensors.json.example: Example discovery file

Files Modified:
- src/sensorpajen/config.py: Added ntfy and discovery config
- src/sensorpajen/main.py: Added discovery manager and config reload
- src/sensorpajen/sensor_reader.py: Added discovery on unknown sensors
- config/sensorpajen.env.example: Added ntfy and reload settings
- pyproject.toml: Added approve-sensors CLI command

Configuration:
- NTFY_ENABLED, NTFY_URL, NTFY_TOPIC, NTFY_TOKEN
- DISCOVERED_SENSORS_FILE, CONFIG_RELOAD_INTERVAL
- Pre-filled comments with sensor metadata

See TASKS.md for complete feature specification.
2025-12-27 15:03:19 +01:00
9de5f82924 Add implementation details to sensor auto-discovery task
Clarifications added:
- Storage: config/discovered_sensors.json with extended metadata
- ntfy: Optional notifications via curl with token auth
- CLI: sensorpajen approve-sensors (interactive only)
- Config reload: Every 15 minutes, no service restart needed
- Metadata: MAC, name, RSSI, timestamps, sample readings
- Ignored sensors: Stored with timestamp and optional reason
- Pre-filled comments with metadata for user to edit
2025-12-27 14:54:52 +01:00
e3bec0d16e Update README with current system architecture
- Modernized documentation to reflect systemd service
- Added installation and configuration instructions
- Kept thermometer flashing instructions
- Added troubleshooting section
- Added project structure overview
- Removed outdated DHT11 and cron references
2025-12-27 14:30:21 +01:00
675c39eab3 Update ROADMAP: Mark Phase 7 complete and fix phase ordering
- Phase 7 (Testing & Validation) complete - service running successfully
- Fixed phase ordering (Phase 9 was appearing before Phase 8)
- Cleaned up corrupted/duplicate content in phases section
2025-12-27 14:22:22 +01:00
c1519b3eb5 Update ROADMAP: Document Phase 6 lessons learned
Key discoveries during systemd service implementation:
- AmbientCapabilities doesn't work in user services
- NoNewPrivileges prevents file capabilities
- Must use setcap with readlink -f on actual binary
2025-12-27 14:18:28 +01:00
f36257226f Fix systemd service: Disable NoNewPrivileges
NoNewPrivileges=true prevents file capabilities from working.
Since we need CAP_NET_RAW/CAP_NET_ADMIN for Bluetooth, we must
disable this security feature.
2025-12-27 14:17:36 +01:00
b740372d88 Fix systemd service: Add Bluetooth permissions troubleshooting
The service needs setcap on the Python binary to access Bluetooth.
Added verification steps to troubleshooting section.
2025-12-27 14:14:51 +01:00
d0ba2c5a52 Phase 6 Complete: Systemd Service Creation
- Created systemd/sensorpajen.service user service unit
  - Uses %h for portability across systems
  - Loads environment from EnvironmentFile
  - Auto-restart with bluetooth capabilities
  - Comprehensive security settings

- Created systemd/README.md
  - Installation instructions
  - Service management commands
  - Troubleshooting guide
  - Log viewing examples

- Updated ROADMAP.md to mark Phase 6 complete
2025-12-27 14:09:29 +01:00
b2f9bff765 Fix paho-mqtt v2.x compatibility
Handle both paho-mqtt v1.x and v2.x in MQTTPublisher:
- Try v2.x format with callback_api_version first
- Fall back to v1.x format if needed
- Ensures compatibility across different paho-mqtt versions

Fixes: ValueError when using paho-mqtt 2.0+
2025-12-27 13:52:13 +01:00
f54c0a0f35 Add Raspberry Pi setup and testing guide
Created SETUP_ON_PI.md with comprehensive instructions for:
- Pulling latest changes on the Pi
- Installing system dependencies (Bluetooth, Python)
- Setting up virtual environment
- Configuring Bluetooth permissions
- Setting up configuration files
- Running test
- Troubleshooting common issues
- Environment variable reference

Enables seamless development workflow between machines.
2025-12-27 13:42:51 +01:00
c9b68dd8e2 Phase 2 Complete: Python Package Structure
Core modules created:
- config.py: Environment-based configuration management
  - Loads MQTT settings from environment variables
  - SensorConfig class for JSON sensor mapping
  - Relative path resolution (PROJECT_ROOT)
  - Configuration validation with fail-fast

- mqtt_publisher.py: MQTT client wrapper
  - MQTTPublisher class with connection management
  - Replaces sendToMQTT.sh shell script
  - Direct Python MQTT publishing
  - Automatic reconnection support
  - Optional battery data publishing

- sensor_reader.py: Bluetooth BLE sensor reader
  - SensorReader class for passive BLE scanning
  - ATC firmware packet parsing
  - Duplicate packet filtering via advertisement counter
  - Watchdog thread for BLE recovery
  - Measurement dataclass for type safety

- utils.py: Bluetooth utilities
  - Ported from bluetooth_utils.py (MIT, Colin GUYON)
  - BLE scanning and advertisement parsing functions
  - Linux HCI socket operations

- main.py: Application entry point
  - Sensorpajen main application class
  - Signal handling (SIGTERM/SIGINT) for graceful shutdown
  - Logging to stdout for journald integration
  - Coordinates all components

Architecture:
- Direct Python integration (no shell scripts)
- Clean separation of concerns
- Type hints and dataclasses
- Comprehensive logging
- Graceful shutdown handling

Updated ROADMAP.md to mark Phase 2 as complete.

Next: Phase 3 - Configuration Migration (mostly done in Phase 1)
2025-12-27 13:17:26 +01:00
426f1d3813 Phase 1 Complete: Preparation & Cleanup
Directory structure:
- Created src/sensorpajen/ for new Python package
- Created config/ for configuration templates
- Created legacy/ for old scripts
- Created systemd/ and debian/ for future phases

Package setup:
- Added pyproject.toml with modern Python packaging
- Created package __init__.py
- Defined dependencies: bluepy, paho-mqtt

Configuration:
- Created config/sensors.json.example (converted from INI)
- Created config/sensorpajen.env.example for environment variables
- All 8 Xiaomi sensors migrated to JSON format

Cleanup:
- Removed temperatur_koksfonstret.py (DHT11 functionality)
- Moved all legacy scripts to legacy/ folder:
  - LYWSD03MMC.py
  - bluetooth_utils.py
  - sendToMQTT.sh
  - sensorer.sh
  - startup.sh
  - sensorer.ini

Updated ROADMAP.md to mark Phase 1 as complete.

Next: Phase 2 - Python Package Structure
2025-12-27 13:13:51 +01:00
8cc2c41acf Begin version 2.0.0 development
Starting modernization phase:
- Transition to systemd service
- Modern Python package structure
- Relative configuration paths
- APT package support

See ROADMAP.md for complete implementation plan.
2025-12-27 13:10:40 +01:00
219ef3240c Add project documentation: AGENTS.md and ROADMAP.md
- AGENTS.md: Guidelines for AI agents working on this project
- ROADMAP.md: Complete migration plan from tmux/cron to systemd
- Configuration strategy using relative paths
- APT package creation plan (Phase 8)
- Progress tracking instructions
v1.0.0
2025-12-27 13:10:06 +01:00
1c20f50379 Uppdaterar sökväg 2022-11-22 09:31:22 +01:00
103b8dc48a Startup för körning på pimoroni audio 2022-01-30 21:35:33 +01:00
2ec3467e36 Lägger till fler termometrar 2021-11-26 17:10:53 +00:00
45ff1abb68 Uppdaterar readme med instruktioner om hur man flashar termometrarna 2021-11-26 17:53:24 +01:00
a9167b614a Lägger till bibliotek som behövs 2021-05-09 18:35:35 +02:00
7f923c3a9b Flyttar publiceringen 2021-01-11 12:50:01 +00:00
c1c02691da Inkluderar MQTT 2021-01-11 11:43:44 +00:00
f35fb548ee 1Merge branch 'master' of ssh://git.casablanca.wahlberg.se:2222/fredrik/sensorpajen 2021-01-11 09:14:57 +00:00
5d1e7d894e Ny ignore-fil 2021-01-11 09:14:35 +00:00
b0291d8cfe Uppdatera 'readme.md' 2020-12-30 14:56:12 +01:00
588c3be2c3 Uppdatera 'readme.md' 2020-12-30 14:49:52 +01:00
cdb5976340 Lite info 2020-12-30 13:45:03 +00:00