Fahrenheit to Celsius (Weathershield mote)

Started by DrSproc, February 20, 2016, 07:16:58 AM

DrSproc

For my Canadian compadres, here's a quick way I got my dashboard talking Celsius for the weathershield mote... this assumes the mote's in the field transmitting values in Fahrenheit. 

Login to your raspberry pi and make a backup copy of the metrics.js file

cp /home/pi/gateway/metrics.js /home/pi/gateway/metrics.js_bak

Next nano into metrics.js

nano /home/pi/gateway/metrics.js

and modify the following line in the //WeatherShield metrics section
FH : { name:'F', regexp:/F\:(-?\d+)/i, value:'', valuation:function(value) {return (((value/100)-32)*(5/9)).toFixed(2);}, unit:'°', pin:1, graph:1, graphValSuffix$:'C', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 }}},



ctl-O to save and ctrl-x to exit...

reboot your pi and you ready to see Celsius...
I also altered the Value description on the web page, with a "C"...

The formula is a well know conversion of F to C
;D 

Kilo95

Could you tell me how to add 0.7229 to the value on the pressure reading? That's my correction factor for my elevation. I tried in the sketch and failed. I assume if you can manipulate the temp reading from F to C you could add 0.7229 to the P reading. I've tried a couple things but failed. Thanks

DrSproc

#2
Kilo... I would change it this way...


from...
P : { name:'P', regexp:/P\:([\d\.]+)/i, value:'', unit:'"', pin:1, },

to...
P : { name:'P', regexp:/P\:([\d\.]+)/i, value:'', valuation:function(value) {return (value+0.7229).toFixed(2);}, unit:'"', pin:1, },


hope this helps...  8)


Kilo95

tried that then sudo reboot. my gateway gui hangs up at "waiting for socket connection". if i revert to my metrics.js_bak it works fine...

Felix

Check the logs for errors.
But don't just copy paste from a non code text, note that the forum will place smiley faces where the character combination matches one.
It should be in a code block (I updated the above). Try it again.


Kilo95

I'll check the log and try again. I didn't copy and paste. I manually entered it. I'll go back through and try it again. I really appreciate it

Kilo95

ok. i changed it to the suggested and the gateway gui wouldn't update. i checked the log and it said it "has no method 'toFixed'". i deleted ".toFixed(2)" and tried it again. i'm attaching a screenshot

http://imgur.com/gallery/B9JvX

DrSproc

#9
Please post the full line as you have it in the metrics.js file.  I have a hunch something is missing. Like a semicolon or a bracket.

Kilo95

i cut an pasted this one from the above to metrics.js:

P : { name:'P', regexp:/P\:([\d\.]+)/i, value:'', valuation:function(value) {return (value+0.7229).toFixed(2);}, unit:'"', pin:1, },

new screen shot of gateway.sys.log:

http://imgur.com/gallery/kPBEx

DrSproc

#11
Kilo...

Looks like the script treats the pressure value as a string data type...

What can be done in this case is to parse the value into a float and then apply the correction factor for your area...

...lastly trimming to two decimal places, so the values look consistently formatted for display...  try replacing with this code...

P : { name:'P', regexp:/P\:([\d\.]+)/i, value:'', valuation:function(value) {return (parseFloat(value)+0.7229).toFixed(2);}, unit:'"', pin:1, },


Kilo95

Perfect! Works like a charm. Much appreciated