Designing something that is functional and future proof turned out to be quite a daunting task. Looking at the feature set that I wanted to implement in wattmon, it became clear that a powerful microcontroller needed to be used. The pic32mx795 is a great little 32 bit mcu with 512k of onboard flash and 128k of ram. At the beginning of the project this seemed like a lot! My experience so far has taught me that with a bit of thought you can make this go a long way. Wattmon uses FreeRTOS threads to coordinate the various os tasks, from network stack to script parsing and cron scheduling. The os makes extensive use of scheduled tasks and limits the number of concurrently executing process to ensure that memory doesn't run out. The task scheduler uses a crontab style format with an additional field making it possible to run things up to once a second.
Description of the firmware part 1
All executable scripts are written in uPHP (micro PHP) which is a name I came up with since the language is based completely on the PHP syntax. At system boot a startup script can be set to execute, which could either run in an infinite loop or be used to initialise system variables. Every script has access to the $_GLOBALS array and can use this as a rudimentary inter process communication method. Scripts that run from within a web page with .cgi extension have an additional set of variables accessible to them: $_GET, $_POST, $_SESSION. These are identical to PHPs arrays and let you access the parameters to the script. The session array is preserved through uses of a cookie sent back to the browser, making it possible to implement an access control mechanism with a user login page.
The uPHP function library implements a subset of the actual functionality of PHP but functions that are implemented are identical in functionality and syntax. These are entirely written from scratch and are not in any way based on the PHP source code. Since most of the language anyway uses lower level C calls this was relatively easy to implement.
More to come...