Writing a Small Bottle Web Application with AJAX API For The Koukaam NETIO230A

I needed an easy way to switch power outlets on and off remotely. So I bought a Koukaam NETIO230A and wrote a Python module to communicate with it via TCP. Now I added a Bottle based web app written in Python that uses that class to interact with the NETIO230A. It consists of an API (not very elaborate yet) and a single page that uses the API via AJAX.

Here is the finished Bottle code: webserver.py. And here is a screenshot of how the app looks:

Screenshot of the NETIO230A bottle web app

Here Is Why I Wrote This Web App

There is a big problem with the NETIO230A: It crashes quite often. This occurs when there is too much stuff going on on the network it is attached to (previously a port scan was enough, fortunately the device became a bit more robust with later firmware versions). If it ever crashes, you need to restart it to make it available again which involves shutting down the devices connected to its outlets as they will loose power during restart of the NETIO230A, which is annoying.
The solution was to isolate the device on a network that only my router shares. Then I added a rule on the router to forward packets from my normal local network to the 'Telnet port' of that box (doing so does not affect the stability of the device too much). Now in my local network I run a small plug computer, a Seagate GoFlex Home, which let's me execute Python code and thus run a Bottle web app. As it is always switched on, it's perfect to host this NETIO230A web app.
When you compare my bottle web app to the original web page of the device, you'll notice that it's much simpler and thus works better for mobile devices. This allows me to use it just like an app on my Android mobile phone.

What you need to run this app

  • A machine that is capable of running Python
  • The following Python modules:
    • bottle (can be installed via pip)
    • netio230a (the one the web app comes with)

The remaining steps are described in the comments of the web app.

Next Steps

  • To secure this web app, I should add authentication.

Resources

Comments