Monday, November 11, 2024

APC UPS 1200VA connected to linux debian

On 1st November 2023 was one of the worst ever day in my working life. One super strongest ever lightning strike completely shut off the the whole house electric supply! I have UPS connected to my laptop which the laptop also shut off abruptly. I would say "lucky" ? that that the laptop managed to boot up unfortunately the USBs are all broken, it does not function anymore. Never in my life would think that even with a laptop protected by an APC UPS, the device would be damage, well partially. Closer inspection show that laptop power adapter socket, the live connector got burned mark. It is just how strong was the lightning strike! So lesson learn, this time I bought a new APC UPS which connected in serial fashion and behind a surge protector (Targus) and hoping that with 2x protections, I will survive in the incoming lightning storm. hopefully. 🤞🙏

Let's see the APC UPS






and when it is connected and running



This unit come with monitoring system. It can be connected to the pc device via USB cable which is awesome! Best part is, if you are using linux, it comes detected automagically. At the time of this writing, I'm using Debian 12.7. 

what you need to do is just installed package apcupsd

$ sudo apt install apcupsd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  hunspell-gl-es hunspell-sv-se libnvidia-compiler libu2f-udev libwpe-1.0-1 libwpebackend-fdo-1.0-1 linux-headers-6.1.0-17-common
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  apcupsd-doc libusb-0.1-4
Suggested packages:
  apcupsd-cgi
The following NEW packages will be installed:
  apcupsd apcupsd-doc libusb-0.1-4
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 670 kB of archives.
After this operation, 1,779 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libusb-0.1-4 amd64 2:0.1.12-32 [23.4 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 apcupsd amd64 3.14.14-3.1+b1 [256 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 apcupsd-doc all 3.14.14-3.1 [390 kB]
Fetched 670 kB in 0s (3,160 kB/s)    
Selecting previously unselected package libusb-0.1-4:amd64.
(Reading database ... 438864 files and directories currently installed.)
Preparing to unpack .../libusb-0.1-4_2%3a0.1.12-32_amd64.deb ...
Unpacking libusb-0.1-4:amd64 (2:0.1.12-32) ...
Selecting previously unselected package apcupsd.
Preparing to unpack .../apcupsd_3.14.14-3.1+b1_amd64.deb ...
Unpacking apcupsd (3.14.14-3.1+b1) ...
Selecting previously unselected package apcupsd-doc.
Preparing to unpack .../apcupsd-doc_3.14.14-3.1_all.deb ...
Unpacking apcupsd-doc (3.14.14-3.1) ...
Setting up libusb-0.1-4:amd64 (2:0.1.12-32) ...
Setting up apcupsd-doc (3.14.14-3.1) ...
Setting up apcupsd (3.14.14-3.1+b1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/apcupsd.service → /lib/systemd/system/apcupsd.service.
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u7) ...
Scanning processes...                                                                                                                                                                         
Scanning processor microcode...                                                                                                                                                               
Scanning linux images...                                                                                                                                                                      

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

and then start it.

$ sudo systemctl start apcupsd
$ sudo systemctl status apcupsd
● apcupsd.service - UPS power management daemon
     Loaded: loaded (/lib/systemd/system/apcupsd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2024-11-11 21:32:23 +08; 2s ago
       Docs: man:apcupsd(8)
    Process: 212186 ExecStartPre=/lib/apcupsd/prestart (code=exited, status=0/SUCCESS)
    Process: 212190 ExecStart=/sbin/apcupsd (code=exited, status=0/SUCCESS)
   Main PID: 212191 (apcupsd)
      Tasks: 3 (limit: 37451)
     Memory: 584.0K
        CPU: 8ms
     CGroup: /system.slice/apcupsd.service
             └─212191 /sbin/apcupsd

Nov 11 21:32:23 debby systemd[1]: Starting apcupsd.service - UPS power management daemon...
Nov 11 21:32:23 debby systemd[1]: apcupsd.service: Can't open PID file /run/apcupsd.pid (yet?) after start: No such file or directory
Nov 11 21:32:23 debby apcupsd[212191]: apcupsd 3.14.14 (31 May 2016) debian startup succeeded
Nov 11 21:32:23 debby apcupsd[212191]: NIS server startup succeeded
Nov 11 21:32:23 debby systemd[1]: Started apcupsd.service - UPS power management daemon.

and even better, gnome automatically detect it. I was really impress how little effort require to make things work.



one thing it does not work out of the box is communication with UPS also lost... but not sure how gnome able to detect the battery percentage..anyway, guess this is the work require.

$ sudo apcaccess

APC      : 001,018,0437

DATE     : 2024-11-11 21:33:20 +0800  

HOSTNAME : debby

VERSION  : 3.14.14 (31 May 2016) debian

UPSNAME  : debby

CABLE    : USB Cable

DRIVER   : USB UPS Driver

UPSMODE  : Stand Alone

STARTTIME: 2024-11-11 21:32:23 +0800  

STATUS   : COMMLOST 

MBATTCHG : 5 Percent

MINTIMEL : 3 Minutes

MAXTIME  : 0 Seconds

NUMXFERS : 0

TONBATT  : 0 Seconds

CUMONBATT: 0 Seconds

XOFFBATT : N/A

STATFLAG : 0x05000100

END APC  : 2024-11-11 21:33:20 +0800  

In any case, I really like this unit come with monitoring system. I guess just need to find out how to fix the communication problem and it would be a blast!


Reference:

https://opensource.com/article/21/12/linux-apcupsd

https://wiki.debian.org/apcupsd

 

Sunday, June 2, 2024

my code is your code

 If tomorrow is debug day (Type "function")

And I'm standin' with the front-end design

And the lead asks me what I did with my code

I will say I coded with you


If I wake up in Code War III (Code War III)

I see bugs and vulnerabilities

And I feel like I want to go home

It's okay if you're debugging with me


(

Cuz your code is my code

My code is your code

It would take an infinity loop to break us

And the chains of GitHub couldn't fork us

) x2


If I lose my fame and followers (Really don't matter)

And my server crashes down (Really don't matter)

As long as I got your commits (Really don't matter)

It really don't matter (Really don't matter)


As the versions they pass us by (the versions, the versions, the versions, the versions, the versions)

We stay updated through each other's code (each other's code)

And no matter how many updates we make

It's okay as long as I got your merge



(

Cuz your code is my code

My code is your code

It would take an infinity loop to break us

And the chains of GitHub couldn't fork us

) x2


If my code should break today (Break today)

Don't worry, 'cause in code we iterate anyway (Oh no)

"No matter the chatter from others (truly inconsequential)

I'll stand by, awaiting you beyond the reckoning's sway"


(

Cuz your code is my code

My code is your code

It would take an infinity loop to break us

And the chains of GitHub couldn't fork us

) x2