0

I'm working on a Linux embedded system that can draw its power from two distinct sources:

  • a dedicated power supply
  • power supply through USB (connected to an external USB host)

I must know when the device is unplugged, so I can do an emergency shutdown.

I know how to detect when my dedicated power supply disappears.

But I don't know when the USB power supply is unplugged.

How would you detect when a USB cable is unplugged from an USB device under Linux ?

Thanks in advance for your insights.

4
  • Please state the Linux distribution you are using/plan on using, because a lot depends on that.
    – Apache
    Commented Apr 11, 2022 at 15:03
  • We're building a root filesystem using Yocto for a processor ARM (IMX6UL). We're using Variscite repositories for their processor and custom layers for our applications. Thanks for your reading. Commented Apr 11, 2022 at 16:05
  • If you look in your log file does it genetate any messages when the cable is plugged in/unplugged? If it revignises a device you can use udev to trigger actions when things are inserted/removed. Fail2ban might also be a hacky option.
    – davidgo
    Commented Apr 11, 2022 at 19:33
  • 1
    Thank you for your advice and information, I've tried a few things on these lines. Eventually, we managed to fix the problem by including GadgetFs code to our app, to manage the connection/deconnection to an USB host... It seems to work so far. Thanks again. Commented Apr 12, 2022 at 7:48

0

You must log in to answer this question.

Browse other questions tagged .