Retrieving statistics from a TP-Link TL-WA801ND WAP

I recently upgraded my home wireless network via a dedicated WAP as the one built-in to my router struggled with coverage. In doing so I lost the ability to retrieve statistics like the number of connected wireless clients as it doesn’t support SNMP.

I thought it would be relatively easy to scrape this information from the web interface, but no. Although I found the page that contained this it seems you have to fetch a couple of other pages before it will serve it up.

So, in case anyone may be interested in doing this here is a simply Python script that displays the number of connected wireless clients in a format suitable for graphing with MRTG.


#!/usr/bin/env python3
import re
from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup

BASE_URL = 'http://192.168.128.254/'
headers = {'Referer': BASE_URL}
auth = ('admin', 'yourpasswordgoeshere')
s = requests.Session()
r = s.get(BASE_URL, headers=headers, auth=auth)
r = s.get(BASE_URL + 'dynaform/css_main.css', headers=headers, auth=auth)
r = s.get(BASE_URL + 'dynaform/common.js', headers=headers, auth=auth)
r = s.get(BASE_URL + 'localiztion/char_set.js', headers=headers, auth=auth)
r = s.get(BASE_URL + 'userRpm/WlanStationRpm.htm', headers=headers, auth=auth)
soup = BeautifulSoup(r.text)
js = soup.find('script')
jss = str(js).replace('\n','')
m = re.search('Array\((\d+)',jss)
if m:
print(m.group(1))
print('0\n0\nWireless Clients')

Controlling the Linux Clementine media player with OpenHAB & MQTT

I use the Clementine media player on my Linux desktop machine at home for music (mostly a couple of Internet radio stations) and I wanted to have an easy way to control it. I have a wall mounted Android tablet which I use as an interface to the OpenHAB home automation system so that seemed like an obvious choice.

I don’t run OpenHAB on my Linux desktop so I needed a way for my OpenHAB server to communicate with it. Clementine has two ways you can control it remotely – a proprietary method based on Google Protocol Buffers and a more generic one using the D-Bus based MPRIS. I chose the later because it looked simpler and could easily be adapted to other media players that provide an MPRIS interface. The only problem was that MPRIS needs to run on the same machine as the media player so I still needed a way to communicate between it at the OpenHAB server – that’s where MQTT comes in as I’m already using it.

I wrote this small Perl script which provides the glue between MQTT and MPRIS. I should be pretty easy to extent or adapt to other media players.


DownloadDescriptionVersionUploaded
mqtt-clementinePerl script to interface between MQTT and MPRIS16-01-2015

Rutherglen – Easter 2011

Begonia and I spent the extra-long Easter weekend in 2011 in Rutherglen enjoying wine, cheese and geocaches.
389
We stayed at The Cottage on the Murray which provided a lovely base to explore the surrounding region. We visited a few of the local wineries on the first day before exploring further afield. The weather was perfect with clear warm autumn days and nights cool and crisp enough to fire up the slow combustion stove.

Eversolar Inverter Monitoring with Linux

In November 2010 I have a 1.5kw solar power system installed by Nu Energy. It came with an Eversolar TL2000AS inverter and since it came with an RS-232 & RS-485 interface I figured it wouldn’t be too hard to monitor & graph it on my web server.

I fired off an email to Nu Energy asking for software to do this but they referred me to Eversolar so I contacted them directly. Unfortunately it seems that the RS-232 interface is only used for uploading firmware, despite what the manual says. They gave me two options – purchase their Power Management Unit (PMU) or one from a German company Solar Log. I went with the former (US$300 vs US$1000).

The Eversolar PMU connects to the inverter via RS-485 using a straight-through RJ-45 cable and is connected to my LAN via ethernet. It can also be connected directly to a PC via USB and comes with some Windows software called AS Control. Since I wanted to monitor it from Linux I was hoping that it would support SNMP, but alas, that wasn’t the case.

The AS Control software communicates with the PMU via HTTP on port 8080. I used WireShark to look at the communication and implemented enough to be able to pull what I needed from the PMU with a Perl script and graph it with MRTG & RRDtool. You can see the graphed results in my Power Stats page.

One thing I discovered about the PMU is that it will actually run on power from the Inverter via the RS-485 connection so you don’t actually need the external power pack. The downside of this is that it it only works when the Inverter is providing power but I can live with this.

I’d be interested in hearing from anyone who’s doing something similar with Linux or has any information on the communication protocol for the Eversolar PMU.


DownloadDescriptionVersionUploaded
pmulogger.zipEversolar PMU/Inverter perl data logger0.1b20-12-2010

Weather Station data logger

I recently bought a wireless Weather Station on eBay and wanted to hook it up to my web server which runs Linux.

Wireless Weather Station

Google revealed a couple of free software options (one in C, the other in Python) and a couple of useful sites, in particular Jim Easterbrook’s and Michael Pendec’s.

The Python package was overkill for my needs and I was initially planning to modify the C source but it was a bit, er, messy so I decided work on my Perl skills and write something from scratch.

You can see the graphed results in my Environmental Stats page.

You can also view it via the Weather Underground:


DownloadDescriptionVersionUploaded
wslogger.plWeather Station data logger written in perl1.412-02-2011

Nagios check plugin for MythTV

Nagios is an Open Source host, service and network monitoring application that I use to monitor a couple of servers I have at home as well as a couple out on the Internet that I look after. One of my home servers is a Home Theatre PC running Linux and MythTV, and while Nagios checks to make sure its up and monitors its disk space, load & temperature, I wanted to check MythTV itself so I wrote a check plugin to do just that.

The check_mythtv plugin connects to the mythbackend process to make sure its running. It reports the status of the tuners and checks to see how much program guide is available:

$ ./check_mythtv.pl -H mythpvr
Ok: Tuners idle, 7 days program guide available

Normally I have around 7 days worth of guide data so I set the plugin to generate a warning alert (via email) if it falls to 4 days and a critical alert at 2 days. The plugin is a simple Perl script so it could easily be modified to check other things.


DownloadDescriptionVersionUploaded
check_mythtv.plNagios plugin for MythTV1.112-02-2011

Cook Islands Holiday

In April 2008 Begonia and I enjoyed our first overseas holiday together in the Cook Islands.

139

We left Sydney on Sunday 6th April and flew to the main Island of Rarotonga where we spent three days at the Rarotongan Beach Resort. It was very nice , but was only a taste of what was to come. We spent our first day relaxing at the resort – some snorkeling, the odd cocktail etc. The next day we headed into the main town of Avarua for a bit of a look around and some Black Pearl shopping. On our last day we headed over to Muri beach to do the Geocache on the Island and then a swim at a nearby beach.

We then flew over to the Island of Aitutaki and spent three days at the Aitutaki Lagoon Resort where we discovered paradise. The resort is actually on it’s own private Island called Akitua which is reached by a ferry. There were only about 40 guests at the resort while we were there, and coupled with the perfect weather it was an amazing relaxing few days.

On the first evening we went on a sunset cruise with one other couple before enjoying a five course dinner. On the second night we had an Umu (like a New Zealand Hāngi) feast following by some traditional dancing. One our last day we went on a cruise of the Lagoon which included a snorkeling stop and a BBQ lunch on One Foot Island we found another geocache.

Before coming home we spent three days in Auckland where we did some sight seeing, shopping and caching. After a week of lovely warm sunny weather in the Cook Islands Auckland turned on some typical wet weather which helped prepare us for the cold, wet autumn weather we were to get when we got home.

You can check out some photos from the trip in my Gallery

Reducing the AC3 bitrate of a video file

I recently tried unsuccessfully to watch an HD movie on my MythTV box, and while the video was fine the audio (Dolby Digital) kept dropping out. The CPU load on my server was pretty low so this wasn’t the problem and I tried copying the file to the server itself rather than accessing it via NFS from my file server to rule out network bandwidth problems.

I then decided that maybe my Amp couldn’t handle the high AC3 bitrate (640kbps) of this file so I looked into how I could reduce it. After much googling and experimenting I finally managed to create a version of the file with a reduced AC3 bitrate, and thankfully, it played fine. As it turned out the movie was pretty crap, but you get that sometimes.

I put together this script that uses various freely available Linux tools to split the video file into separate audio and video components, re-encodes the audio and then puts it back together in case I need to do this again in the future.


#!/bin/sh

infile=$1
outfile=$1-out

cd /media/Temp

tcprobe -i $infile

echo
echo Extracting AC3 soundtrack ...
echo

tcextract -d2 -i $infile -a0 -x ac3 | tcextract -d2 -x ac3 -t raw > soundtrack.ac3

echo
echo Extracting individual audio channels ...
echo

export AC3_6CH=en
/share/bin/ac3dec -o null soundtrack.ac3

echo
echo Converting individual audio files to WAV ...
echo

for i in *.pcm
do
echo $i
sox -t raw -r 48000 -w -s $i `basename $i .pcm`.wav
done

echo
echo Recreating AC3 soundtrack ...
echo

rm -f 6ch.ac3
multimux -f en_l.wav en_c.wav en_r.wav en_ls.wav en_rs.wav en_lfe.wav

echo
echo Creating Xvid AVI file ...
echo

transcode -i $infile -p 6ch.ac3 -y xvid -e 48000,16,6 -E 48000,16,6 -A -N 0x2000 -o $outfile

rm -f *.pcm *.wav

The hardest part was extracting the individual audio tracks from AC3 and I eventually found this site which had a patched version of an AC3 decoder. I had to do a bit of work to get it to compile on a recent Linux system.

The Log Cabin

40

On the June long weekend in 2007 Begonia and I headed to Medlow Bath in the Blue Mountains where we stayed at the delightful Log Cabin.

Unfortunately, the weather wasn’t delightful, at least on the Friday & Saturday with strong winds and heavy rain which flooded the cellar of the cabin taking out the central heating and hot water system. Fortunately the owner pumped it out on the Saturday and managed to get the hot water system going and there was plenty of wood to keep the fire going.

We spent Saturday morning shopping in Katoomba and then had high tea at the Hydro Majestic. On Sunday the weather had improved enough to go for a bit of a walk so we went and found two nearby geocaches. After this exercise we had a spa and a nap before heading to Ashcrofts in nearby Blackheath for dinner.

Steve’s Burritos

This is my Girlfriend’s favourite recipe.

Ingredients (serves 2 hungry Amigos):

    4-6 Tortillas (depending on size)
    1 Jar (375gm) of Old El Paso Thick ‘n Chunky Salsa (Medium)
    1 Chorizo – quartered length ways then chopped
    1 Small onion – chopped
    1 Capsicum – chopped
    A couple of mushrooms – chopped
    1 cup of cherry tomatoes cut in half
    1 cup of Kalamata olives
    140g Tomato paste
    1 Can Mexican chilli beans
    1 Clove of garlic – finely chopped
    1 Small chilli – finely chopped (Optional)
    300g grated low-fat Mozarella
    Paprika
  1. Fry chorizo over a medium heat for 2-3 minutes
  2. Add garlic and optional chilli and fry for 1-2 minutes
  3. Add onion, capsicum & cherry tomatoes and fry for 2-3 minutes
  4. Stir in salsa, beans, tomatoe paste, mushrooms and olives
  5. Bring to the boil and simmer for about 10 minutes
  6. Preheat oven to 180 degrees and give an oven proof dish a light spray of oil
  7. Spoon the mixture into the tortillas and place them in the dish
  8. Cover burritos with the cheese and sprinkle paprika over them
  9. Bake for about 10 minutes

Any left-over filling can be frozen.