PERL vs SHELL

For more advanced meter data users. Learn from others and ask questions about how to read meters, how to use the EKM Push Data, and how to display the meter data in useful ways.
riv
Posts: 29
Joined: Mon Apr 15, 2013 3:55 am

PERL vs SHELL

Post by riv »

Spent lots of time and now completely lost. The shell script with NC works as charm, but not getting any results with PERL:
I am using iSerlal with EKM v4 meter to test

- PERL (write/read section only)

sub read_ekm {
my $peerAddr = shift(@_);
my $peerPort = shift(@_);
my $peerTimeout = shift(@_);
my $meterID = shift(@_);
my $recv_data = '';

my $sock = IO::Socket::INET->new (
PeerAddr => $peerAddr,
PeerPort => $peerPort,
Proto => 'tcp',
Timeout => $peerTimeout,
Type => SOCK_STREAM,
) or die "ERROR in Socket Creation : $!\n";

#binmode($sock);

my $tosend = '/?' . $meterID . "!\r\n";
$sock->send($tosend);
$sock->recv($recv_data,255);

close($sock);

return $recv_data;
}

- Same time "echo "/?meterID\!" | nc -w 10 -C -t peerAddr peerPort", works, sometimes it requires to run it twice to get the data, but somehow.

The perl script does not work, regardless number of times requesting for the data.

Thank you in advance.
----
V. Rublyov
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: PERL vs SHELL

Post by Jameson »

Hello Riv, thanks for posting to the forum!

This is not my forte, but I will try to help you out the best I can.

When you use PERL, are you able to see if you are getting RS485 traffic coming out of the RS485 port of the iSerial? Can you tell us if the meter is responding to your request? Does the data look good? Please send a sample sniff of your HEX request and receive.

I think we will need a bit more information about what is going on before we can give you a helpful answer. Anyone out there that is familiar with PERL, please chime in :)

It sounds like you are familiar with the RS485 protocol (I will post it here for others): http://www.ekmmetering.com/developer-portal

Let us know a bit more about what you are seeing, and we will try to go from there.

Thanks
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
riv
Posts: 29
Joined: Mon Apr 15, 2013 3:55 am

Re: PERL vs SHELL

Post by riv »

Sounds like I sorted out this issue... the problem was with the port number, just missed single "0" in the string.

Any idea is I can use Digest::CRC for CRC16 verification and generation? What parameters should be used for creating this class?

I will share the script to everyone soon, give me a couple of days for completion base part at least.

Thank you
----
V. Rublyov
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: PERL vs SHELL

Post by Jameson »

Hello Riv,

Glad to hear you got it sorted out ;)

CRC-16 is a bit tricky because we use 7 bit data with our meters (rather than 8 bit). Please check out these threads that address this issue directly:

http://forum.ekmmetering.com/viewtopic.php?f=4&t=5
http://forum.ekmmetering.com/viewtopic. ... =crc#p5245
I will share the script to everyone soon, give me a couple of days for completion base part at least.
Yes, please do! Thanks!

Best regards,
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
riv
Posts: 29
Joined: Mon Apr 15, 2013 3:55 am

Re: PERL vs SHELL

Post by riv »

Does anyone know what chars in the result string represent "Decimal Places" value?
Thanks
----
V. Rublyov
riv
Posts: 29
Joined: Mon Apr 15, 2013 3:55 am

Re: PERL vs SHELL

Post by riv »

created separate thread "PERL script"
----
V. Rublyov
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: PERL vs SHELL

Post by Jameson »

The v4 meter places the decimal place in the kWh values depending on the CT ratio. This is so you can have fine granularity with smaller CTs and bigger overall kWh values with larger CTs.

(this is for a v.4 meter only)
When you have a 200 amp CT ratio, the kWh will be displayed with 2 decimal places. For example: 999999.99 kWh In this case the RS485 return string will return 2 for "Decimal Places"
When you have a 800 amp CT ratio, the kWh will be displayed with 2 decimal places. For example: 9999999.9 kWh In this case the RS485 return string will return 1 for "Decimal Places"
When you have a 5000 amp CT ratio, the kWh will be displayed with 0 decimal places. For example: 99999999 kWh In this case the RS485 return string will return 0 for "Decimal Places"

Let us know if you have any questions.
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
riv
Posts: 29
Joined: Mon Apr 15, 2013 3:55 am

Re: PERL vs SHELL

Post by riv »

Following on it

Is value for "Decimal Places" under EKM Dash calculated or received (can be received) from the meter output string?
Which bytes and values stands for "CT Ratio"?
Did anyone had good success with EKM OmniMeter Advanced Settings Commands Protocol? Specifically for v4 meters. I am trying to reset "Max Demand" to zero, issuing following 2 commands in sequence:

["\01\x50\x31\x02\x28" . $password . "\x29\x03" . CRC16] for password verification (before set under EKM Dash)
["\x01\x57\x31\x02\x30\x30\x44\x35\x28\x30\x29\x03" . CRC16] for resetting "Max Demand" value.

No luck so far :( and of course any help is appreciated
----
V. Rublyov
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: PERL vs SHELL

Post by Jameson »

The Value "Decimal Places" is returned in the return string of a v4 meter. It is marked as ^^ in this pdf: http://documents.ekmmetering.com/Omnime ... arsing.pdf

CT Ratio is part of Response Type B (the request for this contains 30 31 after the meter number). It is in the document above.

Please take a look at the HEX Inspector portion of the EKM Dash. It is a tool that is there to teach you how to make settings and how to parse the data. Go to Help > Hex Inspector. Select your meter, then make settings changes to the meter, like set the CT Ratio, or Reset the Max Demand. You can then see the RS485 serial traffic that is generated and received by the EKM Dash to make these settings.

You will need to make a meter setting in this sequence:

Send Full Meter Request
Receive Meter Response
Send Password
Receive Meter Responds OK
Send Make Setting (in your case to set Max Demand to zero use: 01 57 31 02 30 30 34 30 28 30 30 30 30 30 30 29 03 01 2b)
Receive Meter Responds OK
Send Close String

Thanks,
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
riv
Posts: 29
Joined: Mon Apr 15, 2013 3:55 am

Re: PERL vs SHELL

Post by riv »

Thank you. Was able to get that data with help of HEX inspector.

Can you please describe date/time format, encoded into "14 Bytes Time"?

Thanks
----
V. Rublyov
Post Reply