Processing the smart meter data (3)

Well, 2 days later and I’m getting somewhere 🙂

First of all, I must have been drunk when I said the Simplecortex was sending its data with an interval of 200 ms – no, that’s the timer resolution of my logger! The simplecortex sends a packet each time a newline (or line feed, LF) is received from the P1 port. So that’s solved.

First thing on the todo list was parsing the P1 data and extracting the numbers I want to receive in my system:

#define P1PU1  "1-0:1.8.1"      // total power usage normal tariff
#define P1PU2  "1-0:1.8.2"      // total power usage low tariff
#define P1PD1  "1-0:2.8.1"	// total delivered power normal tariff
#define P1PD2  "1-0:2.8.2"	// total delivered power low tariff
#define P1TIP  "0-0:96.14.0"    // tariff indicator power
#define P1PUC  "1-0:1.7.0"	// current power usage
#define P1PDC  "1-0:2.7.0"	// current power delivery
#define P1GTS  "0-1:24.3.0"	// timestamp gas usage sample

A routine was made to check each received line for the occurrence of the above-mentioned OBIS references (identification codes for data in DLMS/COSEM compliant metering equipment), get the value out of the received line and store the result in a buffer:

...
else if(strncmp(P1PU1, line, 9) == 0)
{
  strncpy(value, line+10, 9);
  value[9]=0;
  sendbuf("powertotalN;", value);
}
...

… and another routine that’s being called whenever the application is allowed (by the uIP TCP/IP stack) to send the data over to the other side of the connection. And this is another intermediate result, received by my domotica system:

22:41:54.406  TCP < powertotalN;00003.725
22:41:54.406  TCP < powertotalL;00000.000
22:41:54.406  TCP < powerdelivN;00000.000
22:41:54.406  TCP < powerdelivL;00000.000
22:41:54.406  TCP < powertariff;0001
22:41:54.506  TCP < powercurrent;0000.96
22:41:54.506  TCP < delivcurrent;0000.00
22:41:54.707  TCP < gastimestamp;120808010000
22:41:54.707  TCP < gasusage;00000000
22:42:04.722  TCP < powertotalN;00003.728
22:42:04.722  TCP < powertotalL;00000.000
22:42:04.842  TCP < powerdelivN;00000.000
22:42:04.842  TCP < powerdelivL;00000.000
22:42:04.842  TCP < powertariff;0001
22:42:04.842  TCP < powercurrent;0000.97
22:42:04.842  TCP < delivcurrent;0000.00
22:42:05.043  TCP < gastimestamp;120808010000
22:42:05.243  TCP < gasusage;00000000

That’s much better than what I had 2 days ago; well 4 hours ago actually, cause time is limited and I’m also learning more and more about C while working on this.

Next step: sending this data as payload in a MQTT Publish message! The protocol is not so hard in its simplest form and I’ve got working Delphi MQTT code, so this should not be a problem.

In the meantime some parts have arrived: an enclosure for the simplecortex, 7404 hex inverters and transistors to invert the P1 signal.

Onwards!

Tagged , . Bookmark the permalink.

4 Responses to Processing the smart meter data (3)

  1. Mark says:

    Ha Robert,

    Welke enclosure heb je besteld?

    Groet,

    Mark

  2. willem says:

    Je kan ook een opto-coupler te gebruiken, dat zit in principe ook aan de kant van de meter (open collector) dan is het signaal weer ongedraaid en heb je een gescheiden circuit. Eens kijken of ik er nog een heb liggen …..

Leave a Reply

Your email address will not be published. Required fields are marked *