Commit Graph

35 Commits

Author SHA1 Message Date
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
6940fc1a10 Först incheckning av scripten 2020-12-30 13:42:22 +00:00