LowPowerLab Forum

Software support => Pi Gateway => Topic started by: DrSproc on February 20, 2016, 07:16:58 AM

Title: Fahrenheit to Celsius (Weathershield mote)
Post by: DrSproc on February 20, 2016, 07:16:58 AM
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 
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 20, 2016, 02:29:49 PM
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
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: DrSproc on February 20, 2016, 04:57:25 PM
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)
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 20, 2016, 05:04:47 PM
Much thanks
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 20, 2016, 06:02:08 PM
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...
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Felix on February 20, 2016, 08:46:10 PM
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.
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: DrSproc on February 20, 2016, 09:07:28 PM
Thanks Felix...
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 20, 2016, 09:47:14 PM
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
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 20, 2016, 10:17:05 PM
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
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: DrSproc on February 20, 2016, 11:01:35 PM
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.
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 21, 2016, 08:42:18 AM
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
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: DrSproc on February 21, 2016, 10:03:33 AM
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, },

Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: Kilo95 on February 21, 2016, 01:37:24 PM
Perfect! Works like a charm. Much appreciated
Title: Re: Fahrenheit to Celsius (Weathershield mote)
Post by: DrSproc on February 21, 2016, 03:23:53 PM
Good stuff!