USB hotplug event

Dill

Occasional Visitor
Hello,

I try to have a pi zero W connected by USB to go and eth.
I've been succesfull by following this https://forums.raspberrypi.com/viewtopic.php?t=238746 tutorial and some other forum threads, which all follow this one.
What I fail to attempt is the automatic connection when rebooting or hot plugging.

I did the attempt of going with the hotplug.rules system, which is described in the tuto, but it doesn't do what it should.

/etc//hotplug2.rules (ln to /jffs/hotplug2.rules)

Code:
[...]

SUBSYSTEM == net, ACTION is set {
exec /sbin/hotplug %SUBSYSTEM% ;
exec /jffs/scripts/script_hotplug.sh ;
}
[...]

It doesn't seem to trigger the script.
Does anyone have an idea,
1. how to check what's happening
2. what to change
3. another way to go?

Target is, if the pi is plugged to the USB 2.0, add the usb0 network device by executing
Code:
ifconfig usb0 up
brctl addif br0 usb0

Thank you
Dillinger

Router: Asus RT-AC68U
Firmware: 386.7_2

Installed custom scripts with JFFS and a swap on separate USB Stick:
AMTM with

Diversion v4.3.2
Skynet v7.2.8

YazFi v4.4.2
scribe v2.4.3
x3mRouting v2.4.5

unbound Manager v3.22
nsrum v30.4.0

connmon v3.0.2
ntpMerlin v3.4.5
scMerlin v2.4.0
spdMerlin v4.4.4
uiDivStats v3.0.2
uiScribe v1.4.5

YazDHCP v1.0.4
vnStat v2.0.4


edit: Added router details
 
Last edited:

bennor

Very Senior Member
If the scripts are not being triggered. Did you set the permissions of the following two files to 0755:
/jffs/scripts/init-start
/jffs/scripts/script_hotplug.sh

And the permission to 0644 for the following file:
/jffs/hotplug2.rules

Per the directions...
Note: Failure to set the permission on the three files may cause the scripts not to run.
 

ColinTaylor

Part of the Furniture
It's not explicitly mentioned in that guide but you need to enable "JFFS custom scripts and configs" in Administration - System.
 

bennor

Very Senior Member
It's not explicitly mentioned in that guide but you need to enable "JFFS custom scripts and configs" in Administration - System.
Yeah, thanks for mentioning that. I don't remember when writing up those directions back then if "JFFS custom scripts and configs" was already enabled within the firmware or not when I installed Merlin at the time. Made a thread about the Pi + Merlin USB Ethernet Gadget mode on SNBForums at the time too.


Used that USB Ethernet Gadget mode for about a year before moving back to using a USB ethernet adapter on the Pi Zero W after expanding the local wired network with an additional network switch.
 

Dill

Occasional Visitor
If the scripts are not being triggered. Did you set the permissions of the following two files to 0755:
/jffs/scripts/init-start
/jffs/scripts/script_hotplug.sh

And the permission to 0644 for the following file:
/jffs/hotplug2.rules

Per the directions...
Sorry for getting back not earlier.

@bennor Thank you for your input. Your thread was one of those helping me sort things out.

The permissions are right. I can execute the sh scripts just fine. I also have some merlin custom scripts running, which already use the init-start script.
Thank you @ColinTaylor, reminding me anyways.

I fiddled around a bit and I guess the issue is the moment, the hotplug2.rules are loaded.
I can execute the /jffs/scripts/init-start just fine manualy including

# Replace hotplug2 rules with our own, and restart hotplug2
ln -sf /jffs/hotplug2.rules /etc/hotplug2.rules
killall hotplug2

When I comment out the lines, booting works just fine and I can manualy execute the init-start script again (which seems to be executed just fine), and everything works, including the usb0 mounting.
But if I keep the lines active in the script while booting, alot get's broken. Even the shell isn't the same anymore and several other amtm scripts doesn't work.
Does anyone have an Idea why this happens?

@bennor is there a special reason, why you changed to the external ethernet adapter? Would you recomend that in general?

Best
Dill
 

bennor

Very Senior Member
First, it may help others with diagnosing your issue(s) if you include the Asus router model and Asus-Merlin firmware version it's running. Also include what other scripts (amtm or otherwise) you are running.
@bennor is there a special reason, why you changed to the external ethernet adapter? Would you recomend that in general?
When I initially purchased the Pi Zero W I had a spare USB to OTG cable and USB to Ethernet adapter laying around so I combined and used those with the Pi Zero W rather than using the WiFi on the Pi Zero W. I started down the road of experimenting with the USB Ethernet Gadget Mode due to the RT-AC68U being used at the time running out of network ports, wanting to see if I could reduce cable clutter, and the USB to Ethernet adapter on the Pi going bad (it's USB cable causes intermittent connection unless bent to a specific angle). Went back to using the USB to Ethernet adapter on the Pi Zero W over a year later after; expanding my local network, reconfiguring it, buying a larger network switch, and wanting to use the router's USB ports for other purposes.

The firmware used at the time (2019) was Asus-Merlin 384.10_2. Its entirely possible something changed within the firmware (or possibly the router if one is using a newer model) since then that causes issues with using the configuration that I used in 2019. Its also possible running various other add-on scripts may conflict. Not sure I was running any other add-on scripts back then (likely just YazFi if I was). Its also possible if one already has a USB drive attached that it may also cause a conflict. I wasn't using an external USB drive at that time.
 
Last edited:

Dill

Occasional Visitor
Thank you @bennor.

You are right. I added the infos you requested.
I want to get rid of most of the scripts and put them on the pi.

As it works when done manually after booting, wouldn't it be the most easiest way, to have the init-script lines run later in the boot process, even at the last position of it?
How could I achieve that?

About your change to usb to go. I'm just wondering, if you hat technical reasons, like instabilities or speed issues with the USB gadget mode. The later shouldn't make a difference though, as the USB of the pi Zero is the limiting factor anyway.

Best
Dill
 
Last edited:

bennor

Very Senior Member
You are right. I added the infos you requested.
It appears your running 15 or so add-on scripts on the RT-AC68U. With that many running it wouldn't surprise me if there was some sort of a conflict or issue, or just the RT-AC68U being dragged down at times (like at router boot) trying to execute and run that many add-on scripts.

As it works when done manually after booting, wouldn't it be the most easiest way, to have the init-script lines run later in the boot process, even at the last position of it?
How could I achieve that?
No doubt someone more knowledgeable than me on scripting will have a better idea or solution. But maybe one could try using "sleep" or maybe the "wait" or "read -p" commands to pause the running of the command(s) or scripts used for the USB Ethernet Gadget mode on the Asus router. May have to experiment where to place one of those commands in the three files that one edits or creates for the USB Ethernet Gadget mode on the Asus router.
About your change to usb to go. I'm just wondering, if you hat technical reasons, like instabilities or speed issues with the USB gadget mode. The later shouldn't make a difference though, as the USB of the pi Zero is the limiting factor anyway.
I don't remember having any noticeable or major instabilities or issues using USB Ethernet Gadget Mode with the Pi Zero W. In my case the USB to Go (USB-OTG) cable was used to interface a USB Ethernet adapter's USB Type A connector to the Pi Zero W's Micro-USB port.
 

Dill

Occasional Visitor
Thank you again and sorry for the slow respond. I just had the opportunity to get to it again.

Just to let anyone know, my Idea of delaying the soft link set and hotplug.rules restart, works just fine.

I created another script in /jffs/scripts/ with this:

#!/bin/sh
sleep 30
'ln -sf /jffs/hotplug2.rules /etc/hotplug2.rules
killall hotplug2'

note the sleep line!

this was in return executed by a line in /jffs/scripts/init-start:

./jffs/scripts/hotswaplink.sh &

The '&' keeps the script and boot running, while the hotswaplink.sh waits 30 till its execution.

Thank you and good by
Dill
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top