Code Monkey home page Code Monkey logo

plugctl's Introduction

plugctl

Control your Smartplug from Maginon / Aldi
Based upon information from https://www.dealabs.com/bons-plans/prise-wifi-/85521?page=36 and https://github.com/netdata/loxone/tree/master/maginon_Smart-Plug

Build

Make sure you have Go properly installed, including setting up your GOPATH

Next, run

$ cd $GOPATH
$ go get github.com/42wim/plugctl

You'll have the binary 'plugctl' in $GOPATH/bin

Usage

$ plugctl
  -conf="": a valid config file (uses plugctl.conf if exists)
  -credentials="admin:admin": credentials specify as <login>:<pass>
  -csvfile="output.csv": file to write csv output to (only used with -daemon)
  -daemon=false: run as a (foreground) daemon with polling webserver
  -debug=false: show debug information
  -delay=1: polling delay of statistics in seconds (only used with -daemon)
  -disable="": disable power/cloud/ap
  -enable="": enable power/cloud/ap
  -ip="": ipv4 address of smartplug device
  -port=8080: webserver port (only used with -daemon)
  -raw="": raw command to execute on device (via telnet)
  -show="": show info/uptime/power
  -toggle="": toggle power
  • enable

    • power : enable power output of the plug
    • ap: disable AP mode on the smartplug (for security reasons). Also saved in NVRAM (survives reboot/powerfailure)
    • cloud: disable connections from smartplug to the cloud (iotc). Does not survive a reboot/powerfailure!
  • disable: opposite of enable options above

  • toggle:

    • power: toggles power output of the plug
  • show

    • info: shows current Ampere - Watt - Watt/hour - Volt usage
    • power: shows if power output is on or off
    • uptime: show uptime of the device
  • raw "command": executes a command on the plug (it's running busybox/linux)

    here you can chain commands. eg command1 && command2

  • daemon: starts a webserver and polls the device every second for information

    • port: specify listen port for the webserver (default 8080) (only needed with -daemon)
    • csvfile: specify cvsfile to write to (default "output.csv") (only needed with -daemon)

Configfile

See plugctl.conf.sample (https://github.com/42wim/plugctl/blob/master/plugctl.conf.sample)

If plugctl.conf exists in the current directory it will be used, otherwise a config file can specified using the -conf flag

E.g. The ip of your plug can be specified in plugctl.conf, so you don't need to give the -ip option with every command

Webserver

When -daemon option is used, a webserver will listen by default on port 8080

Available URL

  • /history - webpage/javascript which parses the csvfile history + current data into a chart history

  • /stream - webpage/javascript which shows a realtime chart stream

Examples

Enable plug on ip 192.168.1.50 with login admin and password test

$ plugctl -ip 192.168.1.50 -credentials "admin:test" -enable power
enabling plug.

Get usage information about plug on ip 192.168.1.50 with default password

$ plugctl -ip 192.168.1.50 -show info
0.01 Ampere - 0.07 Watt - 0.00 Watt/hour - 230.90 Volt

Disable the AP mode on the smartplug (for security reasons). This is saved on reboot!

$ plugctl -disable ap
disabling AP...success
saving state...already set

View the CPU info of the device by using the raw command

$ plugctl -raw="cat /proc/cpuinfo"
system type             : Ralink SoC
processor               : 0
cpu model               : MIPS 24K V4.12
BogoMIPS                : 239.61
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes
ASEs implemented        : mips16 dsp
VCED exceptions         : not available
VCEI exceptions         : not available

Get all the usage information Watt/Ampere/Energy/Volt in one go using the rawt command

$ plugctl -raw "GetInfo W && GetInfo I && GetInfo E && GetInfo V"
$01W00 000007
$01I00 000064
$01E00 002134
$01V00 236728

Start daemon/webserver on port 8888 with debug and device on ip 192.168.1.50 and save CSVfile to plug.csv

$ plugctl -daemon -debug -port 8888 -ip 192.168.1.50 -csvfile plug.csv
starting foreground daemon ;-)
[2015/01/11 21:28:13 3.84 66.37 4.47 233.06] took 392.1955ms
[2015/01/11 21:28:14 3.82 66.37 4.47 233.12] took 366.52ms

You can now surf to http://localhost:8888/stream to see realtime chart updating. If you're running for a while or have historic data in plug.csv you can go to http://localhost:8888/history

plugctl's People

Contributors

42wim avatar mpparsley avatar

Stargazers

Florian Michael Szczodrowski avatar Julian Groß  avatar Julien Quiévreux avatar  avatar  avatar

Watchers

Xavier Mertens avatar James Cloos avatar  avatar Julian Groß  avatar Zathras42 avatar  avatar

plugctl's Issues

Current not

2015/02/15 10:47:59,0.88,20.52,1.11,234.70

I have a consuption of 20 watts of 234.7 Volts
Still it tells me i'm using 0.88 Amps, so something is wrong in the conversion ?

make width & height of the graph an option

This is a suggestion but for me the graph is too small in width since i only look at it from my windows box so for now i keep changing the sources get 1600 pixels in width for the graph. When graph is wider it can display more data so maybe it's not a bad idea to be able to change (at least) the width of the graph with a command line parameter

"/stream" is using a cached version of "/read.json" when getting new data

Hi,

As i mentioned before "/stream" is not working with me. I looked into the problem myselve and the problem is that the javascript keeps getting a cached version of "/read.json" resulting in never changing data. I have this problem on internet explorer 11 but not in Firefox.

internet explorer screenshot:
knipsel

Firefox screenshot taken in same timeframe as internet explorer
knipsel2

The fix is rather simple.
just add an ever changing value as a parameter for getting the json value like so:
window.intervalId = setInterval(function () {
dat=new Date();
$.getJSON('/read.json?t=' + dat.toString() , function(data) {
d.push([new Date(),data[1],data[2],data[3],data[4]])
g.updateOptions( { 'file': d } );
});
}, 1000);

and it works in internet explorer as well

/history sometimes has the same problem as well, i couldn't get the data for the last hour, i suspect, but haven't looked into this that it's the same problem. Internet explorer is getting the data from it's cache

Can't Connect

Hi,
Thanks for your work on this. It's exactly what I'm after.

Is there any prep work I need to do on the device itself, or am I missing something?

I've tried a few commands but it says it "can't connect".

[email protected]:~/.go/bin$ ping -c 2 192.168.8.76
PING 192.168.8.76 (192.168.8.76) 56(84) bytes of data.
64 bytes from 192.168.8.76: icmp_seq=1 ttl=255 time=6.09 ms
64 bytes from 192.168.8.76: icmp_seq=2 ttl=255 time=5.97 ms

[email protected]:~/.go/bin$ ./plugctl -ip 192.168.8.76 -show info
2019/07/04 20:39:26 can't connect

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.