I use a USB RTL-SDR dongle to read 433mhz sensors and publish to an MQTT server.
I run the software in Docker with the --device tag /dev/bus/usb/001/003
lsusb -v outputs:
Bus 003 Device 009: ID 0bda:2838 Realtek RTL2838UHIDIR
idVendor 0x0bda
idProduct 0x2838
bcdDevice 1.00
So the hotplug variable PRODUCT must be bda/2838/100
This bus number and/or device number do change every boot and caught it changing even If I don't unplug/reinsert the dongle. It is not possible to get a by-id path as with serial devices.
In a system with udev I could create a rule that creates a symlink when the bus ID changes or the dongle is inserted.
How can this be done on OpenWRT? I read that there is a way to do it with hotplug to but I do not understand how to write the script that reads the bus and device number based on vendor/device ID.
I rewrote the script under the usb section but I am unsure if the middle block is valid. Udev rules has a "changed" variable to detect changes but I do not know if it is possible with hotplug scripts. The device path has changed before without being unplugged so I want to be sure it updates the symlink.
RTL433_PRODID="bda/2838/100"
SYMLINK="rtl433"
if [ "${PRODUCT}" = "${RTL433_PRODID}" ]; then
if [ "${ACTION}" = "add" ]; then
ln -s /dev/${DEVNAME} /dev/${SYMLINK}
logger -t hotplug "Symlink from /dev/${DEVNAME} to /dev/${SYMLINK} created"
fi
fi
if [ "${PRODUCT}" = "${RTL433_PRODID}" ]; then
if [ "${ACTION}" = "change" ]; then
ln -s /dev/${DEVNAME} /dev/${SYMLINK}
logger -t hotplug "Device path changed to /dev/${DEVNAME} and symlink /dev/${SYMLINK} updated"
fi
fi
if [ "${PRODUCT}" = "${RTL433_PRODID}" ]; then
if [ "${ACTION}" = "remove" ]; then
rm /dev/${SYMLINK}
logger -t hotplug "Symlink /dev/${SYMLINK} removed"
fi
fi