Maybe someone would have an explaination of a strange behaviour for processing a raw dump

feeling a little better from the flu so i thought I give processing raw dump. it mostly works wellish. some benefits so far. is I can get sample from all analog port (8) every ~1/2 second . where as doing it the normal way the more ports you have the longer the wait time would become …

but the strange behaviour, and I can not figure out why it does it… when I run the program…for some reason when usage is at zero it sits at 2.6 amps… and it seams maintain this until I pass the 2.6 amps threshold for usage. then once it passes that for usage - it works fine .

I wrote a small program that look at the raw data and extract only the peek and valley. it sits at almost a constant when at zero usage and and as you increase usage the variation increases as expected

here my code for just one analog pin

 #!/usr/bin/perl -w -s

system("stty -F /dev/ttyS18 115200 cs8 raw");

open INFILE, "/dev/ttyS18"
or die "\nCannot open the device!\n";

@data = ();
$buf = "";
$cnt = 0;
 $started = 0;
 $st= 0;
 $ICAL=60.606;
 $offsetI = (1023>>1); 

 # looks at udp stream  thats linked to a virtual port to find the start bit of 0xaa and extracts the whole key
 sub processPacket($);

 while (read(INFILE, $buf, 1)) {
   $d = ord($buf)  ;
  if ($d == 0xaa && $started == 0) {
 $started = 1;
 $a = 0;
  }
  if ($started == 1) {
  $data[$a] = $d;
  $sum += $data[$a];
  #   printf("0x%02X ", $data[$a]);

 $a++;
 if ($a >= 17) {
  # $sum -= $data[16];
 # $sum &= 0xff;
  $sum = 0;
  if ($sum == 0) { processPacket($data); }
  $started=1;
   $a = 0;
   # print "\n";
 }
 }
   }

   # Working sub process packet  converts the bits back to usable info
   sub processPacket($) {
   local($data) = @_;
 
  $A0 = ($data[1]<<8) + $data[2];
  $A1 = ($data[3]<<8) + $data[4];
  $A2 = ($data[5]<<8) + $data[6];
  $A3 = ($data[7]<<8) + $data[8];
  $A4 = ($data[9]<<8) + $data[10];
  $A5 = ($data[11]<<8) + $data[12];
  $A6 = ($data[13]<<8) + $data[14];
  $A7 = ($data[15]<<8) + $data[16];

  # print "$A0,$A1,$A2,$A3,$A4.$A5,$A6,$A7\n";

 {
 $sampleI = ($A0);


$offsetI = ($offsetI + ($sampleI-$offsetI)/1024);
$filteredI = $sampleI - $offsetI;

$sqI = $filteredI * $filteredI;

 $sumI += $sqI;
 }

 $cnt1++;
  if ($cnt1==2000){
 $I_RATIO = $ICAL *((5000/1000.0) / (1024));
 $Irms = $I_RATIO * sqrt($sumI / 2000);
 $sumI = 0;
 $cnt1=0;
 print " amps $Irms\n";
 }
 }
close INFILE; 

so curiously would anyone have explanation for the strange behaviour and perhaps a suggestion on how to correct it … my brain just not working yet

okay i thought I upload a couple screen shots of it out put this on is of one that calculates the volts and and current _ maybe it would help someone understand my issue better
~zero amperage


~5.3 amps

~11.7 amps

realpower seams to be relatively accurate.( with in the norms of emontxshield. just apparent power is way off and it also detecting the direction of the current as well

there alot of voltage drop due the fact I stripped an light extension cord to connect my CTs

but this also got me thinking was apparent and amps always so off. and maybe I never notice as I never used it… realpower out put of this raw UDP Stream is almost the exactly the same as my normal emontx device …

oh well if someone wants a copy of it current & volt to make it work across all analog channels you just need to add them

test2ab.pl.zip (1.5 KB)

the biggest advantage I guess doing it this way is you get a snapshot of all analog inputs every ~1/2 second. and you can setup a electrical load balancing circuit of some form if you wanted or needed