Issue with USB Passthrough?

gdarends

Explorer
Joined
Jan 20, 2015
Messages
72
Hi,

I have just installed Bluefin. Needed the USB Passthrough feature for a VM.
I used the Home Assistant image and everything works fine, except that the Conbee II device I have isn't working as it should.
So I wanted to see if I'm doing something wrong with setting up USB Passthrough or if there is something else wrong.
I've setup the USB Controller Type as "qemu-xhci" and selected the USB device from the list.
root@truenas[~]# lspci | grep
USB 00:14.0 USB controller: Intel Corporation Cannon Lake PCH USB 3.1 xHCI Host Controller (rev 10)
Screen Shot 2022-11-23 at 08.26.26.png

When I boot the VM I get the following in the console log of TrueNAS. At the end of the log it has some output relating to the USB device "usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use"
Is there something wrong here or is this normal?
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.257:80): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685386 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.345:81): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685389 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.437:82): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685400 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.525:83): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685404 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered disabled state
Nov 23 08:16:08 truenas kernel: device vnet10 entered promiscuous mode
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered listening state
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.689:84): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685416 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.257:80): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685386 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.345:81): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685389 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.437:82): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685400 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.525:83): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685404 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered disabled state
Nov 23 08:16:08 truenas kernel: device vnet10 entered promiscuous mode
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered listening state
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.689:84): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685416 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.257:80): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685386 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.345:81): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685389 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.437:82): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685400 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.525:83): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685404 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered disabled state
Nov 23 08:16:08 truenas kernel: device vnet10 entered promiscuous mode
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered listening state
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.689:84): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685416 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.257:80): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685386 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.345:81): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685389 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.437:82): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685400 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.525:83): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685404 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered disabled state
Nov 23 08:16:08 truenas kernel: device vnet10 entered promiscuous mode
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered listening state
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.689:84): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685416 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.257:80): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685386 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.345:81): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685389 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.437:82): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685400 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.525:83): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685404 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered disabled state
Nov 23 08:16:08 truenas kernel: device vnet10 entered promiscuous mode
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered listening state
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.689:84): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685416 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.257:80): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685386 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.345:81): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685389 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.437:82): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685400 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.525:83): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685404 comm="apparmor_parser"
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered disabled state
Nov 23 08:16:08 truenas kernel: device vnet10 entered promiscuous mode
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered blocking state
Nov 23 08:16:08 truenas kernel: br0: port 2(vnet10) entered listening state
Nov 23 08:16:08 truenas kernel: audit: type=1400 audit(1669205768.689:84): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-963ce382-2b7c-498a-928b-8cabe67f0fe4" pid=685416 comm="apparmor_parser"
Nov 23 08:16:23 truenas kernel: br0: port 2(vnet10) entered learning state
Nov 23 08:16:23 truenas kernel: br0: port 2(vnet10) entered learning state
Nov 23 08:16:23 truenas kernel: br0: port 2(vnet10) entered learning state
Nov 23 08:16:23 truenas kernel: br0: port 2(vnet10) entered learning state
Nov 23 08:16:23 truenas kernel: br0: port 2(vnet10) entered learning state
Nov 23 08:16:23 truenas kernel: br0: port 2(vnet10) entered learning state
Nov 23 08:16:38 truenas kernel: br0: port 2(vnet10) entered forwarding state
Nov 23 08:16:38 truenas kernel: br0: topology change detected, propagating
Nov 23 08:16:38 truenas kernel: br0: port 2(vnet10) entered forwarding state
Nov 23 08:16:38 truenas kernel: br0: topology change detected, propagating
Nov 23 08:16:38 truenas kernel: br0: port 2(vnet10) entered forwarding state
Nov 23 08:16:38 truenas kernel: br0: topology change detected, propagating
Nov 23 08:16:38 truenas kernel: br0: port 2(vnet10) entered forwarding state
Nov 23 08:16:38 truenas kernel: br0: topology change detected, propagating
Nov 23 08:16:38 truenas kernel: br0: port 2(vnet10) entered forwarding state
Nov 23 08:16:38 truenas kernel: br0: topology change detected, propagating
Nov 23 08:16:38 truenas kernel: br0: port 2(vnet10) entered forwarding state
Nov 23 08:16:38 truenas kernel: br0: topology change detected, propagating
Nov 23 08:19:15 truenas kernel: audit: type=1400 audit(1669205955.161:85): apparmor="DENIED" operation="capable" profile="libvirtd" pid=4994 comm="rpc-worker" capability=38 capname="perfmon"
Nov 23 08:19:15 truenas kernel: audit: type=1400 audit(1669205955.161:85): apparmor="DENIED" operation="capable" profile="libvirtd" pid=4994 comm="rpc-worker" capability=38 capname="perfmon"
Nov 23 08:19:15 truenas kernel: audit: type=1400 audit(1669205955.161:85): apparmor="DENIED" operation="capable" profile="libvirtd" pid=4994 comm="rpc-worker" capability=38 capname="perfmon"
Nov 23 08:19:15 truenas kernel: audit: type=1400 audit(1669205955.161:85): apparmor="DENIED" operation="capable" profile="libvirtd" pid=4994 comm="rpc-worker" capability=38 capname="perfmon"
Nov 23 08:19:15 truenas kernel: audit: type=1400 audit(1669205955.161:85): apparmor="DENIED" operation="capable" profile="libvirtd" pid=4994 comm="rpc-worker" capability=38 capname="perfmon"
Nov 23 08:19:15 truenas kernel: audit: type=1400 audit(1669205955.161:85): apparmor="DENIED" operation="capable" profile="libvirtd" pid=4994 comm="rpc-worker" capability=38 capname="perfmon"
Nov 23 08:19:21 truenas kernel: usb 1-8: reset full-speed USB device number 64 using xhci_hcd
Nov 23 08:19:21 truenas kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
Nov 23 08:19:21 truenas kernel: usb 1-8: reset full-speed USB device number 64 using xhci_hcd
Nov 23 08:19:21 truenas kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
Nov 23 08:19:21 truenas kernel: usb 1-8: reset full-speed USB device number 64 using xhci_hcd
Nov 23 08:19:21 truenas kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
Nov 23 08:19:21 truenas kernel: usb 1-8: reset full-speed USB device number 64 using xhci_hcd
Nov 23 08:19:21 truenas kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
Nov 23 08:19:21 truenas kernel: usb 1-8: reset full-speed USB device number 64 using xhci_hcd
Nov 23 08:19:21 truenas kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
Nov 23 08:19:21 truenas kernel: usb 1-8: reset full-speed USB device number 64 using xhci_hcd
Nov 23 08:19:21 truenas kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
Nov 23 08:19:22 truenas kernel: usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use
Nov 23 08:19:22 truenas kernel: usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use
Nov 23 08:19:22 truenas kernel: usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use
Nov 23 08:19:22 truenas kernel: usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use
Nov 23 08:19:22 truenas kernel: usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use
Nov 23 08:19:22 truenas kernel: usb 1-8: usbfs: process 698384 (CPU 0/KVM) did not claim interface 0 before use
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I'm not sure about the ConBee specifically - But in general, I'm having success using the nec-xhci controller type.

2886dfc19eb20d09644cb29832d948e8d7788bb9.png
 

gdarends

Explorer
Joined
Jan 20, 2015
Messages
72

Kruku

Cadet
Joined
Feb 22, 2023
Messages
1
Hi,
have You passthrough yours Conbee? I see mine on my VM but i can't connect to it via deconz or i can't add Conbee as a Device.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I also ordered a ConBee II for testing purposes, and I'm facing getting the same error.

I found this link (among others) on Google - Although this report is for HAOS running in KVM on an Ubuntu host.


After reading through, I followed the suggestion to blacklist the cdc_acm module

Code:
system advanced update kernel_extra_options="module_blacklist=cdc_acm"


After blacklisting the module, I have the same issue mentioned in the link: KVM/QEMU doesn't claim the USB device again after the device resets.

Code:
[92424.247129] usb 1-6: reset full-speed USB device number 58 using xhci_hcd
[92425.316789] usb 1-6: usbfs: process 1158099 (CPU 0/KVM) did not claim interface 0 before use



For lack of better ideas, I'm going to see if I can figure out how to update the firmware on the ConBee II and see if that helps.

EDIT: No, it did not help


On a related side note, I have seen similar suggestions to try blacklisting the cp210x module, which I tried first but had no effect. I also dug up my old NORTEK HUSBZB-1, which also uses the cp210x module, and it shows up / works in my HAOS VM without needing to blacklist the module first.
 
Last edited:

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I'm not sure if this is an issue with KVM or the ConBee II itself, but I think it's unlikely related directly to TrueNAS or any middleware voodoo.

I've installed virt-manager with QEMU/KVM on my desktop (Arch), created a VM with HAOS, and tried adding the ConBee II - I'm getting the same error as on Scale.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I sorta got the ConBee II working. Seems like it needs to be added as a serial device instead of USB.

1677422366694.png


I found the answer in the post below



Don't get too excited though, you'll need to start your VM with a script (or run some commands every time it starts) to make it work.

Does anyone know if it's possible to attach a serial device to a VM using the API?
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
It will get annoying to start your VM this way, but if you don’t restart your TrueNAS or HAOS very often, it’s at least something for now.

1. Save this script to your TrueNAS and make it executable.
2. Edit line 4 and set the name of your HAOS VM.
3. Run the script to start your VM.

This will attach the ConBee II to your VM before Home Assistant or any add-ons have a chance to start.


Code:
#!/bin/bash

## Set the name of your VM
vm='HomeAssistant'


if [ ${EUID} -ne 0 ]; then
  echo "Please run this script as root or using sudo" ; exit
elif [ -z "${CONBEE:="$(ls /dev/serial/by-id/*ConBee_II*)"}" ]; then
  echo "ConBee II not found" ; exit
fi

## HEREDOC: ConBee_II.xml
read -r -d '' XML << END_XML
<serial type="dev">
  <source path="${CONBEE}"/>
  <target type="usb-serial" port="1">
    <model name="usb-serial"/>
  </target>
  <address type="usb" bus="0" port="4"/>
</serial>
END_XML

# create a temporary file containing the ConBee II HEREDOC
conbee_xml=$(mktemp -t conbee.xml.XXXXX)
echo "${XML}" > "${conbee_xml}"

# get id and use it to start the VM
id=$(/usr/bin/midclt call vm.query | /usr/bin/jq -r '.[] | ( .id|tostring ) + ":" + .name' | /usr/bin/grep "${vm}" | /usr/bin/cut -f1 -d':')
/usr/bin/midclt call vm.start "${id}" &> /dev/null
sleep 1

# get VM name and use it to attach the ConBee_II
name=$(/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" list --name | /usr/bin/grep "${vm}")
/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" attach-device "${name}" "${conbee_xml}"

# remove the temporary file
rm "${conbee_xml}"
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
Forget my script... Check the link below. I think the following post is more convenient and correct

 

juless

Dabbler
Joined
Jan 3, 2023
Messages
10
Forget my script... Check the link below. I think the following post is more convenient and correct

Hello,

On my PC i can't use PCI passtrough so i try to adapt your script for my RFXcom et sonoff usb dongle.
RFXCOM spec:
DEVLINKS: >-
/dev/serial/by-id/usb-RFXCOM_RFXtrx433XL_DO5QYRWW-if00-port0
/dev/serial/by-path/pci-0000:00:04.0-usb-0:2:1.0-port0
DEVNAME: /dev/ttyUSB0
DEVPATH: /devices/pci0000:00/0000:00:04.0/usb1/1-2/1-2:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS: usb
ID_MODEL: RFXtrx433XL
ID_MODEL_ENC: RFXtrx433XL
ID_MODEL_ID: '6015'
ID_PATH: pci-0000:00:04.0-usb-0:2:1.0
ID_PATH_TAG: pci-0000_00_04_0-usb-0_2_1_0
ID_REVISION: '1000'
ID_SERIAL: RFXCOM_RFXtrx433XL_DO5QYRWW
ID_SERIAL_SHORT: DO5QYRWW
ID_TYPE: generic

sonoff usb dongle spec:
DEVLINKS: >-
/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0
/dev/serial/by-path/pci-0000:00:04.0-usb-0:1:1.0-port0
DEVNAME: /dev/ttyUSB1
DEVPATH: /devices/pci0000:00/0000:00:04.0/usb1/1-1/1-1:1.0/ttyUSB1/tty/ttyUSB1
ID_BUS: usb
ID_MODEL: Sonoff_Zigbee_3.0_USB_Dongle_Plus
ID_MODEL_ENC: Sonoff\x20Zigbee\x203.0\x20USB\x20Dongle\x20Plus
ID_MODEL_ID: ea60
ID_PATH: pci-0000:00:04.0-usb-0:1:1.0
ID_PATH_TAG: pci-0000_00_04_0-usb-0_1_1_0
ID_REVISION: '0100'
ID_SERIAL: Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001
ID_SERIAL_SHORT: '0001'
ID_TYPE: generic

I try to adapt your script:

#!/bin/bash

## Set the name of your VM
vm='haas3'

## RFXCOM

if [ ${EUID} -ne 0 ]; then
echo "Please run this script as root or using sudo" ; exit
elif [ -z "${RFX:="$(ls /dev/serial/by-id/*RFXtrx433XL*)"}" ]; then
echo "RFXtrx433XL not found" ; exit
fi

## HEREDOC: RFX.xml
read -r -d '' XML << END_XML
<serial type="dev">
<source path="${RFX}"/>
<target type="usb-serial" port="1">
<model name="usb-serial"/>
</target>
<address type="usb" bus="0" port="4"/>
</serial>
END_XML

# create a temporary file containing the RFXtrx433XL HEREDOC
RFX_xml=$(mktemp -t RFX.xml.XXXXX)
echo "${XML}" > "${RFX_xml}"

# get id and use it to start the VM
id=$(/usr/bin/midclt call vm.query | /usr/bin/jq -r '.[] | ( .id|tostring ) + ":" + .name' | /usr/bin/grep "${vm}" | /usr/bin/cut -f1 -d':')
/usr/bin/midclt call vm.start "${id}" &> /dev/null
sleep 1

# get VM name and use it to attach the RFXtrx433XL
name=$(/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" list --name | /usr/bin/grep "${vm}")
/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" attach-device "${name}" "${RFX_xml}"

# remove the temporary file
rm "${RFX_xml}"



## ZIGBBE DONGLE

if [ ${EUID} -ne 0 ]; then
echo "Please run this script as root or using sudo" ; exit
elif [ -z "${ZIGBEE:="$(ls /dev/serial/by-id/*Sonoff_Zigbee_3.0_USB_Dongle_Plus*)"}" ]; then
echo "Sonoff_Zigbee_3.0_USB_Dongle_Plus not found" ; exit
fi

## HEREDOC: ZIGBEE.xml
read -r -d '' XML << END_XML
<serial type="dev">
<source path="${ZIGBEE}"/>
<target type="usb-serial" port="1">
<model name="usb-serial"/>
</target>
<address type="usb" bus="0" port="4"/>
</serial>
END_XML

# create a temporary file containing the Sonoff_Zigbee_3.0_USB_Dongle_Plus HEREDOC
ZIGBEE_xml=$(mktemp -t ZIGBEE.xml.XXXXX)
echo "${XML}" > "${ZIGBEE_xml}"

# get id and use it to start the VM
id=$(/usr/bin/midclt call vm.query | /usr/bin/jq -r '.[] | ( .id|tostring ) + ":" + .name' | /usr/bin/grep "${vm}" | /usr/bin/cut -f1 -d':')
/usr/bin/midclt call vm.start "${id}" &> /dev/null
sleep 1

# get VM name and use it to attach the Sonoff_Zigbee_3.0_USB_Dongle_Plus
name=$(/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" list --name | /usr/bin/grep "${vm}")
/usr/bin/virsh -c "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" attach-device "${name}" "${ZIGBEE_xml}"

# remove the temporary file
rm "${ZIGBEE_xml}"

But the result was:
root@truenas[~]# sh /mnt/Documents/Documents_communs/script.sh
: not foundnts/Documents_communs/script.sh: 2:
: not foundnts/Documents_communs/script.sh: 5:
: not foundnts/Documents_communs/script.sh: 7:
/mnt/Documents/Documents_communs/script.sh: 10: Syntax error: "elif" unexpected (expecting "then")

Can you please help i am stuck on this.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I can't see the syntax error with the if statement in your script @juless - It looks good to me.

Did you try running the script with bash

Code:
bash /mnt/Documents/Documents_communs/script.sh
 

juless

Dabbler
Joined
Jan 3, 2023
Messages
10
I can't see the syntax error with the if statement in your script @juless - It looks good to me.

Did you try running the script with bash

Code:
bash /mnt/Documents/Documents_communs/script.sh
Thanks for your reply.

I try it an got:
root@truenas[~]# bash /mnt/Documents/Documents_communs/script.sh
/mnt/Documents/Documents_communs/script.sh: line 2: $'\r': command not found
/mnt/Documents/Documents_communs/script.sh: line 5: $'\r': command not found
/mnt/Documents/Documents_communs/script.sh: line 7: $'\r': command not found
/mnt/Documents/Documents_communs/script.sh: line 10: syntax error near unexpected token `elif'
'mnt/Documents/Documents_communs/script.sh: line 10: `elif [ -z "${RFX:="$(ls /dev/serial/by-id/*RFXtrx433XL*)"}" ]; then
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I'm still not seeing anything wrong...

I copy/paste the script exactly. When I run it, I get this error, which is expected since I don't have the device.

Code:
ls: cannot access '/dev/serial/by-id/*RFXtrx433XL*': No such file or directory


Did you modify your script using a Windows Box?

Now I'm wondering if it's a new line thing.

 

juless

Dabbler
Joined
Jan 3, 2023
Messages
10
I were using windows notepad to modify your script and then modify the .txt to .bh

I now download notepad++ and use the convert to UNIX fonction like your link explain.
Now the error code is the folowing:

root@truenas[~]# bash /mnt/Documents/Documents_communs/change.sh
error: Failed to get option 'domain': Option argument is empty

error: Failed to get option 'domain': Option argument is empty
(change.sh is the script convert to UNIX)

Does it mean we are progressing?

 

juless

Dabbler
Joined
Jan 3, 2023
Messages
10
I also try with your script and i had the same issu
error: Failed to get option 'domain': Option argument is empty
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I also try with your script and i had the same issu
error: Failed to get option 'domain': Option argument is empty
My only guess right now is to ensure you've entered the VM name correctly.

If you're still stuck, I can try to rewrite the script for you, but I won't have time for a few days
 

juless

Dabbler
Joined
Jan 3, 2023
Messages
10
My only guess right now is to ensure you've entered the VM name correctly.

If you're still stuck, I can try to rewrite the script for you, but I won't have time for a few days
Ok, many thanks for the help.
 

juless

Dabbler
Joined
Jan 3, 2023
Messages
10
I rename my VM from haas3 to haas so the name as only letters and it seem's to help.
now i have the message:

error: Failed to attach device from /tmp/RFX.xml.1MTDB
error: unable to stat: /dev/serial/by-id/usb-RFXCOM_RFXtrx433XL_DO5QYRWW-if00-port0: No such file or directory

ls: cannot access '/dev/serial/by-id/*Sonoff_Zigbee_3.0_USB_Dongle_Plus*': No such file or directory
Sonoff_Zigbee_3.0_USB_Dongle_Plus not found

I think the problem comme from this line in the script (line 26)
# create a temporary file containing the RFXtrx433XL HEREDOC
RFX_xml=$(mktemp -t RFX.xml.XXXXX)
echo "${XML}" > "${RFX_xml}"

any clue please?
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I think the problem comme from this line in the script (line 26)

That's from these lines here.

Code:
elif [ -z "${ZIGBEE:="$(ls /dev/serial/by-id/*Sonoff_Zigbee_3.0_USB_Dongle_Plus*)"}" ]; then
echo "Sonoff_Zigbee_3.0_USB_Dongle_Plus not found" ; exit


What happens if you run this command directly in the terminal (not using a script)
Code:
ls /dev/serial/by-id/*Sonoff_Zigbee_3.0_USB_Dongle_Plus*
 
Top