zanco
Posts: 24
Joined: Fri Dec 07, 2012 1:38 pm

Smart meter reading problems

Sat Jul 20, 2013 12:11 pm

Hi All,

I have the Raspberry Pi (model B) connected to a Smart Meter P1 output. I used a ready built cable to USB.

I run the P1uitlezer.py script but it misses a lot of data many times. This script is started once every 5 minutes. I had the script modified to not only save the data to a file P1uitlezer.txt (which is used by another script to create the rrdtools graphs) to also save a P1uitlezer(date/time string).txt to review the file contents. Some of these files contain the correct data, most of them contain too less data or double lines. I will paste two examples below.

After running in this problem I started Minicom with the right settings for the serial data and had it captured to a file. After about one hour I had collected 323 measurements with totally no error. Each measurement was complete and no errors.

What could be the reason that the P1uitlezer.py gives me wrong data (run once every 5 minutes) but the minicom collecting data pushed by the meter every 10 seconds for about one hour gives no errors ?

Thanks in advance for your advice,
Kind regards,
Ben

Good P1 file:

('DSMR P1 uitlezer', '1.0')
Control-C om te stoppen
daldag 01745
piekdag 01819
dalterug 00000
piekterug 00000
afgenomen vermogen 540 W
teruggeleverd vermogen 0 W
Gas 2067927 dm3

Bad P1 file:

('DSMR P1 uitlezer', '1.0')
Control-C om te stoppen
daldag 01745
piekdag 01819
piekterug 00000
afgenomen vermogen 420 W
teruggeleverd vermogen 0 W
daldag 01745
piekdag 01819
piekterug 00000
afgenomen vermogen 420 W

P1uitlezer.py with saving to file:

#
# DSMR P1 uitlezer
# (c) 10-2012 - GJ - gratis te kopieren en te plakken

versie = "1.0"
import sys
import serial

################
#Error display #
################
def show_error():
ft = sys.exc_info()[0]
fv = sys.exc_info()[1]
print("Fout type: %s" % ft )
print("Fout waarde: %s" % fv )
return


################################################################################################################################################
#Main program
################################################################################################################################################
print ("DSMR P1 uitlezer", versie)
print ("Control-C om te stoppen")

#Set COM port config
ser = serial.Serial()
ser.baudrate = 9600
ser.bytesize=serial.SEVENBITS
ser.parity=serial.PARITY_EVEN
ser.stopbits=serial.STOPBITS_ONE
ser.xonxoff=0
ser.rtscts=0
ser.timeout=20
ser.port="/dev/ttyUSB0"

#Open COM port
try:
ser.open()
except:
sys.exit ("Fout bij het openen van %s. Programma afgebroken." % ser.name)


#Initialize
# stack is mijn list met de 20 regeltjes.
p1_teller=0
stack=[]

while p1_teller < 20:
p1_line=''
#Read 1 line
try:
p1_raw = ser.readline()
except:
sys.exit ("Seriele poort %s kan niet gelezen worden. Programma afgebroken." % ser.name )
p1_str=str(p1_raw)
#p1_str=str(p1_raw, "utf-8")
p1_line=p1_str.strip()
stack.append(p1_line)
# als je alles wil zien moet je de volgende line uncommenten
# print (p1_line)
p1_teller = p1_teller +1

#Initialize
# stack_teller is mijn tellertje voor de 20 weer door te lopen. Waarschijnlijk mag ik die p1_teller ook gebruiken
stack_teller=0

while stack_teller < 20:
if stack[stack_teller][0:9] == "1-0:1.8.1":
print "daldag ", stack[stack_teller][10:15]
elif stack[stack_teller][0:9] == "1-0:1.8.2":
print "piekdag ", stack[stack_teller][10:15]
# Daltarief, teruggeleverd vermogen 1-0:2.8.1
elif stack[stack_teller][0:9] == "1-0:2.8.1":
print "dalterug ", stack[stack_teller][10:15]
# Piek tarief, teruggeleverd vermogen 1-0:2.8.2
elif stack[stack_teller][0:9] == "1-0:2.8.2":
print "piekterug ", stack[stack_teller][10:15]
# Huidige stroomafname: 1-0:1.7.0
elif stack[stack_teller][0:9] == "1-0:1.7.0":
print "afgenomen vermogen ", int(float(stack[stack_teller][10:17])*1000), " W"
# Huidig teruggeleverd vermogen: 1-0:1.7.0
elif stack[stack_teller][0:9] == "1-0:2.7.0":
print "teruggeleverd vermogen ", int(float(stack[stack_teller][10:17])*1000), " W"
# Gasmeter: 0-1:24.3.0
elif stack[stack_teller][0:10] == "0-1:24.3.0":
print "Gas ", int(float(stack[stack_teller+1][1:10])*1000), " dm3"
else:
pass
stack_teller = stack_teller +1

#print (stack, "\n")

#Close port and show status
try:
ser.close()
except:
sys.exit ("Oops %s. Programma afgebroken." % ser.name )

Borreltje
Posts: 31
Joined: Sat Aug 31, 2013 8:49 pm

Re: Smart meter reading problems

Wed Oct 16, 2013 7:30 am

Hi Zanco,

did you ever resolve this issue? I am having the same problem and get it to work reliable.
If you did solve this, can you post your solutions here please?

regards, Borreltje

zanco
Posts: 24
Joined: Fri Dec 07, 2012 1:38 pm

Re: Smart meter reading problems

Wed Oct 16, 2013 8:07 pm

Hi,

somehow I had the problem "solved", at least reduced to minimum holes in my graphs. Sadly after another ethernet breakdown I did reboot my Pi after which the Pi did not reboot properly. I misplaced the SD card when trying to run fsck and I actually managed to break my SD card. No recovery possible, started again from scratch.

So now I have it running but with large and lot of holes. I did change the python script to save the readout in files with date / time stamp for one day and somehow I managed to pull a conclusion out of these results. I have to think very hard what made the difference. I will update this message as soon as my brain tells me how I did fix it.

Kind regards,
Ben

zanco
Posts: 24
Joined: Fri Dec 07, 2012 1:38 pm

Re: Smart meter reading problems

Sat Oct 19, 2013 6:04 pm

I think I remember.

I suppose I did set ser.xonxoff=0 to ser.xonxoff=1

I did find two messages, one here http://stackoverflow.com/questions/1755 ... range-data and one here http://www.linuxquestions.org/questions ... 175469118/ which both had similair problems and solved it the same way.

Changed it this evening and for the last 1 hour no gaps.

Give it a try !

Kind regards,
Ben

Borreltje
Posts: 31
Joined: Sat Aug 31, 2013 8:49 pm

Re: Smart meter reading problems

Sat Oct 19, 2013 6:13 pm

Changed that setting just now, script is running, I'm gonna let it run overnight and post back first thing in the morning.

thanks for the tip.


Borreltje

Borreltje
Posts: 31
Joined: Sat Aug 31, 2013 8:49 pm

Re: Smart meter reading problems

Sun Oct 20, 2013 10:04 am

Hi, it has been running all night without a single drop-out, no more gaps in the line, thanks again for posting that solution, works great!!!


Borreltje.

Return to “Troubleshooting”