or smart electricity meter if you prefer English..

It is the meter that will get installed in every dutch home in the near future, and because my meter got swapped the other day, I already own one. It looks like this:


They call it smart because it is able to send its readouts to the electricity company by GSM/GPRS.. smart heh?

It can show 4 readouts on its display, peak/off-peak usage kWh and peak/off-peak production (if you own solar panels).. it knows the current watts you are using.. but does not show that on the display… very ‘smart’.

I want this data, and I don’t want it on the display, I want it on my computer… in JSON preferably, so I can make a nice webpage showing the currently used watts. The ‘smart’ meter does not have a network port, but it does have a what they call P1 port.

The P1 port is RJ11 connector on which you can get a serial signal of the readings (if you supply a certain pin with 5V), this serial signal is inverted, so to get it right you need a 74HC04 to invert it.
To interface between this serial and the network, I will use a Netduino plus 1 that I had laying around. Soldered the 7404 on a shield, and added an USB cable so my cable modem can power all this. It looks like this:


By opening this serial port on the Netduino

[csharp]_serialP1 = new SerialPort(SerialPorts.COM2, 9600, Parity.Even, 7, StopBits.One);
_serialP1.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);[/csharp]

you will start to receive this kind of messages:



Using this code on the Netduino, I ‘decode’ the P1 message into variables in my program:

[code language=”csharp”] private static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
if (_serialP1.CanRead && _serialP1.BytesToRead > 0)
byte[] bytes = new byte[_serialP1.BytesToRead];
_serialP1.Read(bytes, 0, bytes.Length);

foreach (var b in bytes)
var c = (char)b;
_msg += c;
if (c == ‘!’)
_msgComplete = true;

if (_msgComplete && _msg.Length > 0)

_currentUsagekW = getFromMessage(_msg, "1-0:1.7.0");
_currentProductionkW = getFromMessage(_msg, "1-0:2.7.0");

_usageHighkWh = getFromMessage(_msg, "1-0:1.8.1");
_usageLowkWh = getFromMessage(_msg, "1-0:1.8.2");

_productionHighkWh = getFromMessage(_msg, "1-0:2.8.1");
_productionLowkWh = getFromMessage(_msg, "1-0:2.8.2");

_msg = string.Empty;
_msgComplete = false;

catch (Exception)
Debug.Print("Serial receive fail!!");

public static string getFromMessage(string message, string key)
var test = "Error";
int startIndex = message.IndexOf(key);
test = message.Substring(startIndex + key.Length + 1,
message.IndexOf("*kW", startIndex) – startIndex – key.Length – 1);
return test;


Next is to open up a Socket and listen for requests on it:

[csharp] public static void ListenForRequest()
while (true)
using (Socket clientSocket = _socket.Accept())
while (!clientSocket.Poll(10, SelectMode.SelectRead)) ;

int bytesReceived = clientSocket.Available;
if (bytesReceived > 0)
Debug.Print("resrquest received");
//Get request
byte[] buffer = new byte[bytesReceived];
int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);
string request = new string(Encoding.UTF8.GetChars(buffer));
//Compose a response
var sb = new StringBuilder();
sb.AppendLine("\"usageHighkWh\":\"" + _usageHighkWh + "\",");
sb.AppendLine("\"usageLowkWh\":\"" + _usageLowkWh +"\",");
sb.AppendLine("\"productionHighkWh\":\"" + _productionHighkWh + "\",");
sb.AppendLine("\"productionLowkWh\":\"" + _productionLowkWh + "\",");
sb.AppendLine("\"currentUsagekW\":\"" + _currentUsagekW + "\",");
sb.AppendLine("\"currentProductionkW\":\"" + _currentProductionkW + "\"" );

string response = sb.ToString();
string header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n";
clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);
clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);
catch (Exception)
Debug.Print("This may fail somtimes for unknown reasons.. large amount of req/s for instance");

And now a request in the browser to the netduino’s IP will get you this:


Your meter’s readings in a JSON format.

Next up will be posting this data to Azure storage tables.. stay tuned for part II.

Flores Eken

Author Flores Eken

I’m passionate about technology in general and particularly about software development and automation. Specializing in Infrastructure automation and Microsoft .NET, I can handle the entire process, from installing a Team Foundation Server to the smallest programming detail. Always innovating and on the cutting edge.

More posts by Flores Eken
21 April 2014

Leave a Reply