The Blog

Description of the firmware part 1

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.

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...
Comment (0) Hits: 2584

Why Wattmon?

In this article I will try and explain how this little device came into being.

I have always been fascinated by numbers and measurement, including but not limited to time, humidity, temperature, and so on.  As a programmer I work with numbers a lot anyway, but in 2009 I started work on an ebike battery monitor which coulomb counts both generation and load. It works pretty well and gives me a fair idea of what is left and for our users the best part is that it took out the guesswork making a vehicle with limited range a useful reliable one nonetheless. This is what I want to achieve with Wattmon as well.
Where I live, power cuts are part of every day life.  Most people have a battery and inverter to bridge the gaps in supply for some if not all loads in a house or office. But, information on battery state is mostly unavailable. So people either underutilize or overextend their batteries which of course shortens their lifespan.  In addition to grid charging, more and more people are hooking up solar panels or micro wind turbines to supply power to their batteries.
Definitely, monitoring all these inputs and loads greatly improves one's understanding and ability to manage energy better. But in addition, intelligent decisions based on the state of the battery and inputs can save money. For example, in a hybrid setup with a set of solar panels, grid charger and inverter, I may need to top up batteries once in a while but my loads could run mainly on solar.  Wattmon can be programmed to switch on or off the charger based on certain preset conditions.
In another example, imagine you have an off grid system that runs a few lights and a solar fridge. On a cloudy day the batteries may not be charged, and the available amp hours in the battery would be less than normal. Wattwon could be set to switch off your fridge relay in case the battery drops below 70% thus ensuring that your lights and other essential loads stay on. You could even switch multiple devices on or off around the house based on such events, or on time.
This total flexibility and feature set is what I kept as my goal while extensively researching existing products on the market, and it turns out that I couldn't find anything like it. Software solutions exist but require a pc for data logging. The raspberry PI came out just before I started development and is of course a fantastic solution but still aimed more at hackers than end users. So, I decided to use the microchip pic32 which is pretty powerful but limited in memory and flash. Together with an interpreted language running off an sd card this solution provides the ultimate flexibility. The language and core os run off the internal flash while the entire application runs off the sd card. I will explain the workings of the system in greater detail in a future post.
I hope this helps you better understand my reasons for spending such a lot of time on such a little box :)
Comment (1) Hits: 3033

Recent comments

  • I like researching on the batteries and other electrical things which we use in our daily life. This article is very much related to me and my hobbies. Its really an informative post and I would say just keep sharing.
View other comments

My First Blog Post!

I'm excited to announce that this is the first blog post on this website about Wattmon!  In this blog, I will try and always give you an interesting read.  Depending on how much time I can muster up, I will also try and post something regularly.  I also look forward to your comments at the bottom of each blog post.

Comment (0) Hits: 2826