Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cprima/0a9c42755c4d5f274a3a877c20c80aae to your computer and use it in GitHub Desktop.
Save cprima/0a9c42755c4d5f274a3a877c20c80aae to your computer and use it in GitHub Desktop.
Scraping custom statistics from a Devolo Powerline adapter

Scraping custom statistics from a Devolo Powerline adapter

THAT moment when you realize that the webinterface of the access point in a Devolo dLAN® 1200+ Powerline gets updated via jQuery from a json file!

ab95b5b2-3dea-11e6-8598-294304c7cc01

curl 'http://10.xxx.yyy.zzz/cgi-bin/htmlmgr?_file=getjson&service=hpdevices'
[{"loc":"local","type":"hp200","name":"dLAN 1200+ WiFi ac","mac":"F4:06:ab:ab:ab:ab","tx":"","rx":"","ustr":"teh remote"},{"loc":"remote","type":"hp200","name":"dLAN 1200+","mac":"F4:06:aa:bb:cc:dd","tx":"85.3125","rx":"254.625","ustr":"teh master"},{}]

To make use of tht information this gist integrates a custom script return value into luci_statistics. Installation of the plugin like:

opkg install collectd-mod-exec

It is best NOT fo follow tutorials on the internet but rather copy files or contents of files in these locations:

  • /usr/lib/lua/luci/statistics/rrdtool/definitions/*.lua (copy to exec.lua)
  • /usr/share/collectd/types.db needs to be amended by own "types"
  • and in the webfront the plugin needs to be enabled plus a command added (see screenshot below)

94c06ef8-3deb-11e6-957e-f6c2d53f3614

# grep powerlan /usr/share/collectd/types.db
powerlan_rx             value:GAUGE:0:4294967295
powerlan_tx             value:GAUGE:0:4294967295

The attached script checkwifipowerlan.py must run standalone, producing lines in Collectd's plain text protocol https://collectd.org/wiki/index.php/Plain_text_protocol .

After changes to these files a

/etc/init.d/luci_statistics restart

also restarts collectd.

exec

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 CHAOS CALMER (15.05.1, r48532)
 -----------------------------------------------------
  * 1 1/2 oz Gin            Shake with a glassful
  * 1/4 oz Triple Sec       of broken ice and pour
  * 3/4 oz Lime Juice       unstrained into a goblet.
  * 1 1/2 oz Orange Juice
  * 1 tsp. Grenadine Syrup
 -----------------------------------------------------
#!/usr/bin/env python2
# vim: set fileencoding=utf-8 :
"""checkwifipowerlan.py: Read connection quality of a Devolo dLan 1200+ into col
__version__ = "1.0.1"
__author__ = "Christian Prior"
__license__ = "MIT"
import os
from json import loads
from urllib2 import urlopen
from time import sleep
#This is a feature of collectd, to call with environment variables set
HOST = os.environ.get('COLLECTD_HOSTNAME') #default None
INTERVAL=os.environ.get('COLLECTD_INTERVAL')
if INTERVAL is None:
#makes the script runnable standalone, for debugging
INTERVAL = 5
#when running 'endless', then in the output no INTERVAL attribute is necessary
while True:
response = urlopen('http://10.xx.yy.zz/cgi-bin/htmlmgr?_file=getjson&service=hp
for node in loads(response.read()):
if len(node) > 0 :
#change this:
if node['mac'] == 'F4:06:aa:bb:cc:dd':
print('PUTVAL "'+str(HOST)+'/exec-powerlan/powerlan_rx" N:'+str(int(float(node['rx']))))
print('PUTVAL "'+str(HOST)+'/exec-powerlan/powerlan_tx" N:'+str(int(float(node['tx']))))
sleep(INTERVAL)
module("luci.statistics.rrdtool.definitions.exec", package.seeall)
function rrdargs( graph, plugin, plugin_instance )
--
-- bitrate diagram
--
local powerlan = {
title = "%H: Rx and Tx at dLAN 1200+ WiFi ac",
vlabel = "MBit/s",
number_format = "%5.1lf%sBit/s",
data = {
types = { "powerlan_rx", "powerlan_tx" },
options = {
powerlan_rx = {
title = "RX",
overlay = true,
color = "0000ff"
},
powerlan_tx = {
title = "TX",
overlay = true,
color = "ff0000"
}
}
}
}
return { powerlan }
end
@cprima
Copy link
Author

cprima commented Jul 1, 2016

Not sure what is the best way to publish pictures in the description above ;)
Sure, when downloaded they won't show. But I prefer to document this Gist not just with text.

94c06ef8-3deb-11e6-957e-f6c2d53f3614
ab95b5b2-3dea-11e6-8598-294304c7cc01
exec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment