Node returning strange values from watermeter [solved]

Started by Memnon, November 11, 2015, 05:43:33 AM

Memnon

Hi

I set up the water meter as watt meter, i changed the unit in metrics script file and the PULSESPERGALLON and its returning numbers with lots of decimals. How can i just have it report numbers with no decimals?





Many thanks
DJ

Felix

Well can you give us all the details of what you changed and what you're sending from the node side? (ie what the message looks like)

Memnon

Here is the only thing I have changed. Everything else is the same as the orginal pulsemeter sketch. And in the metrics script i changed only the unit from gal to kw as this is for powermeter.
I also want the moteino web interface to show kw per hour, not gal pr min. And same for gal last min. I want it to show kw last hour.
So far the power meter only shows the total kw used correctly.

//WaterMote
  GPM : { name:'GPM', regexp:/GPM\:([\d\.]+)/i, value:'', unit:'kw/h', graph:1,  graphOptions : { legendLbl:'Watt/hour', lines: { lineWidth:1 }, colors:['#09c'],  /*yaxis: { ticks: [1,5,20], transform:  function(v) {return v==0?v:Math.log(v); //log scale },*/ tickDecimals: 2} },
  GLM : { name:'GLM', regexp:/GLM\:([\d\.]+)/i, value:'', unit:'kwlh', },
  GAL : { name:'GAL', regexp:/GAL\:([\d\.]+)/i, value:'', unit:'KW', pin:1, },


#define NODEID             3
#define GATEWAYID          1
#define NETWORKID          200
#define FREQUENCY          RF69_433MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
#define ENCRYPTKEY         "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
#define IS_RFM69HW            //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define PULSESPERGALLON    500 //how many pulses from sensor equal 1 gallon
#define GPMTHRESHOLD       8000  // GPM will reset after this many MS if no pulses are registered
#define XMITPERIOD         5000  // GPMthreshold should be less than 2*XMITPERIOD

Felix

Ok the changes I think are fine. I must say I have been using this sketch for years without such issues. So you will have to do some debugging to see where the problem is. Let me try to give some pointers.

The problem is with the 1.00.02 string, is that right?

If you look at the regex expression that matches that metric (ie /GAL\: ([\d\.]+)/i), it will match any decimals and dots. That would also match the string above, no matter how many dots are in between digits. If you want to get more specific, you could rewrite that regex to be more strict, ex: /GAL\: (\d+\.\d+)/i - this will match "GAL:" followed by several digits followed by 1 dot, followed by several more digits. So that will cause the bad string to not even register in the UI. (NOTE: I had to add a space between : and ( to avoid smiley faces, remove that space in real use).

BUT you have to fix this string coming from the node, that's the root cause. The node is sending that metric, and the sketch needs to change and send the correct number before it will register correctly. You will need to debug these 3 lines in the PulseMeter sketch:

GAL = ((float)PulseCounter)/PULSESPERGALLON; //this is where the GAL (gallons) number is calculated as a float.
dtostrf(GAL,3,2, GALstr);                                       //this is where the GAL float is formatted into a string
sprintf(buff, "GAL:%s GPM:%s", GALstr, GPMstr); //this is where the GALstr is formatted into a bigger string along with other pieces of information


You can add your own debugging statements (Serial.println or my DEBUGln variants) to figure out where the final string is malformed.

Memnon

That fixed the problem. But I did see in the serial/debugger that the numbers and decimal came when saving to eprom.  So I downloaded a new clean sketch and tried again. This time it showed the right decimal.  So I must have done something wrong with the first sketch.

;D