gersilex / apcupsd-docker

apcupsd in a container; can trigger arbitrary commands on the Docker host
https://hub.docker.com/r/gersilex/apcupsd
MIT License
24 stars 12 forks source link

using with modbus #13

Open andrasg opened 1 year ago

andrasg commented 1 year ago

Hi, any ideas what other devices than /dev/usb/hiddev0 would need to be handed over to the container when trying to use modbus? I am constantly getting COMMLOST when running in docker. If I install on the host, modbus communication is perfectly running using the same apcupsd.conf

gersilex commented 1 year ago

Hm I really don't know anything about modbus. I use Modbus over TCP with my Home Assistant installation and a ventilation appliance. But this is also just TCP/IP and therefore just works already. Is a "real" modbus creating any devices with udev? You could try to monitor udev events and find out if there is a device created when you plug in the modbus

https://www.freedesktop.org/software/systemd/man/udevadm.html

Message ID: @.***>

andrasg commented 1 year ago

This is what I get when unplugging and then re-plugging the UPS. To me it looks like it's just the /dev/usb/hiddev0

KERNEL[1059.450438] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[1059.450932] unbind   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
KERNEL[1059.451017] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
UDEV  [1059.455653] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [1059.458996] unbind   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
UDEV  [1059.461268] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
KERNEL[1071.927832] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
KERNEL[1071.930314] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[1071.937939] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
KERNEL[1071.940274] add      /class/usbmisc (class)
KERNEL[1071.940552] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc)
KERNEL[1071.940764] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw)
KERNEL[1071.941004] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
KERNEL[1071.941245] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[1071.941463] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
UDEV  [1071.944257] add      /class/usbmisc (class)
UDEV  [1071.954475] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
UDEV  [1071.958297] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [1071.961996] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
UDEV  [1071.962383] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc)
UDEV  [1071.971599] add      /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw)
UDEV  [1071.974600] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
UDEV  [1071.977741] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [1071.990606] bind     /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb)
KERNEL[1072.460279] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc)
KERNEL[1072.460572] remove   /class/usbmisc (class)
KERNEL[1072.460753] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw)
KERNEL[1072.460963] unbind   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
KERNEL[1072.461189] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
KERNEL[1072.461445] unbind   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [1072.461769] remove   /class/usbmisc (class)
UDEV  [1072.465252] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc)
UDEV  [1072.467226] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw)
UDEV  [1072.470632] unbind   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
UDEV  [1072.474385] remove   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid)
UDEV  [1072.478086] unbind   /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
gersilex commented 1 year ago

So it is plugged into the host via USB? Or is it a USB-Modbus Adapter? I have problems understanding where exactly modbus comes into play in your setup. Can you elaborate?

Am Mi., 7. Juni 2023 um 23:40 Uhr schrieb Andras Gaal < @.***>:

This is what I get when unplugging and then re-plugging the UPS. To me it looks like it's just the /dev/usb/hiddev0

KERNEL[1059.450438] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) KERNEL[1059.450932] unbind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) KERNEL[1059.451017] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) UDEV [1059.455653] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) UDEV [1059.458996] unbind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) UDEV [1059.461268] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) KERNEL[1071.927832] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) KERNEL[1071.930314] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) KERNEL[1071.937939] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) KERNEL[1071.940274] add /class/usbmisc (class) KERNEL[1071.940552] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc) KERNEL[1071.940764] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw) KERNEL[1071.941004] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) KERNEL[1071.941245] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) KERNEL[1071.941463] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) UDEV [1071.944257] add /class/usbmisc (class) UDEV [1071.954475] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) UDEV [1071.958297] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) UDEV [1071.961996] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) UDEV [1071.962383] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc) UDEV [1071.971599] add /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw) UDEV [1071.974600] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) UDEV [1071.977741] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) UDEV [1071.990606] bind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2 (usb) KERNEL[1072.460279] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc) KERNEL[1072.460572] remove /class/usbmisc (class) KERNEL[1072.460753] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw) KERNEL[1072.460963] unbind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) KERNEL[1072.461189] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) KERNEL[1072.461445] unbind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb) UDEV [1072.461769] remove /class/usbmisc (class) UDEV [1072.465252] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/usbmisc/hiddev0 (usbmisc) UDEV [1072.467226] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002/hidraw/hidraw0 (hidraw) UDEV [1072.470632] unbind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) UDEV [1072.474385] remove /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/0003:051D:0003.0002 (hid) UDEV [1072.478086] unbind /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0 (usb)

— Reply to this email directly, view it on GitHub https://github.com/gersilex/apcupsd-docker/issues/13#issuecomment-1581546639, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPMV52UVIVHI4BELFA5GNDXKDYLVANCNFSM6AAAAAAY6LPPTA . You are receiving this because you commented.Message ID: @.***>

andrasg commented 1 year ago

It's an APC SMT1500i UPS, hardware ID 18, firmware 9.3. The UPS is connected to the hoot using a USB cable, yes. The UPS can talk "hid" (generic USB), the now legacy protocol for APC and can also talk "modbus", the newer, open "language" used lately by APC. I am unsure though how modbus is implemented, as I cannot find any modbus related device on my host (eg: a serial adapter).

When installiing apcupsd on the host, modbus based communication works correctly, apcupsd can see the UPS and read its status. When trying the same in a container, I get COMMLOST.

I have tried with other similar apcupsd container images as well as with my own-built images, and got the same result, so I don't think anything is wrong with your image. Just wanted to check if there's anyone who happens to know what additional config I might be missing...

gersilex commented 1 year ago

Understood, thanks for the information. maybe you can brute force your way through, give the container host access, add every single device from the host to the container, etc. or run apcupsd on the host through strace and watch for CONNECT or OPEN sys calls.

I'm certain that it must be possible. And also hopefully someone finds this thread and can add some ideas or even the solution.

Andras Gaal @.***> schrieb am Do., 8. Juni 2023, 00:18:

It's an APC SMT1500i UPS, hardware ID 18, firmware 9.3. The UPS is connected to the hoot using a USB cable, yes. The UPS can talk "hid" (generic USB), the now legacy protocol for APC and can also talk "modbus", the newer, open "language" used lately by APC. I am unsure though how modbus is implemented, as I cannot find any modbus related device on my host (eg: a serial adapter).

When installiing apcupsd on the host, modbus based communication works correctly, apcupsd can see the UPS and read its status. When trying the same in a container, I get COMMLOST.

I have tried with other similar apcupsd container images as well as with my own-built images, and got the same result, so I don't think anything is wrong with your image. Just wanted to check if there's anyone who happens to know what additional config I might be missing...

— Reply to this email directly, view it on GitHub https://github.com/gersilex/apcupsd-docker/issues/13#issuecomment-1581587661, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPMV5YNE4KEAMNXMH2NAQTXKD425ANCNFSM6AAAAAAY6LPPTA . You are receiving this because you commented.Message ID: @.***>

Lennong commented 2 months ago

Look in your hosts /dev directory and see how your UPS is seen and what name it has been given. I run a Debian12 and my APC Smart1000 is connected through device name 'ttyUSB0'. I add this to my compose:

devices:
      - /dev/ttyUSB0:/dev/ttyUSB0

You will have to edit the apcupsd.conf accordingly as well. Mine looks like this:

UPSNAME SmartUPS1000
UPSCABLE 940-0625A
UPSTYPE modbus
DEVICE /dev/ttyUSB0