The E-files - Part 1 - Introduction
Here in the Netherlands, most houses are (or soon will be) equiped with a smart meter for recording gas and electricity consumption. These meters come with some ‘smart’ ports that enable transmitting the energy consumption data to the utilities suppliers. Of couse, we want to have this data for ourselves as well. Why? Because We Can! Fortunately, one of the (physically) available ports is the P1 port through which it is possible to read data from the meter. The port has a RJ-11 connector and works with a standard serial protocol (IEC-62056-21 more precisely). All kinds of projects can be found on the web to build your own equipment to read the data coming out of this port. I choose the easy way out and just ordered me a ready-to-use cable with a RJ-11 connecter on one side and a USB connector on the other side (available online for about $20,-). The USB side contains some electronics like a pull-up resistor and inverter logics. To be able to do anything useful with the cable and the data, you of course need to atttach some kind of computer to the USB side. A cheap and easy option for that is to use a Raspberry Pi and that is exactly what I did. The end result looks like this (the blue circle indicates where the RJ-11 port is):
Right above the blue circle in the picture there are two interesting terms printed: DSMR 4.0 and GPRS. The latter indicates on how the data is being transmitted to the utilities company - wirelessly with GPRS. The first is the name and version of the standard that describes the end-consumer (that's us!) P1 interface and stands for 'Dutch Smart Meter Requirements'. This standard has extensive documentation (latest version) and was very useful in making sense of the data.
So, we have a smart meter wired up to a Raspberry Pi sending data in a well described protocol. Now what?
When I started looking at ways to read the data, I quickly found a lot of existing resources out there already. A lot of them were also using a Raspberry Pi for reading the data and most either used a Perl, Python or PHP (I even found a Ragel based C parser, ugh!) program for processing and MySql or PostgreSQL database for storage. As a Azure/.NET person, I could not settle for that of course, so I set upon a journey to write a C# program running on the Pi to read and parse the data and store it in a database running on Azure (which one exactly was still undecided).
Preping the Pi
The easiest way to get .NET running on the Pi would probably be to get it to run Windows IoT Core. Unfortunately, it seems that development of the Raspberry Pi compatible version of this OS has come to a standstill and you need a very specific Technical Preview build for my specific Pi model (3B+). For me this did not end with a smooth running Raspberry Pi, so this was a no-go option. (There were some announcements around Windows IoT at Build, so we might get this working better in the future) Fortunately, since .NET core, we are capable of running .NET everywhere, so it can run on Linux and therefore by extension can run on a standard configured Raspberry Pi running Raspbian.
The .NET site (https://dotnet.microsoft.com/) has specific instructions for installing on Linux but it is not really clear on how to install exactly on Raspbian (the Raspberry Linux Debian 10 flavor) because the docs on the Linux page only describe the automated installation on a 64 bit environment. For the 32 bits version you need to install manually. For me the best way to get up-and-running was to use the steps described under the heading 'Install with bash automation' and then following the steps described in the 'Tip' section above on the same page (add the path to the ~/.bash_profile file). The end result:
That's it for the introduction. In the next part I'll dive deeper into the program to get the data out of the meter. Let me know what you think in the comments below.
Comments are closed