OctoPrint-USBControl

So... can you confirm that all of these combinations definitively work for you (at the command line) without unwanted side-effects?

NZS1 on: sudo uhubctl --loc=1-1.1 --ports=2 --action=on
NZS1 off: sudo uhubctl --loc=1-1.1 --ports=2 --action=off
NZS2 on: sudo uhubctl --loc=1-1.1 --ports=3 --action=on
NZS2 off: sudo uhubctl --loc=1-1.1 --ports=3 --action=off
Arduino on: Probably not do-able
Arduino off: sudo uhubctl --loc=1-1 --ports=2 --action=off
Webcam on: sudo uhubctl --loc=1-1 --ports=3 --action=on
Webcam off: sudo uhubctl --loc=1-1 --ports=3 --action=off

Ultimately, you could run sudo lsusb -vvv and search for the word "ganged". This will tell you a lot about how things are going to work on one of the hubs.

From what I see, that port that you've got the Arduino plugged into is on a ganged set of four ports and it's behaving like the Raspi3B. You might ultimately re-arrange things so that the Arduino can be better controlled. It could be the limitation that this author was referring to.

So in the same order I get:

NZS1 on: sudo uhubctl --loc=1-1.1 --ports=2 --action=on OK
NZS1 off: sudo uhubctl --loc=1-1.1 --ports=2 --action=off OK
NZS2 on: sudo uhubctl --loc=1-1.1 --ports=3 --action=on OK
NZS2 off: sudo uhubctl --loc=1-1.1 --ports=3 --action=off OK
Arduino on: sudo uhubctl --loc=1-1 --ports=2 --action=on Arduino on, Webcam on, NZS1 still off, NZS2 still off
Arduino off: sudo uhubctl --loc=1-1 --ports=2 --action=off all OFF
Webcam on: sudo uhubctl --loc=1-1 --ports=3 --action=on Webcam still OFF despite reporting power
Webcam off: sudo uhubctl --loc=1-1 --ports=3 --action=off OK

And in this order I get:

NZS1 off: sudo uhubctl --loc=1-1.1 --ports=2 --action=off OK
NZS1 on: sudo uhubctl --loc=1-1.1 --ports=2 --action=on OK
NZS2 off: sudo uhubctl --loc=1-1.1 --ports=3 --action=off OK
NZS2 on: sudo uhubctl --loc=1-1.1 --ports=3 --action=on OK
Arduino off: sudo uhubctl --loc=1-1 --ports=2 --action=off all OFF
Arduino on: sudo uhubctl --loc=1-1 --ports=2 --action=on all ON
Webcam off: sudo uhubctl --loc=1-1 --ports=3 --action=off OK
Webcam on: sudo uhubctl --loc=1-1 --ports=3 --action=on OK

So the odd behaviou is sudo uhubctl --loc=1-1 --ports=2 --action=off. It can't switch off this port individually.
For the 3B+ I would:

  • Remove the slider corresponding to sudo uhubctl --loc=1-1 --ports=2 --action=off / on
  • Add a slider to disable/enable all by running all of the 4 commands.
1 Like

I see ganged but I don't see a reference to 1-1 port 2 in that section of the log (or the matching device ID)

lsusb vvv.zip (6.3 KB)

Displaying a combination of iManufacturer, idVendor, iProduct and idProduct next to the sliders would give useful info about what's connected!

Here is the output of

sudo lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 5: Dev 5, If 0, Class=Vendor Specific Class, Driver=ftdi_sio, 12M

And here is where the printer's MCU is connected.
USB_port_used

After running few more tests I need to take back part of my earlier statement. Disabling either port 2 or 5 terminates connectivity between RPI and MCU. The difference is - LCD goes off only when USB2 is powered off and UI switches from Connected to Disconnected state in sync with port 5.

Thanks

"Losing connectivity" to me means that you've found the USB port that toggles power for both the Ethernet and wi-fi adapters, I'd guess.

Looks like disabling USB port(s) does not play well with Klipper. If both - MCU power supply and USB power are turned off, re-establishing communication between Klipper host and MCU, after bringing power back on, is not possible unless you reboot RPI :(.

v1.0.4 of the plugin now includes CSS namespace so that it doesn't clash with anything else running on OctoPrint.

1 Like

Let me order a Raspi3B+ and hack away at this.

Nice plug-in. It is just what I needed. I already added the TP-Link outlet to turn off the power supply to the printer. But then the USB powered the computer in the printer so that was on. Now with this plug-in I can toggle off the power from the USB so when the power supply is off everything but the PI is off. Which is the way I wanted it to work.

Great job pulling all this together.

2 Likes

Well, I'm trying. It's problematic with the way the Raspberry Pi 2/B3B are implemented internally; it sounds like they used a "ganged-bus" chipset.

I'll buy one or two commodity external USB smart hubs and see what it will take to extend that control out to something like that.

Also, don't forget that the REST API allows you to code something up that will both toggle your TP-Link and turn off the USB port(s) power.

I am new to OctoPrint and was going to play with the plugin. I have only installed plugins from the OctoPrint repository. Am I missing where it is or do I need to down loaded and side load?

I tried to cleverly hide how to install this in the documentation.

Thanks for not using initials on me. :slight_smile:

You said, "Install via the bundled Plugin Manager". That makes me think it is in the official OctoPrint repository.

I am still not sure what I am doing wrong, but if I search the Plugin Manager from the device for 'OctoPrint-USB' nothing shows up.

Then if your goto the web OctoPrint Plugin Manager and search https://plugins.octoprint.org/search/?q=octoprint-usb I still don't see it.

So should I see it in the repository or do I need to sideload it? Sorry, for the Andriod terminology, just how I think of manually loading something that is not in an official repository for that product.

Take a closer look into the plugin manager:

At the top it has the stuff from the repository. But at the bottom it also allows you to "sideload" :wink:

And the docs tell you what URL to put there:

Admittedly that phrasing can be read both ways - that's my fault as it originates from the plugin template. Happy to take rephrasing advice from native speakers :sweat_smile:

1 Like

No biggie, it is just me being new. If there would have been something wrong then I wanted to bring it to someone attentions.

BTW, as I said, new to 3D Printing and I love OctoPrint.

I am waiting for my 3v relays to come in for the PSU. Right now I have a ton of 5v and I tested with a logic leveler and all seemed to work. I also have a PI 3B+ somewhere that I can test the USB with, I just need to dig it up. Sometime it might be cool to combine the PSU and the USB power controls into one toggle.
Before I saw this, my plan was to relay the 5v out of the USB, but that would require hacking the cable and could cause com issues by messing with shielding and such.

If you've got an ATX style of power supply, feel free to search the forum here for that term. I recall many posts where people have done programmatic control in a number of ways.

PSU Control
ATXPiHat A particular Pi hat
Enclosure Swiss Army Knife
TP-Link Use a TP-Link SmartPlug

The documentation for my plugin describes that the Raspi3B+ is slightly better than the Raspi3B, for what it's worth.

I've got both a Raspberry Pi 3B+ and an A+ on order now with Adafruit. I should be able to test things directly myself for these two models. You've got to love their Spartan email notification:

Products
------------------------------------------------------
1 x Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM
1 x Raspberry Pi Model 3 A+
1 x Raspberry Pi Zero W
1 x Raspberry Pi Zero WH (Zero W with Headers)
1 x PN532 NFC/RFID controller breakout board (v1.6)
2 x 13.56MHz RFID/NFC Card - Classic 1K
3 x 13.56MHz RFID/NFC White Tag - Classic 1K
3 x Micro NFC/RFID Transponder - NTAG203 13.56MHz
1 x Premium Female/Female Jumper Wires - 40 x 6"
1 x Adafruit Perma-Proto Half-sized Breadboard PCB - Single

I am both happy to report that the box from Adafruit arrived today and yet sad that the Raspberry Pi 3A+ is not at all compatible with the underlying uhubctl program; it can't see the single hub that's inside this new computer. Presumably it can't because it's not even a smart hub.

v1.0.5 of OctoPrint-USBControl now supports the Raspberry Pi 3B+.

If you've previously installed it and have the Raspberry Pi 3B+, I'd suggest removing the plugin from Settings -> Plugin Manager, letting that restart. Then manually edit your ~/.octoprint/config.yaml to remove any lines in the plugins section related to usbcontrol.

  usbcontrol:
    cpuRevision: a020d3
    init: true
    isRaspi3Bplus: true
    piModel: Raspi3B+

Then reinstall and go through the motions and it should work as expected.

For this computer, the interface looks like this:

The 3B+ is odd in that it has control over the network devices (USB1), then programmatic control over the next two smart devices (USB2/USB3) and then everything else is lumped together on a separate ganged hub. It's slightly better than the Raspberry Pi 3B but only marginally.

Great work.
For my 3b+ LCD switches off only when selecting ALL USB
USB 2 and USB 3 wont work.

How do I put a shortcut on Octoprint for quick toggle on/off just like PSU plugin does?