Tuesday, 3 May 2016

A Web Status Panel On The Raspberry Pi - Part Two

In part one of this series, the status panel on details exposed via the dart:io package. To get more useful information we will look at running external commands and feeding them back to the web status panel. This version of the panel will be Linux (may work on a Mac!) only though could be easily modified for other platforms.

The dart:io package has a useful command to execute a process with arguments and collect the results. This is unsurprisingly asychronous. I chose to wrap the command into a little helper:

  runCommand(String command, List args) async {
    ProcessResult results = await Process.run(command, args);
    return results.stdout;
  }

One of the commands I wrapped was free to get memory usage:

  get memoryUsage async {
    return await runCommand("free", ['-o', '-h']);
  }

The code for the web status panel is available from GitHub. A couple of configuration points. Firstly, you will need to set you own IP on the server. Secondly, depending on the version of Linux you are using on the system, you may need to open up the port through the firewall software.

The ARMv7 version of Dart is available from here - select Linux from the OS dropdown if it is not shown automatically. I am finding Dart is a good environment to run on the Raspberry Pi. Small, lightweight, fast and has certainly been less bother that running Python at times.

Please leave a comment if you have created anything interesting on the Pi with Dart!