Giter Site home page Giter Site logo

jacknewman12 / koradmote Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 1.83 MB

A simple control server for Korad power supplies

License: MIT License

HTML 4.31% CSS 6.56% Rust 50.08% TypeScript 38.07% Shell 0.99%
korad tenma farnell stamos velleman powersupply remote

koradmote's Introduction

A remote for Korad power supplies

A simple Korad (and clones) power supply server.

Screenshot

Design Goals:

  • Dirt simple REST API so other automated frameworks can toggle devices
  • No changing of voltage / current. i.e. Idiot-proof
  • Simple frontend and backend design - only a single source
  • Single binary output - all files embedded, no mucking around

Running

Grab the binaries from the Releases.

./koradmote Dev1 /dev/tty/Blah Dev2 /dev/tty/Junk

API

All Devices

/device/ Returns the current state of all devices

curl -s localhost:8000/device/
{
  "Dev1" :{"voltage":0.0, "current":0.0, "power":false},
  "Dev2" :{"voltage":0.0, "current":0.0, "power":false},
  "Dev3" :{"voltage":0.0, "current":0.0, "power":false},
  "Etc๐Ÿš€":{"voltage":0.0, "current":0.0, "power":false}
}

Single Device

/device/{name}/ Returns the state of just a single device or 404 Not Found for invalid device name

curl -s localhost:8000/device/Dev1
  {"voltage":0.0, "current":0.0, "power":false}

Toggle Devices

/device/{name}/toggle will toggle the device

/device/{name}/toggle/true will set the device to the target state

The reponse will return the state of the power supply after the toggle or 404 Not Found for invalid device name and 500 Internal Server Error for toggle/serial comms failure.

curl -s localhost:8000/device/Dev1/toggle
  {"voltage":0.0, "current":0.0, "power":false}
curl -s localhost:8000/device/Dev1/toggle/false
  {"voltage":0.0, "current":0.0, "power":false}

Building

Assuming Node.js and Rust are installed

  npm install
  npm run build
  cargo build --release

Note that the debug version of the binary will use the files in the /build/ folder for faster development. The release build will embed the files inside the binary

You can create some virtual serial ports on linux via:

sudo socat -d -d pty,link=/dev/ttyS0,raw,echo=0 pty,link=/dev/ttyS1,raw,echo=0

Logging

There are various logging levels implemented for this application:

LOG=DEBUG ./koradmote
LOG=INFO ./koradmote
LOG=OFF ./koradmote

koradmote's People

Contributors

dependabot[bot] avatar jacknewman12 avatar voidedlegacy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

stuartjmatheson

koradmote's Issues

Add more compile targets

Note: Use musl for linux so we can ignore the libudev dependency.

I think the target matrix should be:

x86_64-unknown-linux-musl
x86_64-pc-windows-gnu
arm-unknown-linux-musleabihf
- Whatever the Mac OS one is - 

Changing threading implementation

Original feature just splits the database (containing the serial port + current status) and the combines it again once the threads are complete.

Task is to change it so that each thread takes the serial port permanently and pushes the status results to a mpsc. The receiver thread can then push the changes to the status dict (and maybe also trigger a websocket push once its implemented).

This should make it a little easier to recreate serial devices if something goes wrong with them (im looking at you windows) and means we can just poll the PSUs as fast as possible without hurting the web interface speed.

Merge to Warp to compare features / overhead

I think warp might be better than rocket for such a small project.

TODO: Merge over to warp and see if it reduces the memory footprint (its only 2mb atm).
Also just curious how that library compares in features.

Add -v debugging

The -v flag currently does nothing.

Would probably be nice to dump the serial ports + settings, rocket mounts, etc.

Improve Toggle / Status update error handling

Should probably make the update_state and set_power function return a Result. Currently is very rare to fail, and its mostly harmless (the next UI update will probably show the real state).

Also adding a with_context({psu_name}) would be nice

TODO: Should we retry the update? Push some information back up to the user?

Forward the entire PSU Status struct

Should be very simple to import the entire Status from the Ka3005p driver:
{"voltage":0.0, "current":0.0, "power":false}
to
{"voltage":0.0, "current":0.0, "channel1": "CV","channel2": "CV","beep": "On","lock": Unlocked,"output": "On"}

Note this ticket doesn't involve updating the web interface to show all this data. (Is this extra data even useful for the user?)
This is simply so we don't have to redefine the state struct ourselves.

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.