sbs20 / scanservjs

SANE scanner nodejs web ui
https://sbs20.github.io/scanservjs/
GNU General Public License v2.0
748 stars 144 forks source link

USB Device Id changes after reboot #134

Closed eyduh closed 3 years ago

eyduh commented 3 years ago

Unclear error message after restarting the host of the container. Logs indicate updated device mapping not applied and scanner still using old.

To Reproduce Steps to reproduce the behavior: Reboot host. Reconfigure Device mapping after USB paths changed. Try to scan, web gui says it's using new device mapping but logs point to the old one.

Expected behavior Scanning like prior to reboot.

Screenshots image image

Client (please complete the following information):

Server (please complete the following information): DietPi x86_64 Docker 20.10.3 CE Deployed server through Portainer 2.1.1

Using

version: '2'
services:
  scanserver:
    image: sbs20/scanservjs:latest
    ports: 
      - 8080:8080
    volumes: 
      - /var/run/dbus:/var/run/dbus
      - /local/storage/scans:/app/data/output
    devices:
      - /dev/bus/009/002:/dev/bus/009/002
    restart: unless-stopped
    privileged: yes

where /dev/bus/00/00 changes with host reboots and is updated manually.

Logs

[2021-02-21T02:28:12.818Z] ERROR (Http): TypeError: Cannot read property 'features' of undefined

    at Request.extend (/app/server/request.js:25:29)

    at Function.createPreview (/app/server/api.js:48:42)

    at processTicksAndRejections (node:internal/process/task_queues:94:5)

    at async /app/server/configure.js:121:16

[2021-02-21T02:28:12.816Z] DEBUG (Http): request:  {

  method: 'POST',

  path: '/scanner/preview',

{

    version: '2.6.0',

    params: {

      deviceId: 'epson2:libusb:005:002',

      top: 20,

      left: 17,

      width: 267,

      height: 389,

      resolution: 300,

      mode: 'Color',

      source: 'Flatbed'

    },

    filters: [],

    pipeline: 'PNG',

    batch: 'none',

Additional context The docker host is running as a QEMU/KVM guest under proxmox with the USB Vendor/Device ID passed through to Docker host.

output of some other troubleshooting (scan server console through portainer):

sane-find-scanner 

  # sane-find-scanner will now attempt to detect your scanner. If the
  # result is different from what you expected, first make sure your
  # scanner is powered up and properly connected to your computer.

  # No SCSI scanners found. If you expected something different, make sure that
  # you have loaded a kernel SCSI driver for your SCSI adapter.

found USB scanner (vendor=0x03f0 [Hewlett-Packard], product=0x3117 [HP Color LaserJet 2605dtn]) at libusb:009:003
could not fetch string descriptor: Pipe error
could not fetch string descriptor: Pipe error
found USB scanner (vendor=0x04b8, product=0x0869) at libusb:009:002
  # Your USB scanner was (probably) detected. It may or may not be supported by
  # SANE. Try scanimage -L and read the backend's manpage.

  # Not checking for parallel port scanners.

  # Most Scanners connected to the parallel port or other proprietary ports
  # can't be detected by this program.

scanimage:

# scanimage -L
device `epson2:libusb:009:002' is a Epson PID 0869 flatbed scanner
# scanimage -d epson2:libusb:009:002 -A

All options specific to device `epson2:libusb:009:002':
  Scan Mode:
    --mode Lineart|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --depth 8bit [inactive]
        Number of bits per sample, typical values are 1 for "line-art" and 8
        for multibit scans.
    --halftoning None|Halftone A (Hard Tone)|Halftone B (Soft Tone)|Halftone C (Net Screen)|Dither A (4x4 Bayer)|Dither B (4x4 Spiral)|Dither C (4x4 Net Screen)|Dither D (8x4 Net Screen)|Text Enhanced Technology|Download pattern A|Download pattern B [inactive]
        Selects the halftone.
    --dropout None|Red|Green|Blue [None]
        Selects the dropout.
    --brightness 0..0 [inactive]
        Selects the brightness.
    --sharpness -2..2 [inactive]

    --gamma-correction User defined (Gamma=1.0)|User defined (Gamma=1.8) [User defined (Gamma=1.8)]
        Selects the gamma correction value from a list of pre-defined devices
        or the user defined table, which can be downloaded to the scanner
    --color-correction None|Built in CCT profile|User defined CCT profile [inactive]
        Sets the color correction table for the selected output device.
    --resolution 75|300|600|1200dpi [75]
        Sets the resolution of the scanned image.
    --threshold 0..255 [128]
        Select minimum-brightness to get a white point
  Advanced:
    --mirror[=(yes|no)] [inactive]
        Mirror the image.
    --auto-area-segmentation[=(yes|no)] [inactive]
        Enables different dithering modes in image and text areas
    --red-gamma-table 0..255,...
        Gamma-correction table for the red band.
    --green-gamma-table 0..255,...
        Gamma-correction table for the green band.
    --blue-gamma-table 0..255,...
        Gamma-correction table for the blue band.
    --wait-for-button[=(yes|no)] [no]
        After sending the scan command, wait until the button on the scanner
        is pressed to actually start the scan process.
  Color correction:
    --cct-type Automatic|Reflective|Colour negatives|Monochrome negatives|Colour positives [inactive]
        Color correction profile type
    --cct-profile -2..2,...
        Color correction profile data
  Preview:
    --preview[=(yes|no)] [no]
        Request a preview-quality scan.
  Geometry:
    -l 0..297.18mm [0]
        Top-left x position of scan area.
    -t 0..431.8mm [0]
        Top-left y position of scan area.
    -x 0..297.18mm [297.18]
        Width of scan-area.
    -y 0..431.8mm [431.8]
        Height of scan-area.
  Optional equipment:
    --source Flatbed|Automatic Document Feeder [Flatbed]
        Selects the scan source (such as a document-feeder).
    --auto-eject[=(yes|no)] [no]
        Eject document after scanning
    --film-type Positive Film|Negative Film|Positive Slide|Negative Slide [inactive]

    --focus-position Focus on glass|Focus 2.5mm above glass [inactive]
        Sets the focus position to either the glass or 2.5mm above the glass
    --bay 1|2|3|4|5|6 [inactive]
        Select bay to scan
    --eject []
        Eject the sheet in the ADF
    --adf-mode Simplex|Duplex [inactive]
        Selects the ADF mode (simplex/duplex)

The Web GUI and scanimage results indicate the new device map has been applied but logs indicate scan/preview still uses old device mapping.

sbs20 commented 3 years ago

Finding the device is an expensive and time consuming operation. It is stable on most systems. Therefore the results are cached in devices.json. In the event that the address changes it's possible to use the Reset button to clear everything and get it again. But I take your point that the error message isn't great. I'll raise an issue to fix that.

In your case, however, is there not a solution in the way you map the device? Scanimage thinks it's deviceId: 'epson2:libusb:005:002' so would this work? i.e. you just change the left side of the mapping with the changed device but keep the right side stable?

      - /dev/bus/009/002:/dev/bus/005/002

You could automate this with a bit of lsusb and cut or awk.

eyduh commented 3 years ago

In your case, however, is there not a solution in the way you map the device? Scanimage thinks it's deviceId: 'epson2:libusb:005:002' so would this work? i.e. you just change the left side of the mapping with the changed device but keep the right side stable?

Funny you should mention that.. I did try this at first but portainer threw an error when creating the stack. I'll have a go again and see what it actually says. Here we go:

Failure
Recreating scanserver_scanserver_1 ...  Recreating scanserver_scanserver_1 ... error  ERROR: for scanserver_scanserver_1 Cannot start service scanserver: error gathering device information while adding custom device "/dev/bus/009/002": no such file or directory ERROR: for scanserver Cannot start service scanserver: error gathering device information while adding custom device "/dev/bus/009/002": no such file or directory Encountered errors while bringing up the project. 

Superweird that it can't find the device when it is mapped to the old location but when I map it to the same location as on the host it works fine. I'll try and attach to the console of the container and edit devices.json directly.

sbs20 commented 3 years ago

Strange. TBH I think the bigger issue, for me at least, is why the usb port id is changing. I have a feeling it's because it's running under a VM host. I can't find an exact match when searching, but this looks similar. And this too.

Both seem to point towards adding some udev rules. If that route worked then it would avoid having to re-find the scanner each time.

sbs20 commented 3 years ago

Closing due to inactivity. Please re-open if you find new information and I can help.

sorryusernameisalreadytaken commented 2 years ago

@sbs20 did you already implement a better error notification? I just ask because I had the same problem like @eyduh.

Did I get that right: I need to tell my debian system to give this device always the same usb-id?

sbs20 commented 2 years ago

Yes, you should now see "No devices found" or similar. I'm afraid I don't have sufficient information about the problem you're seeing to know the solution.

But if your USB id keeps changing then the solution you propose should help.