Git Product home page Git Product logo

gcups's Introduction

GreenCell UPS App in docker

GC UPS App is a program that enables preview in real time and displays measurement data including input and output voltages, load frequency of the UPS, its temperature and battery capacity.

You can setup automatic system shut-off, notifications and email warnings in the event of switching to batter operation.

DISCLAIMER:
I am not affiliated with GREENCELL.GLOBAL brand, I don't represent and I was never employed by CSG S.A. nor I was ever contracted by them for doing any work whatsoever

About

I took the desktop-only electron app and forced it to run in docker with HTTP webUI enabled. I wrote a blog entry regarding the subject.

Table of Contents

Quick Start

For testing purposes (to see if this thing works on your machine) you can run the container in privileged mode but this is not recommended, read.
docker run --privileged -p 0.0.0.0:8080:8080 ghcr.io/fajfer/gcups:1.1.7

Image exposes port 8080 and the default password is gcups123

How To Run It

Container itself is ready to start, the only thing you need to do is to attach proper USB device:
docker run --device=/dev/bus/usb/001/011 -p 0.0.0.0:8080:8080 ghcr.io/fajfer/gcups:1.1.7
How to find which device to use? Read USB detection

You can also run it via Docker-compose, for which I provided an example of. This is a desktop app that was forced inside of a container and it exposes a HTTP connection which makes you unable to configure following stuff:

  • enabling/disabling HTTP server
  • changing password
  • changing HTTP server port

It's not much of a problem since we're using docker. You can decide to not publish the port and you can always map it to a different port on your host container so it isn't much of a problem. If you wish to change the password, however, then I recommend you read Custom settings part.

USB detection

An example, based on my UPS05, on how to find which USB to mount to your docker.

If you plug your usb and then proceed with sudo dmesg you will see something like this:

[21022.370000] usb 1-4: new full-speed USB device number 11 using xhci_hcd
[21022.623977] usb 1-4: New USB device found, idVendor=0001, idProduct=0000, bcdDevice= 1.00
[21022.623981] usb 1-4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[21022.623983] usb 1-4: Product: MEC0003
[21022.623985] usb 1-4: Manufacturer: MEC

Let's compare this with lsusb output:

Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 05e3:0626 Genesys Logic, Inc. USB3.1 Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 011: ID 0001:0000 Fry's Electronics MEC0003
Bus 001 Device 006: ID 046d:c31c Logitech, Inc. Keyboard K120
Bus 001 Device 004: ID 08bb:2902 Texas Instruments PCM2902 Audio Codec
Bus 001 Device 002: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Notice device number 11 from dmesg: [21022.370000] usb 1-4: new full-speed USB device number 11 using xhci_hcd

And that we can see both the product and the manufacturer

[21022.623983] usb 1-4: Product: MEC0003
[21022.623985] usb 1-4: Manufacturer: MEC

That aligns perfectly with our device: Bus 001 Device 011: ID 0001:0000 Fry's Electronics MEC0003
We need both bus and device number so --device=/dev/bus/usb/$BUS/$DEVICE gives us --device=/dev/bus/usb/001/011

Custom settings

If you didn't read my blog entry I would recommend scrolling just to the "Generating your own by-sequence" part. Basically you can mount the entire /opt/gcups/ if you wanted but the only thing you really need is /opt/gcups/db/gcups-rxdb-1-settings which is actually a LevelDB database.

Example: docker run --device=/dev/bus/usb/001/011 -p 0.0.0.0:8080:8080 -v /opt/gcups/db/gcups-rxdb-1-settings:/opt/gcups/db/gcups-rxdb-1-settings ghcr.io/fajfer/gcups:1.1.7

There's no other way at this moment to change the password during runtime since I don't know how to properly manipulate password hash and salt and it doesn't really bother me.

Docker-compose

An example of docker-compose.yaml:

version: '3'
services:  
  gcups:
    container_name: gcups
    image: ghcr.io/fajfer/gcups:1.1.7
    ports:
      - '0.0.0.0:8085:8080'
    restart: unless-stopped
    volumes:
      - $HOME/gcups-rxdb-1-settings:/opt/gcups/db/gcups-rxdb-1-settings
    devices:
      - /dev/bus/usb/001/010:/dev/bus/usb/001/010

Above example exposes port 8085 on the host, uses a volume and a device. You can safely remove volumes and would need to change your devices based on USB detection

Versioning

I'm not a fan of latest tag so I will probably not to have it here. I'm going to try to always support the latest version (1.1.7 since 02.06.2023) and this is how the container image is named. If I optimize the image I'm going to update the latest available version based on it and if GreenCell releases the new version I will also build it and provide with a new tag.

FAQ

If you are getting the following error:

/opt/gcups/gcups[101]: ../../third_party/electron_node/src/node_api.cc:1332:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.

Then you have your UPS connected via USB and provided a wrong --device for the docker image. This will obviously make the HTTP server unable to start.

gcups's People

Contributors

fajfer avatar

Stargazers

Bohdan Sukhomlinov avatar Thomas D'Hollander avatar Zada Zorg avatar  avatar Leonardo Caveglia Curtil avatar David Sn avatar

Watchers

 avatar

gcups's Issues

The server is unable to find the ups

Hi, i bought the ups for my qnap nas and i need to get the panel working for the automatic shut off.
I managed to get to the webUI but the ups is not being picked up by the software.
I'm getting the error you put at the bottom of the readme, but even when the device was correct it just kept spamming it
image
At one point i just mounted the whole /dev/bus/usb/ to the container but even that didnt help.
On your blog i saw that some guy had the exact same problem as me so i hope you can help us both

Fix CI

I gave it a blind shot based on the suggested template (never really used GH Actions before) and the image didn't properly push. I need to fix that, the current 1.1.7 image was pushed from my local machine but I don't want it to be a regular thing

Make SMTP server settings configurable

As of now the SMTP mail server settings are reset each time the container is run if there's no volume mapping to the container. I wish for the gcups container to be fully functional without using volumes or mounts and for SMTP mail server settings to be configured via environment variables

Provide some examples

README should contain examples on how to run the initial script mentioned in #1 as well as show how to run the image itself

Trim gcups extras

We can make the base image smaller sometime in the future but the low hanging fruit seems to be the /opt/gcups/. The packages contain things like pdf manuals for their products without which I believe this image will run

Write an initial setup script

If not modified, gcups doesn't serve HTTP by default (even though we're currently lying about it with EXPOSE 8080 in Dockerfile

We need an initial setup that sets up the by-sequence (as explained on my blog) with configured port and enable. As for the password - I think we can make some default one and throw it in. Right now, I'm not really sure how to approach this

Testing docker image after build

After building the image we should test if we get proper status code from the HTTP endpoint - only then should the image be pushed to mainline tag

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.