I am a big fan of eco-friendly stuff and activities. I bike to work, I have a green garden on my rooftop, and I also have a 250-watt solar panel. This post is about how I built a crazy monitoring system for it with an old Android phone and an OutSystems app!
250-watt is not a big deal, but it is enough to handle most of my power needs during the day — a sunny day means that I get the refrigerator, the stereo, and the laptop running for free since I don’t have to buy power from the electrical company. All thanks to the panel and the grid-tie inverter that connects to a standard wall outlet. Because of that connection, I bought a power consumption meter to measure the production.
How can I build a monitoring system out of this? I thought of:
- A phone taking pictures of the display of the meter every minute or so
- The phone somehow recognizing what number was in the picture
- The phone sending that number to a monitoring app in the cloud
- A cool monitoring app for me to monitor production
- Fun and profit (mostly fun, because I get to build everything)
So, this adventure started when my niece abandoned her old Android phone. The next step was figuring out how the phone would recognize the digits after taking a picture. I could have looked for an optical character recognition (OCR) library to do the work, but instead, I did it the fun way.
I put red duct tape on the edges of the display, lining it up with the digits so that it would be easier to spot where the digits are—with a very simple image processing routine running in the phone.
So, based on this setup, I implemented a basic image processing algorithm and some RGB to luminance conversions. After a few tries to get it up and running, it began accurately reading the number that was on the display.
Of course, for this to work, the phone needed to be motionless and in front of the meter. Here’s how I addressed that challenge.
So about the “bomb like” setup around the phone: on the top right is a charger that is controlled by a timer, which turns it on for just 30 minutes every day. Below is a Powerline WiFi adapter, controlled by another timer that sets it on only during a few hours of the day. The piece of wood was a leftover from another project; I used 2 Japanese sticks, zip ties, plus a few metal and plastic brackets to hold the phone. For the curious, the handwritten number on the wood is the wireless adapter key.
Now that I had the phone positioned, I built a native Android App. It uses an AlarmManager to wake up the phone every 2 minutes, take a picture with flash and macro, do the “duct tape” OCR, save the results in the SD card, and if there’s network available, send them to a REST API. Solar panels only work with sunlight, so I used this library to calculate sunrise and sunset in my location to make the monitoring work during daylight time.
Here’s what the phone keeps doing during the day:
The boring life of this phone: Wake up, take picture, duct tape OCR, save and send results, go back to sleep…
The app exposes a REST API to which the phone sends the readings. These readings are stored in a database, to be displayed in a front-end web responsive app. This also features an integration with OpenWeatherMap API to plot a chart with temperatures in my area. It is known that solar panel output decreases with heat, and with this integration I can visually confirm that.
On top of this, I added functionality that compares multiple days.
The dashboard also enables me to compare multiple days — here’s a summer day (red) vs. an autumn day (blue)
I live in the northern hemisphere, and I oriented the solar panel south, but unfortunately, I had to orient it a bit to the west. That explains why, in the chart, there is not much difference in the morning, as opposed to the afternoon, where we can clearly see that the daylight time in August is longer than in October.
Could I do this another way? Sure, I could have an Arduino doing all work. I could use other kinds of technology, but that would not have been as fun and rewarding as this was.