Linux - Jarcar MP5205

This project started life as a replacement for the Solar UPS. Essentially, following a move, the current office premesis in early 2022 are rented. As such there is no solar. The possibility of me drilling the necessary holes needed for the required panels to support the now aging solar UPS is negligible.

Jaycar MP5705

Enter the cheap and cheerful MP5205 from Jaycar. Cheap it may be, but perform it does! albeit with some issues around EMC/RFI compliance. There are also a bunch of undocumented features which can be used by Linux systems as well. Windows users may be able to access the information via the included Windows app, but Linux people are pretty much on their own.

In this article I outline how to connect the unit to an MQTT hub and then pipeline the information into an OpenSearch cluster. The result is a system that provides analytics that rival big iron computer centre backup systems (but not necessarily their big battery backup times).

Software

Despite the Jaycar website claiming Linux compatibility the software download on the same site only provides a Windows .exe setup program. The most Linux users can expect, out of the box, is the ability to shutdown when battery exhaustion is imminent.

The key to obtaining the information needed from the unit is to recognize its origins. The Jarcar MP5205 is in fact known in South America as the Hunnox HNX-650. The significance of this discovery is that Linux UPS software is available pretty much off the shelf for this unit. And it works with the Jarcar MP5205!

Hunnox HNX-650 (left)

Network UPS Tools

Enter the NUT suite otherwise known as Network UPS Tools. The NUT package available on Ubuntu (the OS of choice and used extensively here at ElectricBrain) is at version 2.7.4 as at mid 2022 on Ubuntu 22.04LTS. Unfortunately this is just prior to the inclusion of support for the Hunnox compatible UPSes which was experimentally included in version 2.8.0 which is used here. Essentially that means compiling and installing from source.

At this point many people would be scared off at the mere mention of the words compile and source code. However, this author has spent the time to make installation "painless" (or very close to it) by providing steps, which make use of docker, to do everything without installing anything on the host computer at all except the final product.

It was actually quite painful deriving the needed steps from the Ubuntu package build chain. It turns out the Ubuntu packages (the original was split in to several bits) take what I consider to be a convoluted approach to packaging. Coming from a Fedora background where one simply downloads the source package and runs it with mods to obtain a new package, the Ubuntu packaging appears way more complex.

The final solution was to create a bash script file which does everything inside a container bypassing Ubuntu's packaging. Everything includes installing all the needed tools, supporting libraries and their dev source code, downloading the NUT package source code running and compiling all the bits as per the original distribution from Git and placing the results on the host's hard disk ready for a classic installation.

Ultimately the only thing required is a working Docker installation (which is beyond the scope of this article) - and of course an Internet connection - lol. Oh - that and a directory name /data which holds the results.

#!/bin/bash
# build-nut.sh
#
# Build Ubuntu configured nut package
#
docker run \
 --rm \
 --volume /data:/data \
 ubuntu:22.04 \
 /bin/bash -c \
   "set -x; \
    cd /data; \
    rm -rf nut*; \
    ls -lsah; \
    export DEBIAN_FRONTEND="noninteractive"; \
    cp /etc/apt/sources.list /etc/apt/sources.list~; \
    sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list; \
    chown -Rv _apt:root /var/cache/apt/archives/partial/; \
    chmod -Rv 700 /var/cache/apt/archives/partial/; \
    chown -Rv _apt:root /data; \
    chmod -Rv 775 /data; \
    echo 'Acquire::http { Proxy \"http://hostb.localdomain:3142\"; };' >> /etc/apt/apt.conf.d/01proxy; \
    apt-get update && apt-get -y install curl git; \
    git clone https://github.com/networkupstools/nut.git; \
    apt-get -y install gnupg pbuilder ubuntu-dev-tools apt-file debhelper dh-python pkg-config libnss3-dev libgd-dev libusb-dev; \
    cd nut; \
    ./autogen.sh; \
    ./configure \
       --build=aarch64-linux-gnu \
       --prefix=/usr \
       --includedir=\${prefix}/include \
       --mandir=\${prefix}/share/man \
       --infodir=\${prefix}/share/info \
       --sysconfdir=/etc \
       --localstatedir=/var \
       --disable-option-checking \
       --disable-silent-rules \
       --libdir=\${prefix}/lib/aarch64-linux-gnu \
       --runstatedir=/run \
       --disable-maintainer-mode \
       --disable-dependency-tracking \
       --prefix= \
       --sysconfdir=/etc/nut \
       --includedir=/usr/include \
       --mandir=/usr/share/man \
       --libdir=\${prefix}/lib/aarch64-linux-gnu \
       --with-ssl \
       --with-nss \
       --with-cgi \
       --with-dev \
       --enable-static \
       --with-statepath=/run/nut \
       --with-altpidpath=/run/nut \
       --with-drvpath=/lib/nut \
       --with-cgipath=/usr/lib/cgi-bin/nut \
       --with-htmlpath=/usr/share/nut/www \
       --with-pidpath=/run/nut \
       --datadir=/usr/share/nut \
       --with-pkgconfig-dir=/usr/lib/aarch64-linux-gnu/pkgconfig \
       --with-user=nut \
       --with-group=nut \
       --with-udev-dir=/lib/udev \
       --with-systemdsystemunitdir=/lib/systemd/system \
       --with-systemdshutdowndir=/lib/systemd/system-shutdown; \
    make
   "

A directory on the host machine is mapped in to the container. Ultimately this directory will end up with the resulting compiled code. The configuration is taken from the original package, ensuring everthing ends up in the correct places according the Ubuntu view of the world.

Once the compiling process is completed successfully all that needs to happen is a "cd /data" followed by "make install" on the host computer where the UPS is attached.

To launch the UPS software just run "systemctl start nut-server"

The Ubuntu package systemd scripts are as follows:

# Install as /etc/systemd/system/nut-driver.service
#
[Unit]
Description=Network UPS Tools - power device driver controller
After=local-fs.target network.target systemd-udev-settle.service
Wants=systemd-udev-settle.service
StopWhenUnneeded=yes

[Service]
ExecStart=/sbin/upsdrvctl -u root start
ExecStop=/sbin/upsdrvctl -u root stop
Type=forking

 

# Install as /etc/systemd/system/nut-server.service
#
[Unit]
Description=Network UPS Tools - power devices information server
After=local-fs.target network.target nut-driver.service
# We don't Require drivers to be successfully started! This would be
# a change of behavior compared to init SysV,
 and could prevent from
# accessing successfully started,
 at least to audit a system.
Wants=nut-driver.service
Before=nut-monitor.service

[Service]
ExecStartPre=/bin/sleep 10
ExecStart=/sbin/upsd
Type=forking

[Install]
WantedBy=multi-user.target

 

# Install as /etc/systemd/system/nut-monitor.service
#
[Unit]
Description=Network UPS Tools - power device monitor and shutdown controller
After=local-fs.target network.target nut-server.service

[Service]
ExecStart=/sbin/upsmon
PIDFile=/run/nut/upsmon.pid
Type=forking

[Install]
WantedBy=multi-user.target

 

root@hosta:/etc/systemd/system# systemctl status nut-server.service    
		● nut-server.service - Network UPS Tools - power devices information server
		    Loaded: loaded (/etc/systemd/system/nut-server.service; enabled; vendor preset: enabled)
		    Active: active (running) since Thu 2022-11-17 17:11:20 AEDT; 6s ago
		   Process: 70992 ExecStartPre=/bin/sleep 10 (code=exited,
 status=0/SUCCESS)
		   Process: 71000 ExecStart=/sbin/upsd (code=exited,
 status=0/SUCCESS)
		  Main PID: 71001 (upsd)
		     Tasks: 1 (limit: 9217)
		    Memory: 488.0K
		       CPU: 29ms
		    CGroup: /system.slice/nut-server.service
		            └─71001 /sbin/upsd

		Nov 17 17:11:20 hosta.localdomain upsd[71000]: fopen /run/nut/upsd.pid: No such file or directory
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: Could not find PID file '/run/nut/upsd.pid' to see if previous upsd instance is already running!
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: listening on 192.168.0.49 port 3493
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: listening on 127.0.0.1 port 3493
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: listening on 192.168.0.49 port 3493
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: listening on 127.0.0.1 port 3493
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: Connected to UPS [Jaycar-MP5205]: nutdrv_qx-Jaycar-MP5205
		Nov 17 17:11:20 hosta.localdomain upsd[71000]: Connected to UPS [Jaycar-MP5205]: nutdrv_qx-Jaycar-MP5205
		Nov 17 17:11:20 hosta.localdomain upsd[71001]: Startup successful
		Nov 17 17:11:20 hosta.localdomain systemd[1]: Started Network UPS Tools - power devices information server.
 

EMC/RFI regulatory compliance

In Table part 2, in the row idenitifed by 11 in the serial column (column 2) of https://www.acma.gov.au/publications/2019-06/rules/acma-mandated-emc-standard over in the column named Applicable Standard the standard for compliance is noted as AS 62040.2 (EN 62040-2, IEC 62040-2)

Taking the cover off and taking a peek inside it seems that parts were left out for EMC that are involved in the suppression of RFI.

The Radio Frequency EMI Interference was massive. This is the spectrum as seen by the Yaesu FT-710's SDR receiver.

The fix was to buy a Yunpen YG10T5 suppression unit and fit inside the UPS to replace the missing parts.

After the fix the MP5202 now happily co-exists with the radios (See the Ham Radio section of the site)