Send Decimals with RFM

Hi all,

I'm using the 3 phase sketch on Emontx v3.4 and I'm interested in exact values (2 decimals) of the Power factor and exact values of the current (1 decimal).

The serial print shows the right decimals but de RF module sends only integers. I can send the data by multiplying the data by 10 or 100 to get a higher accuracy, but that has to be post processed. So not preferable. 

Is there a way to include decimals in the data package of rfm?

 

 

Beire's picture

Re: Send Decimals with RFM

In the payload structure, try to change the type from "int" to "float".

I have some values set up this way, and they work. You probably need to edit your emonhub config also.

pb66's picture

Re: Send Decimals with RFM

You can use floats rather than ints in your payload structure as Biere suggests or scale as you have already mentioned, either will require "post-processing" the difference being firstly the size, range and accuracy of the value, a float is 4 bytes and has a massive range but it's accuracy is questionable (not likely to be a problem here), a scaled signed int still only uses 2 bytes (so halve the size) with a range of -32767 to 32768 before scaling (so -327.67 to 327.68 at 2 digits of precision) with no question over accuracy.

Using scaling has the added advantage of being transmitted and passed to emoncms with no additional processing until it arrives in enmoncms, where as using the datacodes and/or scaling in emonhub means the real values are available sooner before posting to emoncms or elsewhere .

It was for this reason emonhub has the ability to scale and use other data types, previously the stream of bytes was always post-processed from 2byte pairs as unsigned ints without any variation, now the default use of integers is just a backward compatibility legacy.

Paul

Bart's picture

Re: Send Decimals with RFM

Both thanks!

I have multiplied the values in my sketch and scaled it emoncms.

It seemed to me cumbersome, but in the case of the maximum number of bytes it is better to use scales. I use for ct1-4 the power, apparentPower, powerFactor and the current, so it must be 2 bytes otherwise the maximum package of the RFM will be exceeded.

Sketch adjustment:

  emontx.Irms1 = Irms1 * 10;
  emontx.Irms2 = Irms2 * 10;
  emontx.Irms3 = Irms3 * 10;
  emontx.Irms4 = Irms4 * 10;
  emontx.powerFactor1 = powerFactor1 * 100;
  emontx.powerFactor2 = powerFactor2 * 100;
  emontx.powerFactor3 = powerFactor3 * 100;
  emontx.powerFactor4 = powerFactor4 * 100;

Emonhub.conf node decoder:

[[11]]
nodename = emonTx_three_phase
firmware =three_phase
hardware = emonTx_(NodeID_DIP_Switch1:OFF)
[[[rx]]]
names = power1, apparentPower1, powerFactor1, Irms1, power2, apparentPower2, powerFactor2, Irms2, power3, apparentPower3, powerFactor3, Irms3, power4, apparentPower4, powerFactor4, Irms4, Vrms
datacode = h
scales = 1,1,0.01,0.1,1,1,0.01,0.1,1,1,0.01,0.1,1,1,0.01,0.1,1
units =W,W,PF,A,W,W,PF,A,W,W,PF,A,W,W,PF,A,V

 

pb66's picture

Re: Send Decimals with RFM

Shouldn't Vrms be scaled by 0.01 in emonhub.conf too? otherwise the units should be mV or does your sketch only report whole Volts?

As a side note, if payload size is a concern, and the power factor is always within the -1,27 to 1.28 or the 0 to 2.55 ranges (I know it should be, but do not know the extremes the sketch could report) you could use a single signed or unsigned byte/char (b or B) saving an additional 4 bytes of payload.

Paul

Bart's picture

Re: Send Decimals with RFM

First of all thanks for thinking along

About Vrms it can, but accuracy isn't that interesting for me. I'm going to monitor milking systems of dairy farms and I am now setting up the first Emontx (will be 6 in future). I want to compare different farms and find why there is a big difference in usage. Probably due to efficiency of the systems. The integers will show me that there is a voltage drop, what will be only significant when it's more than a number of volts.

I'm not that familiar with programming, so I don't know what to change to save another 4 bytes as you mentioned with changing b or B.

 

 

Robert Wall's picture

Re: Send Decimals with RFM

Power factor should never be greater than 1, however due to rounding errors in the maths, it can be slightly greater. If power is being returned to the supply, it can be negative. What Paul was saying is, if you define the power factor in the Payload as "char powerFactor1", ('char' is a signed byte) then having calculated the value, you fill the payload with
"emontx.powerFactor1 = powerFactor1 * 100;"
then you'll get a number that you can divide by 100 in emonHub to give the correct value (truncated to 2 decimal places) as before, but it occupies only 1 byte in the Payload. Use datacode 'b' in emonHub for each of the power factor values. i.e., you'll need:

datacodes = h, h, b, h,   h, h, b, h,   h, h, b, h,   h, h, b, h,   h

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.