networkupstools / nut

The Network UPS Tools repository. UPS management protocol Informational RFC 9271 published by IETF at https://www.rfc-editor.org/info/rfc9271 Please star NUT on GitHub, this helps with sponsorships!
https://networkupstools.org/
Other
2.07k stars 350 forks source link

SMS Manager III Support #1987

Open leleobhz opened 1 year ago

leleobhz commented 1 year ago

Hello!

I'm trying to read SMS Manager III without sucess. I've built NUT for Docker and published at https://github.com/leleobhz/docker-nut (To use glibc-based compilation) and as stated at https://networkupstools.org/stable-hcl.html - This nobreak is served by blazer_ser. Since this driver was superseed by nutdrv_qx, I'm trying to use it.

With the following configuration:

docker run -it --rm --name nut --user 0 --privileged --device /dev -e DRIVER="nutdrv_qx" -e DESCRIPTION="Nobreak Zenith" -e NAME="NobreakZenith" -e PORT="auto" -e SUBDRIVER="cypress" -e VENDORID="04b4" -e PRODUCTID="5500" -e SDORDER="-1" -e API_USER="upsmon" -e API_PASSWORD="aaaaa"  quay.io/pqatsi/docker-nut:v2.8.0-signed

Resulting this ups.conf:

[NobreakZenith]
        driver = nutdrv_qx
        port = auto
        desc = "Nobreak Zenith"
        subdriver = "cypress"
        vendorid = 04b4
        productid = "5500"
        sdorder = -1

Running driver directly returns:

/nut/bin/nutdrv_qx -V

Network UPS Tools - Generic Q* USB/Serial driver 0.32 (2.8.0-signed)
USB communication driver (libusb 1.0) 0.43

/nut/bin/nutdrv_qx -a NobreakZenith -DDD

Network UPS Tools - Generic Q* USB/Serial driver 0.32 (2.8.0-signed)
USB communication driver (libusb 1.0) 0.43
   0.000000 [D1] debug level is '3'
   0.002508 [D1] upsdrv_initups...
   0.024183 [D2] Checking device 1 of 4 (04B4/5500)
   0.039965 [D2] - VendorID: 04b4
   0.040428 [D2] - ProductID: 5500
   0.040754 [D2] - Manufacturer: Cypress Semiconductor
   0.041119 [D2] - Product: USB to Serial
   0.042261 [D2] - Serial Number: unknown
   0.042335 [D2] - Bus: 001
   0.042391 [D2] - Device: unknown
   0.042517 [D2] - Device release number: 0000
   0.042571 [D2] Trying to match device
   0.042625 [D3] match_function_regex: matching a device...
   0.044825 [D2] Device matches
   0.045186 [D2] Reading first configuration descriptor
   0.046393 [D3] libusb_kernel_driver_active() returned 0
   0.047206 [D2] Claimed interface 0 successfully
   0.047784 [D3] nut_usb_set_altinterface: skipped libusb_set_interface_alt_setting(udev, 0, 0)
   0.049516 [D3] send: QGS
   0.175883 [D3] read: �
   0.176624 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   0.178995 [D3] send: QGS
   0.306880 [D3] read: �
   0.307551 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   0.309425 [D3] send: QGS
   0.435873 [D3] read: �
   0.436628 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   0.440793 [D3] send: M
   0.568869 [D3] read: �
   0.569095 [D2] voltronic_qs_protocol: invalid protocol [�]
   0.571009 [D3] send: M
   0.698866 [D3] read: �
   0.699093 [D2] voltronic_qs_protocol: invalid protocol [�]
   0.700526 [D3] send: M
   0.827869 [D3] read: �
   0.828521 [D2] voltronic_qs_protocol: invalid protocol [�]
   0.830483 [D3] send: M
   0.957869 [D3] read: �
   0.960846 [D2] voltronic_qs_hex_protocol: invalid protocol [�]
   0.965752 [D3] send: M
   1.093863 [D3] read: �
   1.094032 [D2] voltronic_qs_hex_protocol: invalid protocol [�]
   1.095566 [D3] send: M
   1.222859 [D3] read: �
   1.223629 [D2] voltronic_qs_hex_protocol: invalid protocol [�]
   1.224731 [D3] send: QS
   1.350854 [D3] read: �
   1.351556 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   1.354554 [D3] send: QS
   1.480838 [D3] read: �
   1.481003 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   1.482841 [D3] send: QS
   1.610841 [D3] read: �
   1.611007 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   1.613615 [D3] send: D
   1.742842 [D3] read: �
   1.743475 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   1.745949 [D3] send: D
   1.871833 [D3] read: �
   1.872316 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   1.876676 [D3] send: D
   2.003831 [D3] read: �
   2.004197 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.006173 [D3] send: Q1
   2.133828 [D3] read: �
   2.135792 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.136917 [D3] send: Q1
   2.265821 [D3] read: �
   2.265997 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.267396 [D3] send: Q1
   2.393808 [D3] read: �
   2.394632 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.397461 [D3] send: Q1
   2.524817 [D3] read: �
   2.524981 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.526360 [D3] send: Q1
   2.654806 [D3] read: �
   2.654976 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.656296 [D3] send: Q1
   2.785807 [D3] read: �
   2.785972 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.787384 [D3] send: Q1
   2.913792 [D3] read: �
   2.914269 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   2.917185 [D3] send: Q1
   3.043785 [D3] read: �
   3.043961 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.044942 [D3] send: Q1
   3.170793 [D3] read: �
   3.170960 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.171992 [D3] send: Q1
   3.298779 [D3] read: �
   3.298955 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.300688 [D3] send: Q1
   3.426774 [D3] read: �
   3.426951 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.428079 [D3] send: Q1
   3.554770 [D3] read: �
   3.554935 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.555110 [D2] find_nut_info: info type series not found
   3.555983 [D2] claim: cannot find series
   3.556982 [D2] find_nut_info: info type series not found
   3.558218 [D2] claim: cannot find series
   3.558411 [D2] find_nut_info: info type series not found
   3.558517 [D2] claim: cannot find series
   3.559762 [D3] send: Q1
   3.687776 [D3] read: �
   3.687943 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.689348 [D3] send: Q1
   3.815768 [D3] read: �
   3.815935 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.817749 [D3] send: Q1
   3.943758 [D3] read: �
   3.943925 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   3.945467 [D3] send: Q1
   4.071753 [D3] read: �
   4.071918 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   4.073586 [D3] send: Q1
   4.199757 [D3] read: �
   4.199921 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   4.201397 [D3] send: Q1
   4.327750 [D3] read: �
   4.327918 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   4.329559 [D3] send: Q1
   4.455749 [D3] read: �
   4.455916 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   4.457639 [D3] send: Q1
   4.583735 [D3] read: �
   4.583910 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   4.585068 [D3] send: Q1
   4.711740 [D3] read: �
   4.712227 [D2] qx_process_answer: input.voltage - invalid start character [f0], expected [28]
   4.712526 Device not supported!
   4.712847 Device not supported!

For reference. lsusb of this device:

Bus 001 Device 010: ID 04b4:5500 Cypress Semiconductor Corp. HID->COM RS232 Adapter
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04b4 Cypress Semiconductor Corp.
  idProduct          0x5500 HID->COM RS232 Adapter
  bcdDevice            0.00
  iManufacturer           1 Cypress Semiconductor
  iProduct                2 USB to Serial
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0029
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 Sample HID
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.00
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      37
          Report Descriptor: (length is 37)
            Item(Global): Usage Page, data= [ 0xa0 0xff ] 65440
                            (null)
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x02 ] 2
                            (null)
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Main  ): Output, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x03 ] 3
                            (null)
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x05 ] 5
            Item(Main  ): Feature, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               1
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)

And tracing this nobreak history, in past SMS was this driver: https://alioth-lists.debian.net/pipermail/nut-upsdev/2013-January/006379.html

This is a issue with nutdrv_qx driver, there is any configuration required I'm missing there or this is in fact a bug of nutdrv_qx?

jimklimov commented 1 year ago

I've asked on the mailing list if someone better versed with the driver structure is online these summer days. Perhaps also CC @blaa who was fixing a subdriver recently.

If no quick solutions come up, a sparrow in hand is better than a swan in the sky, for a first catch anyway ;)

blaa commented 1 year ago

I'm not well informed as of now, but:

  1. qx driver lets you write a subdriver that handles communication with the UPS.
  2. It sends commands, reads replies.
  3. Replies are then parsed against one of many dialects.
  4. Dialects are mostly ASCII related, but there are some dedicated preprocessors that can be defined per command per dialect.

So. I'm unsure where you're with the driver. But it should be easy to write a subdriver to handle communications, and if those are binary only - just synthesize a valid ASCII response in Q1-related format (megatec maybe?) and don't even touch the dialects.

This should be rather easy but it has this nah feeling because you'd go binary--parsing-->data--synthesis-->ascii--parsing-->data. But it might be in total much less code.

Subdriver I was writing had a weird binary protocol, but in the end it was used to transmit a valid ASCII megatec response. So I just parsed the binary to retrieve the message. Unsure how it works with yours.

alexwbaule commented 1 year ago

Hi @jimklimov

im looking in the documentation to create a "qx" sub-driver, and i got some questions, if this driver is a qx compatible sub-driver.

The "leading" on "item_t", is a char, but in the "Q" command on SMS 1Phase, the valid answer can be 3 values (<.>,=).

I Thinking in maybe open a PR from this driver and after that, migrate the driver if need some changes to qx driver itself.

You are ok with that ?

Hi @blaa ! My only concern is the "valid value" that can be readed on "leading" can be a option between 3 possibilities. but the Qx sub-driver only accepts one. Im building the sub-driver based on a megatec-hex driver, its basically the same thing.

cristovamperes commented 7 months ago

I'm trying to make nut work with my SMS Manager III using the nutdrv_qx driver with no luck.

Here's my ups.conf

pollinterval = 15
maxretry = 3

offdelay = 120
ondelay = 240

[apc]
# SMS Manager III
driver = nutdrv_qx
port = /dev/ttyUSB0
desc = "SMS Manager III"

Am I missing something?

alexwbaule commented 7 months ago

@cristovamperes in nuts 2.8.0 up, there is a SMS driver, that i built.

Here is the MAN https://github.com/networkupstools/nut/blob/master/docs/man/sms_ser.txt

cristovamperes commented 7 months ago

I'm running proxmox with bullseye so the package available is < 2.8.0. Created a new lxc with debian, updated to bookwork passingthrought the usb port. Using apt install nut was able to install 2.8.0-7

# nut-scanner -V
Network UPS Tools - 2.8.0

But running nut-scanner -U won't detect the UPS and after checking /lib/nut/ for the sms_ser driver found out that it's not there.

alexwbaule commented 7 months ago

Sorry @cristovamperes

The merge was for 2.8.1 milestone...

https://github.com/networkupstools/nut/pull/2090

cristovamperes commented 7 months ago

Great! It's now running. Testing with PeaNUT from https://github.com/Brandawg93/PeaNUT

raphaeleduardo42 commented 5 months ago

Worked great whe using with SMS PRO 1500va, really thank you guys.

Is it possible to implement the battery runtime by the data got?