Monday, March 2, 2015

DSMR4 P1 reader with PL2303 from Windows PC and c# WinForm

For those out there who are NOT connecting with a Raspberry Pi and bought the 'cheap' PL2303 cable before they realised they were in trouble with the inverted signal on the DSMR4 smart meters, here is my experience from what I learned getting this to work, which is slightly different than has been posted already :-
http://www.domoticz.com/forum/viewtopic.php?f=14&t=4970
http://www.iproto.nl/post/37?title=P1+poort+%5C%26quot%3Bslimme%5C%26quot%3B+meter+uitlezen
http://www.maartendamen.com/2012/04/new-smart-meter-installed-iskra-me382-and-landis-gyr-gasmeter-e06140/
https://www.sossolutions.nl/gpio-accessoires/9324365-usb-naar-ttl-serieel-kabel.html

So many thanks to the above sources, they pretty much had everything I needed among them.

My first thoughts in this process was to buy a cable from http://www.smartmeterdashboard.nl/,
but instead I thought it might be fun to try and do this myself as a mini project. So before I did the proper research I ordered a PL2303 chipset USB to ttl serial, as it was going to keep me under the 22.50 budget level of smartmeterdashboard.

Next day delivery, I had my cable ready to hook up to the rj11 4 wire cable i had already prepared and plugged in to the meter 5 meters away through the floor of my office.

+5V connected, from Red wire on PL2303 USB to RJ11 BLACK (it seems they mix the red black to confuse us electrical numbties).
Black of USB to Red of RJ11 (the P1 port of the meter).
White Rx to Yellow of RJ11 (the P1 port of the meter).
Green, for now, not required, as we are not going to be sending anything to the meter, just reading.

At this stage I knocked up a quick visual studio WinForms project in C#, dropped a serial control to the form, set it to 115200/8N1, text box output on the data received event (.Read(byte[] buffer,0,length) then AppendText(System.Text.Encoding.Default.GetString(buffer)).

High expectations turned to disappointment, with no readings coming through, nothing at all. So back to researching, and came across the above sites detailing the differences with the DSMR4 meters, oops.
At first I thought I could get away with the 'pull up' resistor bridged from the +Ve and software manipulate the inversion. The following is my received buffer printed out by byte bit pattern separated by : the ascii char code, inverted code (unmasked at this stage to remove bit 8)
01000000:64:-65
00000000:0:-1
00111000:56:-57
00000000:0:-1
01000110:70:-71
01100000:96:-97
01110010:114:-115
01110010:114:-115
01100010:98:-99
01100010:98:-99
01110010:114:-115
00010010:18:-19
00011110:30:-31
00011110:30:-31
00011110:30:-31
00011110:30:-31
00000110:6:-7
00000110:6:-7
00010010:18:-19
00010010:18:-19
11000000:192:-193
11000010:194:-195
11000000:192:-193
11000010:194:-195
00000000:0:-1
01000110:70:-71
01000000:64:-65
01000100:68:-69
00100000:32:-33
00100100:36:-37

OK, so reverse engineering the UART protocol start & stop bits was not the fun I had intended, so more researching.
A transistor to hardware invert the signal is stretching my electronics capability, and I didn't want to order a single BS170, and I didn't have these Arduino boards, or any other type, to connect it to.
http://www.kabeldirect.nl/aten-uc-232a-usb-rs232-seriele-verloopkabel.html, would of made it easier for myself in the first place I guess.
Maybe time to buy that cable from smartmeterdashboard?
Overnight thoughts led me to cannibalise  an old pentium that had been gathering dust in the attic that the previous owner left up there. Searching for possible transistors on the circuit boards.
Googling a 2n3904 part number of similar looking items on an audio io board led me to other articles that electronic savvy people were posting about in relation to PL2303 and signal inversion for TTL.

So hooking up the left leg of this item to the +ve after the resistor, middle leg to the RJ11 inbound data (I moved the data (yellow RJ11 from P1 port) from being connected to the +ve)  and the right leg to the ground wires.
Nothing...again.
After a bit of head scratching and poking my wiring to make sure everything was connected correctly and soldered still I had a minor 'accident' of touching the transmit Green wire of the USB adapter to the middle leg of the transistor where the Data stream was attached while everything was connected up. All of a sudden my text box starts to fill with data, in a nice looking structured format!
What I realised later was that I had taken the 'pull up' power away from the data leg, and the USB green wire was carrying 3.3v from the spec sheet, which replaced the required power that I was missing. My lack of electronics knowledge would not of made this jump of revelation without the 'accident' as I had already connected one leg to the +ve and the other to ground, so 'completing' the circuit for my view.
Here is my reading!

/XMX5LGBBFFB200004422

1-3:0.2.8(40)
0-0:1.0.0(150302104808W)
0-0:96.1.1(4530303035303031343933343131333133)
1-0:1.8.1(001119.327*kWh)
1-0:2.8.1(000000.000*kWh)
1-0:1.8.2(001577.942*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.144*kW)
1-0:2.7.0(00.000*kW)
0-0:17.0.0(999.9*kW)
0-0:96.3.10(1)
0-0:96.7.21(00002)
0-0:96.7.9(00000)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:52.32.0(00000)
1-0:72.32.0(00000)
1-0:32.36.0(00000)
1-0:52.36.0(00000)
1-0:72.36.0(00000)
0-0:96.13.1()
0-0:96.13.0()
1-0:31.7.0(001*A)
1-0:51.7.0(000*A)
1-0:71.7.0(000*A)
1-0:21.7.0(00.082*kW)
1-0:41.7.0(00.046*kW)
1-0:61.7.0(00.015*kW)
1-0:22.7.0(00.000*kW)
1-0:42.7.0(00.000*kW)
1-0:62.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303137353931323038323037313134)
0-1:24.2.1(150302100000W)(01045.614*m3)
0-1:24.4.0(1)
!A395 

and my out of focus wiring :-)

Now to the fun part of parsing the data and making some graphics in my own particular way :-)

Hope this helps someone else out there in addition to the posts out there already.


 




No comments:

Post a Comment