- 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
- 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
- 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.
- 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
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!
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
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
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
NoNewPrivileges=true prevents file capabilities from working.
Since we need CAP_NET_RAW/CAP_NET_ADMIN for Bluetooth, we must
disable this security feature.
- 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
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+
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.
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)
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
Starting modernization phase:
- Transition to systemd service
- Modern Python package structure
- Relative configuration paths
- APT package support
See ROADMAP.md for complete implementation plan.
- 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