Add fix command and troubleshooting for errno=16 error

- Add 'fix' command to diagnose CEC connection issues
- Add detailed troubleshooting section for common errors
- Fix handles errno=16 (device busy) by checking processes and trying sudo
- Document solutions for CEC permission and connection issues

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 17:57:47 +01:00
parent ad963000f6
commit d0d0bb35a4
2 changed files with 87 additions and 3 deletions

View File

@@ -37,6 +37,7 @@ chmod +x cec-control.sh
| `scan` | Scan for CEC devices | `./cec-control.sh scan` | | `scan` | Scan for CEC devices | `./cec-control.sh scan` |
| `status` | Show CEC adapter status | `./cec-control.sh status` | | `status` | Show CEC adapter status | `./cec-control.sh status` |
| `info` | Show TV information | `./cec-control.sh info` | | `info` | Show TV information | `./cec-control.sh info` |
| `fix` | Troubleshoot connection issues | `./cec-control.sh fix` |
| `raw <command>` | Send raw CEC command | `./cec-control.sh raw 4f:82:10:00` | | `raw <command>` | Send raw CEC command | `./cec-control.sh raw 4f:82:10:00` |
| `help` | Show help message | `./cec-control.sh help` | | `help` | Show help message | `./cec-control.sh help` |
@@ -55,9 +56,48 @@ chmod +x cec-control.sh
## Troubleshooting ## Troubleshooting
- **CEC not working**: Make sure CEC is enabled in your TV settings ### Common Issues
- **Permission denied**: Run with `sudo` if needed
- **Device not found**: Check HDMI connection and try rescanning with `scan` command **ioctl CEC_S_MODE failed - errno=16 (Device or resource busy)**
This error means something else is using the CEC device. Try these solutions:
1. Run the built-in fix command:
```bash
./cec-control.sh fix
```
2. Kill any existing CEC processes:
```bash
sudo killall cec-client
```
3. Check what's using the device:
```bash
sudo lsof /dev/cec0
```
4. Try running with sudo:
```bash
sudo ./cec-control.sh scan
```
5. If using Kodi or LibreELEC, CEC may be enabled in the application. Disable it or stop the application first.
**CEC not working**
- Make sure CEC is enabled in your TV settings (often called "HDMI Control", "CEC Control", or branded names like "Bravia Link", "Anynet+", etc.)
- Try a different HDMI port on your TV
- Check that the HDMI cable is properly connected
**Permission denied**
- Add your user to the `video` group: `sudo usermod -aG video $USER`
- Then log out and back in
- Or run with `sudo`
**Device not found**
- Check if `/dev/cec0` exists: `ls -l /dev/cec0`
- Ensure `cec-utils` is installed
- Try rebooting the Pi
## Advanced Usage ## Advanced Usage

View File

@@ -41,6 +41,7 @@ Commands:
scan Scan for CEC devices scan Scan for CEC devices
status Show CEC adapter status status Show CEC adapter status
info Show TV information info Show TV information
fix Troubleshoot connection issues
raw <command> Send raw CEC command (hex) raw <command> Send raw CEC command (hex)
@@ -136,6 +137,46 @@ raw_command() {
send_command "tx $cmd" send_command "tx $cmd"
} }
fix_connection() {
echo "Attempting to fix CEC connection issues..."
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Checking for existing CEC processes..."
pgrep -a cec-client || echo "No cec-client processes found"
echo ""
echo "Trying with sudo - you may need to enter your password:"
echo ""
sudo "$0" "$@"
exit $?
fi
echo "Running as root - checking CEC device status..."
echo ""
# Check if device exists
if [ -e /dev/cec0 ]; then
echo "CEC device /dev/cec0 exists"
ls -l /dev/cec0
echo ""
# Check what's using the device
echo "Checking what's using the CEC device:"
lsof /dev/cec0 2>/dev/null || echo "Nothing is locking /dev/cec0"
echo ""
else
echo "Warning: /dev/cec0 does not exist"
echo "Available devices:"
ls -la /dev/cec* /dev/tty* 2>/dev/null | grep -E "cec|ttyAMA|ttyS0" || echo "No CEC devices found"
echo ""
fi
echo "Attempting to scan for devices..."
echo ""
$CEC_CLIENT -s -d 1 < /dev/null
}
# Main script logic # Main script logic
case "$1" in case "$1" in
tv-on) tv-on)
@@ -174,6 +215,9 @@ case "$1" in
info) info)
show_info show_info
;; ;;
fix)
fix_connection
;;
raw) raw)
raw_command "$2" raw_command "$2"
;; ;;