USB Hotplug Script Support

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
Nite
DD-WRT Novice


Joined: 11 Oct 2008
Posts: 18

PostPosted: Sun Feb 08, 2009 9:19    Post subject: USB Hotplug Script Support Reply with quote
Hey everyone,

I was wondering if anyone has investigated the possibility of enabling the use of a hotplug daemon in order to allow the use of hotplug scripts when devices are connected.

I'm trying to get a Laserjet 1018 printer working with DD-WRT, but it's not possible without the ability to upload firmware when the USB connection is detected. Any assistance would be much appreciated. What all is involved in possibly adding hotplug script support? There is a Tomato build with this functionality currently enabled, but DD-WRT has many more features.

Again, any help is appreciated. Thanks.
Sponsor
gaganwalia
DD-WRT User


Joined: 24 Dec 2007
Posts: 449

PostPosted: Sun Feb 08, 2009 11:00    Post subject: Reply with quote
it is possible to use a printer with dd-wrt. i have 2 printers on my router, and one USB drive connected using a 4 USB extension port. all working fine.

first you have to install the drivers for USB

then you have to install the drivers for printer support.

then you have to setup your computer to use tcp/ip port for printing

this is fully documented in the wiki, search for it.
MrAlvin
DD-WRT User


Joined: 07 Jan 2007
Posts: 457
Location: Denmark

PostPosted: Sun Feb 08, 2009 13:13    Post subject: Reply with quote
For usb drives hot-plug script support can be enabled via the web-GUI (on v24-pre-sp2 firmwares that have usb support in the web-GUI). Its called run-on-mount, and Slim Samba2 depends on this functionality.

So some level of hot-plug support/detection is already enabled in dd-wrt. I suppose its only a question of tapping into this functionality, to have a run-a-script-on-new-usb-device-detection.
Nite
DD-WRT Novice


Joined: 11 Oct 2008
Posts: 18

PostPosted: Sun Feb 08, 2009 20:23    Post subject: Reply with quote
Gaganwalia,

I have already completed everything you mentioned. The HP LJ1018 will not work without the ability to upload a 120 KB firmware file every time the device is detected. If the devices is turned off and back on it will no longer accept print jobs. If the device goes into sleep mode after an hour and you try to print it will no longer accept print jobs. This makes it unusable unless USB hotplug script support is enabled in DD-WRT.
MrAlvin
DD-WRT User


Joined: 07 Jan 2007
Posts: 457
Location: Denmark

PostPosted: Sun Feb 08, 2009 20:46    Post subject: Reply with quote
Nite wrote:
The HP LJ1018 will not work without the ability to upload a 120 KB firmware file every time the device is detected.

What du you mean when you say upload?
The firmware file is stored on eg. /jffs or /mnt?
and then needs an insmod command to run in order to be recognized by dd-wrt?
or some other command?

I guess what I am saying: what do you specifically do to get the driver to work in the first place?

Once the steps to success are listed, maybe someone will be able to fill in "the missing link" in the process, for the auto-detect-on-wake-up to start working.

What do you know about the tricks they do in Tomato to have this process working?
Nite
DD-WRT Novice


Joined: 11 Oct 2008
Posts: 18

PostPosted: Sun Feb 08, 2009 21:45    Post subject: Reply with quote
Here's what I was able to find out about this:

The firmware is stored on the router in /jffs. It's a approximately 120 kb file named sihp1018.dl.

They use the following hotplug script:

if [ $PRODUCT = "3f0/4117/100" ] (this is the printer's product code)
then
if [ $ACTION = "add" ]
then
sleep 5
cat /jffs/sihp1018.dl > /dev/usb/lp0
fi
fi
fi


My understanding is that DD-WRT currently cannot execute scripts like this for printers on detection or removal.

The normal Tomato firmware is not able to do this (or USB at all), but the firmware available and discussed in this thread: http://www.linksysinfo.org/forums/showthread.php?t=60185 has been modded in order to have USB and hotplug scripts. The source code is loaded in a git repository as well, but I'm not knowledgeable enough to know how to proceed.

Thanks for the help MrAlvin.
Nite
DD-WRT Novice


Joined: 11 Oct 2008
Posts: 18

PostPosted: Tue Feb 10, 2009 8:08    Post subject: Reply with quote
Does anyone have any interest in adding hotplug or know-how on how to do so?
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Tue Feb 10, 2009 11:29    Post subject: Reply with quote
I wrote a script to automatically load the printer driver when a printer is connected and kill it when it is disconnected....

Just add that line and bob's your uncle...

Search for it in the forum....
If you can't find it, I will send the link this evening

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Tue Feb 10, 2009 18:08    Post subject: Reply with quote
If you save this as /jffs/usbprinter you can run it as /jffs/usbprinter &

Code:
#!/bin/sh
# Printer monitoring script

while sleep 60
do
isdaemon=`ps | grep -v grep | grep -c p9100`
if [ $isdaemon == 0 ]; then
  # No daemon running
  # Start daemon if printer is attached
  if [ -e /dev/usb/lp0 ]; then
    /opt/bin/p910nd  -b -f /dev/usb/lp0 0
    sleep 1
    cat /jffs/sihp1018.dl > /dev/usb/lp0
  fi
else
  if [ ! -e /dev/usb/lp0 ]; then
    # No Printer attached but daemon running
    # Kill daemon
    process=`pidof p9100d`
    kill $process
  fi
fi
done

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
eastside
DD-WRT Novice


Joined: 07 Apr 2010
Posts: 4

PostPosted: Thu Apr 08, 2010 8:05    Post subject: Reply with quote
My printer (Hp1020) is working, but I have to manually execute the
cat /jffs/sihp1020.dl > /dev/usb/lp0
every time.

At startup the following script runs:
Code:
/jffs/usr/sbin/p910nd -b -f /dev/usb/lp0 0
/bin/mkdir -m 755 -p /dev/usb
/bin/mknod -m 660 /dev/usb/lp0 c 180 0
/jffs/watchprinter


with the watchprinter file looking like this:
Code:
#!/bin/sh
# Printer monitoring script

while sleep 60
do
isdaemon=`ps | grep -v grep | grep -c p9100`
if [ $isdaemon == 0 ]; then
  # No daemon running
  # Start daemon if printer is attached
  if [ -e /dev/usb/lp0 ]; then
    /opt/bin/p910nd  -b -f /dev/usb/lp0 0
    sleep 1
    cat /jffs/sihp1020.dl > /dev/usb/lp0
  fi
else
  if [ ! -e /dev/usb/lp0 ]; then
    # No Printer attached but daemon running
    # Kill daemon
    process=`pidof p9100d`
    kill $process
  fi
fi
done


It looks like the watchprinter script is not executed given this error:
sh: eval: line 4: /jffs/watchprinter: not found

What am I doing wrong?
nordberg
DD-WRT Novice


Joined: 26 Dec 2008
Posts: 11

PostPosted: Wed Sep 22, 2010 14:40    Post subject: Reply with quote
frater wrote:
If you save this as /jffs/usbprinter you can run it as /jffs/usbprinter &

Code:
#!/bin/sh
# Printer monitoring script

while sleep 60
do
isdaemon=`ps | grep -v grep | grep -c p9100`
if [ $isdaemon == 0 ]; then
  # No daemon running
  # Start daemon if printer is attached
  if [ -e /dev/usb/lp0 ]; then
    /opt/bin/p910nd  -b -f /dev/usb/lp0 0
    sleep 1
    cat /jffs/sihp1018.dl > /dev/usb/lp0
  fi
else
  if [ ! -e /dev/usb/lp0 ]; then
    # No Printer attached but daemon running
    # Kill daemon
    process=`pidof p9100d`
    kill $process
  fi
fi
done


Do I need to install anything else on the router for this to work? Optware? Maybe I just need it broken down a little more...

If I get this working, then this router will do EVERYTHING I want. Then I can back up the settings with your other great script Frater.

====================
edit: Okay, i tried the script saving as /jffs/usbprinter, making executable, and running on startup with /jffs/usbprinter &

I am using DD-WRT v24-sp2 (09/18/10) mini-usb-nas - build 15230M NEWD-2 K2.6 Eko on a Belkin Play F7D4302v1. This router is just newly supported so I don't think I can go older.

Anyway, the script seems to die because of the location of p910d which is not in the /opt/bin location as this version already has printer support built in. Do I need a modified script for this new firmware? Do I require Optware still?

I've been using DD-WRT for 3 years, but only on the old neutered Linksys units, so this functionality is all new to me!

Thanks
franciz
DD-WRT Novice


Joined: 04 Jun 2009
Posts: 46

PostPosted: Thu Sep 23, 2010 0:23    Post subject: Reply with quote
nordberg wrote:
Anyway, the script seems to die because of the location of p910d which is not in the /opt/bin location as this version already has printer support built in. Do I need a modified script for this new firmware? Do I require Optware still?
Thanks


You don't need optware, just redirect all the "opt/bin/p910nd" for the direction of yours. Usually "jffs/usr/sbin/p910nd"

EDIT: only put the "cat sp...." line if your printer is an HP 1018, 1020, p1005, p1006 and few others
nordberg
DD-WRT Novice


Joined: 26 Dec 2008
Posts: 11

PostPosted: Thu Sep 23, 2010 5:00    Post subject: Reply with quote
franciz wrote:
nordberg wrote:
Anyway, the script seems to die because of the location of p910d which is not in the /opt/bin location as this version already has printer support built in. Do I need a modified script for this new firmware? Do I require Optware still?
Thanks


You don't need optware, just redirect all the "opt/bin/p910nd" for the direction of yours. Usually "jffs/usr/sbin/p910nd"

EDIT: only put the "cat sp...." line if your printer is an HP 1018, 1020, p1005, p1006 and few others


Thanks, I do have one of those printers.

So, taking a look with SCP onto the router, it seems that p910d lives in /usr/sbin , so I changed the reference to there.

my startup script is:

mknod -m 660 /dev/usb/lp0 c 180 0
/jffs/usbprinter &


Still does not seem to work. Frustrating, but thanks for the help!
franciz
DD-WRT Novice


Joined: 04 Jun 2009
Posts: 46

PostPosted: Thu Sep 23, 2010 15:41    Post subject: Reply with quote
you need the firmware for the printer you got. Which printer is it?

read my post here:
http://www.dd-wrt.com/phpBB2/viewtopic.php?p=480752
nordberg
DD-WRT Novice


Joined: 26 Dec 2008
Posts: 11

PostPosted: Thu Sep 23, 2010 23:34    Post subject: Reply with quote
franciz wrote:
you need the firmware for the printer you got. Which printer is it?

read my post here:
http://www.dd-wrt.com/phpBB2/viewtopic.php?p=480752


my printer is hp 1018, so i have downloaded sihp1018.dl to /jffs/

I am running DD-WRT v24-sp2 (09/18/10) mini-usb-nas - build 15230M NEWD-2 K2.6 Eko with usb already installed. Since it is a K26 version, do I have to use a slightly different script? I followed you link but couldn't tell... thanks Very Happy
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum