diff --git a/SETUP_ON_PI.md b/SETUP_ON_PI.md index d9120fe..baab811 100644 --- a/SETUP_ON_PI.md +++ b/SETUP_ON_PI.md @@ -34,7 +34,7 @@ source .venv/bin/activate ### 4. Install Python Dependencies ```bash pip install --upgrade pip -pip install bluepy paho-mqtt +pip install pybluez bluepy paho-mqtt # Or install the package in development mode pip install -e . @@ -43,8 +43,12 @@ pip install -e . ### 5. Set Bluetooth Capabilities This allows Python to access Bluetooth without sudo: ```bash -# Set capabilities on the Python interpreter in the venv -sudo setcap 'cap_net_raw,cap_net_admin+eip' .venv/bin/python3 +# Set capabilities on the actual Python binary (not the symlink) +sudo setcap 'cap_net_raw,cap_net_admin+eip' $(readlink -f .venv/bin/python3) + +# Verify it was set correctly +getcap $(readlink -f .venv/bin/python3) +# Should show: cap_net_raw,cap_net_admin+eip ``` ### 6. Configure the Application @@ -88,13 +92,13 @@ Press Ctrl+C to stop. If you get permission errors: ```bash # Check if capabilities are set -getcap .venv/bin/python3 +getcap $(readlink -f .venv/bin/python3) # If not set, run: -sudo setcap 'cap_net_raw,cap_net_admin+eip' .venv/bin/python3 +sudo setcap 'cap_net_raw,cap_net_admin+eip' $(readlink -f .venv/bin/python3) # Verify Bluetooth device is up -hciconfig hci0 up +sudo hciconfig hci0 up ``` ### MQTT Connection Issues diff --git a/src/sensorpajen/mqtt_publisher.py b/src/sensorpajen/mqtt_publisher.py index 5583fb1..4cabdbd 100644 --- a/src/sensorpajen/mqtt_publisher.py +++ b/src/sensorpajen/mqtt_publisher.py @@ -23,7 +23,16 @@ class MQTTPublisher: def _setup_client(self): """Setup MQTT client with callbacks.""" - self.client = mqtt.Client(config.MQTT_CLIENT_ID) + # Handle both paho-mqtt v1.x and v2.x + try: + # Try v2.x format (with callback_api_version) + self.client = mqtt.Client( + callback_api_version=mqtt.CallbackAPIVersion.VERSION1, + client_id=config.MQTT_CLIENT_ID + ) + except (TypeError, AttributeError): + # Fall back to v1.x format + self.client = mqtt.Client(config.MQTT_CLIENT_ID) # Set credentials if provided if config.MQTT_USER and config.MQTT_PASSWORD: