Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_single_value #13

Closed
dawidce opened this issue Jun 17, 2020 · 5 comments
Closed

read_single_value #13

dawidce opened this issue Jun 17, 2020 · 5 comments

Comments

@dawidce
Copy link

dawidce commented Jun 17, 2020

Hi
i cant read single value from meter.
Function read_standard_readout works but i get huge amount of data.
i would like to get only one value eq. (1.8.0)

my code:
`#!/usr/bin/python3

from iec62056_21.client import Iec6205621Client
import logging

logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s,%(msecs)d %(levelname)s: %(message)s",
datefmt="%H:%M:%S",
)

client = Iec6205621Client.with_tcp_transport(address=('192.168.200.123', 2222), device_address='035 0000101', password='00000000')
client.connect()
password_challange = client.access_programming_mode()
client.send_password('00000000') # Common standard password
data_answer = client.read_value('1.8.0')
print(data_answer)`

output:
20:30:10,157 DEBUG: Connecting to ('192.168.200.123', 2222) 20:30:10,157 INFO: Staring init sequence 20:30:10,157 INFO: Sending request message: RequestMessage(device_address='035 0000101') 20:30:10,158 DEBUG: Sent b'/?035 0000101!\r\n' over transport: TcpTransport 20:30:10,158 DEBUG: Resting for 0.25 seconds 20:30:11,294 DEBUG: Received b'/POZ4LP1-VP02.04*\r\n' over transport: TcpTransport 20:30:11,294 INFO: Received identification message: IdentificationMessage(identification='P1-VP02.04*', manufacturer='POZ', switchover_baudrate_char='4') 20:30:11,295 INFO: Sending AckOptionsSelect message: AckOptionSelectMessage(baud_char='4', mode_char='1') 20:30:11,295 DEBUG: Sent b'\x06041\r\n' over transport: TcpTransport 20:30:11,295 DEBUG: Resting for 0.25 seconds 20:30:11,546 DEBUG: Received b'\x01P0\x02(0000)\x03' over transport: TcpTransport
Traceback (most recent call last):
File "./iec_net.py", line 26, in
client.send_password('00000000') # Common standard password
File "/home/pi/.local/lib/python3.7/site-packages/iec62056_21/client.py", line 193, in send_password
data_set = messages.DataSet(value=_pw)
TypeError: init() missing 1 required positional argument: 'address'
`

@dawidce
Copy link
Author

dawidce commented Jun 17, 2020

Or maybe it's easier to parse response from read_standard_readout function and find data ?

@Krolken
Copy link
Contributor

Krolken commented Jun 18, 2020

I use different strategies depending on how much the data costs. If cost and bandwidth isn't a problem I just do standard readout since I don't have to change much afterwards. Lots of MNOs also charge you in incremental steps for each session. So if you pay at least for 1 kB for every session you might as well read all of it.
If I am able I adjust the standard readout (can be done usually by the manufacturers software), I try to do that to get the data I need.
And if I just only need the one data or data not available in standard readout I do single read.

Seems like you are using the LP-1 with Wifi? So I would just read the standard readout.
But if you have time please try out the single read to find if it works properly on the device. I am trying to find a better API to use the different password mechnisms, but it seems very device specific sometimes so it might be better handles elsewhere.

@dawidce
Copy link
Author

dawidce commented Jun 20, 2020

im using LP-1 with Ethernet. How should i parse standard readout to get single data (1.8.0?) what kind of type is AnswerDataMessage ?

@Krolken
Copy link
Contributor

Krolken commented Jun 20, 2020

Simplest thing would be to use the data property of AnswerDataMessage. The data structure of AnswerDataMessage consists if DataBlock that consists of DataLines that consists of DataSets. It is just to conform to the standard and make it easy to parse the data coming from the meter, but the interesting is the list of DataSets that actually hold the data.

data_list: List[DataSet] = answer_data_msg.data

Data sets consists of address, value and unit. See

class DataSet(Iec6205621Data):

So if you only need one element search the list for it and if you think you need more values you can for example create a mapping using dict with the address as key and then just look up by address.

@Krolken
Copy link
Contributor

Krolken commented Jul 3, 2020

Closing this since it seems done. If there is anything else just open it again.

@Krolken Krolken closed this as completed Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants