Help on Coldplug/hotplug script not executed on boot for usb printer (17.x )

Hi All,

I try convert TP-MR3220v2 into usb printers server.
it had limited flash so extroot is necessary.

i have two printer epson L1800 and epson L310. Both on usb.
So the setup:
router - 4 port usb hub - flaskdisk + L1800 + L310

the system boot up and detect both /dev/usb/lp0 and /dev/usb/lp1
p910nd work fine too

BUT the lp0 or lp1 will not always match the correct printer

I find a partial solution from :
https://www.qualityology.com/tech/add-multiple-usb-printers-to-openwrt-firmware-router-via-p910nd-using-hotplug/

WARNING! the script on that page have error. it seem when the author put it on the web, the "pipe sign" or "|" got filter out

I edit it :

#!/bin/sh

# process USB and parallel printers only
if [ "$INTERFACE" = "7/1/1" ]  || [ "$INTERFACE" = "7/1/2" ]
then

# set -x
DEV="none"

# Brother HL2140

if [ "$PRODUCT" = "4f9/33/100" ]
then
VID="04f9"
PID="0033"
DEV="hl2140"
fi

# Zebra LP2442

if [ "$PRODUCT" = "1645/6/100" ]
then
VID="1645"
PID="0006"
DEV="lp2442"
fi

if [ "$DEV" != "none" ]
then
if [ "$ACTION" = "add" ] || [ "$ACTION" = "bind" ]
then

# search for last printer assignment using dmesg

LP=`dmesg | grep -i "usblp.: USB Bidirectional printer dev .* if .* alt .* proto .* vid 0x$VID pid 0x$PID" | grep -io "lp[0-9]" | tail -n 1`

if [ "$LP" != "" ]
then
echo $LP >/var/run/$DEV.lp
ln -s /dev/usb/$LP /dev/$DEV
fi

fi

if [ "$ACTION" = "remove" ]
then
# LP = `cat /var/run/$DEV.lp`
rm /var/run/$DEV.lp
rm /dev/$DEV

fi
fi
fi

Doing "hot" plugging and unplugging both printer... the script does it task.
but went the router reboot... "coldplug" parsing (which i read being run by procd) did not happen for usb

in OpenWRT HotPlug user guide, at the bottom part of the page, mention coldplug for openwrt 18.0

does it mean only 18.x and above can do coldplug?

thank you for your help...

one more thing...
It had been literally 16 years since the last time i did shell script programing/editing

which one is the correct one ?

if [ "${ACTION}" = "bind" ]

---===OR===---

if [ "$ACTION" = "bind" ]

???
(i was wondering if that original page the script i copy also filter out " { } " too)

HanHan

It might be a race condition, so hotplug cannot detect the device due to startup timing/delay.

I guess it something to do with extroot.
coldplug were loaded before the OS partition on flashdisk mounted

any direction/document about when coldplug being executed ?

I read the procd .... still can not figure it out

Openwrt boot analysist

Hotplug and coldplug source code

I try to learn the code....
How can I re-execute coldplug using rc.local ?

Something like this:

PRNS="04f9:0033:hl2140 1645:0006:lp2442"
for PRN in ${PRNS}
do
IFS=":" read -r VID PID DEV << EOI
${PRN}
EOI
LP="$(dmesg | ...)"
...
done
1 Like