Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legrand "WHAD HE" should be supported but it doesn't work. #2038

Open
sathia-musso opened this issue Sep 5, 2023 · 8 comments
Open

Legrand "WHAD HE" should be supported but it doesn't work. #2038

sathia-musso opened this issue Sep 5, 2023 · 8 comments
Labels
Legrand Devices produced and/or branded by Legrand

Comments

@sathia-musso
Copy link

sathia-musso commented Sep 5, 2023

Hi, according to the Hardware compatibility list the Legrand WHAD HE series should be supported with 4 stars, but in reality it doesn't work. I've looked a bit and it appears that in 2018 a Legrand representative was about to release a specific driver for this series, but as far as I see it was not merged zykh#4

@jimklimov jimklimov added the Legrand Devices produced and/or branded by Legrand label Sep 11, 2023
@jimklimov
Copy link
Member

Just in case - which NUT version are you running? Many systems still package 2.7.4, and fixes from 2018 would be part of 2.8.0 (or current master) codebase.

@sathia-musso
Copy link
Author

I compiled from nut-2.8.0

@sathia-musso
Copy link
Author

sathia-musso commented Sep 11, 2023

a strace looks like this:

  openat(AT_FDCWD, "/usr/local/ups/etc/ups.conf", O_RDONLY) = 3
  fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
  fstat(3, {st_mode=S_IFREG|0644, st_size=50, ...}) = 0
  read(3, "[Basement]\n    driver=metasys\n  "..., 4096) = 50
  read(3, "", 4096)                       = 0
  close(3)                                = 0
  write(2, "   0.000000\t", 12   0.000000   )           = 12
  write(2, "[D1] Starting UPS: Basement\n", 28[D1] Starting UPS: Basement
  ) = 28
  stat("/usr/local/ups/bin/metasys", {st_mode=S_IFREG|0755, st_size=370768, ...}) = 0
  clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7faf3c30fa10) = 1982700
  rt_sigaction(SIGALRM, {sa_handler=0x5617d81bfd20, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7faf3c518420}, NULL, 8) = 0
  alarm(45)                               = 0
  wait4(1982700, Network UPS Tools - Metasystem UPS driver 0.08 (2.8.0)
  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Error executing command 0

  Could not communicate with the ups: No such file or directory
  [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 1982700
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1982700, si_uid=120, si_status=1, si_utime=0, si_stime=0} ---
  alarm(0)                                = 40
  write(2, "   5.009695\t", 12   5.009695   )           = 12
  write(2, "Driver failed to start (exit sta"..., 39Driver failed to start (exit status=1)
  ) = 39

and as far as I can see, this is where it fails:

/* Read STX byte */
res = ser_get_char(upsfd, my_buf, 1, 0);
if (res < 1) {
	ser_comm_fail("Receive error (STX): %" PRIiSIZE "!!!\n", res);
	return -1;
}

so it looks it can't talk at all with the bus

and here's the driver before being forked:

  umask(022)                              = 022
  openat(AT_FDCWD, "/var/state/ups/metasys-Basement.pid", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
  getpid()                                = 1988634
  fstat(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
  write(4, "1988634\n", 8)                = 8
  close(4)                                = 0
  umask(022)                              = 022
  openat(AT_FDCWD, "/dev/ttyS0", O_RDWR|O_EXCL|O_NOCTTY|O_NONBLOCK) = 4
  flock(4, LOCK_EX|LOCK_NB)               = 0
  ioctl(4, TCGETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  ioctl(4, TCFLSH, TCIFLUSH)              = 0
  ioctl(4, TCGETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  ioctl(4, SNDCTL_TMR_START or TCSETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  ioctl(4, TCGETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  write(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 100) = 100
  clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=0}, NULL) = 0
  write(4, "\2\2\0\2", 4)                 = 4
  clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=0}, NULL) = 0
  select(5, [4], NULL, NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
  write(2, "Communications with UPS lost: Re"..., 57Communications with UPS lost: Receive error (STX): 0!!!

@jimklimov
Copy link
Member

Could it be that the UPS firmware (or HW it runs on) is slower than the driver expects? Can you try increasing the timeout (the last couple of "1" sec and "0" usec parameters to ser_get_char()) as a first shot?

While at it, since you are building NUT, can you try using the current master branch as the base (especially useful if a PR would come out of this adventure)? At the very least, there were some improvements to make run-time debugging easier.

If using an IDE like NetBeans is an option (can use GDB over SSH to run code on an appliance and an IDE on your workstation), you could even try stepping through the driver code directly. Otherwise, peppering interesting places in the code with upsdebugx() is an option - then also a larger debug verbosity level (and starting the driver directly, not via upsdrvctl wrapper) might help.

One more idea is to check FS permissions for /dev/ttyS0 - can the nut driver runtime user account access it (R/W)? Probably yes, should have got permissions errors otherwise, but better check it explicitly :) Also, is it connected to a true serial port, or some USB dongle (might be /dev/ttyUSB0 instead, then - and may need some fuss about udev or similar setup for auto-permissions)?

@sathia-musso
Copy link
Author

sathia-musso commented Sep 11, 2023

It is most definitely not attached to a Usb dongle, I will make some tests and write here if I find something.

  root@tank:/opt/nut# /usr/local/ups/sbin/upsdrvctl -u nut  -D start
  Network UPS Tools - UPS driver controller 2.8.0-2336-ge8985bcfa
     0.000001 [D1] upsdrvctl commanding all drivers (1 found): (null)
     0.000038 [D1] Starting UPS: Basement
  Network UPS Tools - Metasystem UPS driver 0.09 (2.8.0-2336-ge8985bcfa)
  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Receive error (STX): 0!!!

  Communications with UPS lost: Error executing command 0

  Could not communicate with the ups: No such file or directory
     5.009339 Driver failed to start (exit status=1)
     5.009397 [D1] Completed the job of upsdrvctl tool, cleaning up and exiting now

--
Git log

  commit e8985bcfa77df22c02b6ca6e0936a0bdfeafd754 (HEAD -> master, origin/master, origin/HEAD)
  Merge: 7ae19e5c5 98ee05919
  Author: Jim Klimov <[email protected]>
  Date:   Sun Sep 10 20:26:51 2023 +0200

      Merge pull request #2045 from jimklimov/docs-usb-explore

--
and this is the driver itself.

  getpid()                                = 2546612
  fstat(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
  write(4, "2546612\n", 8)                = 8
  close(4)                                = 0
  umask(022)                              = 022
  openat(AT_FDCWD, "/dev/ttyS0", O_RDWR|O_EXCL|O_NOCTTY|O_NONBLOCK) = 4
  flock(4, LOCK_EX|LOCK_NB)               = 0
  ioctl(4, TCGETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  ioctl(4, TCFLSH, TCIFLUSH)              = 0
  ioctl(4, TCGETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  ioctl(4, SNDCTL_TMR_START or TCSETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  ioctl(4, TCGETS, {B2400 -opost -isig -icanon -echo ...}) = 0
  write(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 100) = 100
  clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=0}, NULL) = 0
  write(4, "\2\2\0\2", 4)                 = 4
  clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=0}, NULL) = 0
  select(5, [4], NULL, NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
  write(2, "Communications with UPS lost: Re"..., 57Communications with UPS lost: Receive error (STX): 0!!!

--

ls -lah /dev/ttyS0
  crw-rw---- 1 root nut 4, 64 Sep 11 13:59 /dev/ttyS0

@sathia-musso
Copy link
Author

by the way, having read all the thread of that guy from Legrand it looked like he said that the metasys driver was not compatible at all with WHAD HE (High Efficiency, new models) and it seems to me that his PR was never merged. So that's why it doesn't surprise me that it isn't getting any data from the serial bus.

@jimklimov
Copy link
Member

jimklimov commented Sep 11, 2023

For a random shot, check if they talk Qx protocols? e.g. with nutdrv_qx or even echo/nc/socat/minicom/... chatter to the serial port directly?

IIRC the recommended start is to set the port to 1200 baud and echo Q or Q1 to it, a compatible device would return (<some readings' numbers> <bitmask for status>

@sathia-musso
Copy link
Author

/usr/local/ups/bin/nutdrv_qx -a Basement -u nut
Network UPS Tools - Generic Q* Serial driver 0.33 (2.8.0-2336-ge8985bcfa)

Device not supported!
Device not supported!

I'll test the chatter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Legrand Devices produced and/or branded by Legrand
Projects
None yet
Development

No branches or pull requests

2 participants