Author Topic: Issue with Gateway when Converting fahrenheit to Celsius [solved]  (Read 1873 times)

Zachary

  • NewMember
  • *
  • Posts: 10
Hi there.

I have been having and Issue when I try to convert Fahrenheit to Celsius in the Metrics.js file. When I go into to the file and Uncomment FtoC and go and log into the gateway dashboard again, the gateway dashboard is stuck at waiting for socket connection. This has happened once and I did not know how to fix it so I reformatted my SD card for my raspberry pi and set up the gateway again. Everything worked again until I tried to uncomment the FtoC again to see if it will work and it happened again. I have also tried changing it back to the way it was with the FtoC commented again but it still did not work.
« Last Edit: December 13, 2018, 02:57:16 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #1 on: December 11, 2018, 01:10:08 PM »
What's the error in the gateway.sys.log?

Zachary

  • NewMember
  • *
  • Posts: 10
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #2 on: December 11, 2018, 05:47:06 PM »
If you mean the log or terminal in the gateway dashboard, it is empty. I was also wondering if it would go back to normal if I replaced the metrics file with new metrics file.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #3 on: December 11, 2018, 05:50:08 PM »
I meant the  gateway.sys.log found under the /gateway/logs folder. Thats where errors are dumped when something goes awry, like editing the .js files and introducing some bugs or syntax errors.

Always take backups when you replace a known working file.

Zachary

  • NewMember
  • *
  • Posts: 10
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #4 on: December 11, 2018, 06:01:17 PM »
Ok I found it.

/home/pi/gateway/metrics.js:89
  F : { name:'F', regexp:/\bF\ :( -?\d+\.\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},
  ^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
/home/pi/gateway/metrics.js:89
  F : { name:'F', regexp:/\bF\ :( -?\d+\.\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},
  ^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
/home/pi/gateway/metrics.js:89
  F : { name:'F', regexp:/\bF\ :( -?\d+\.\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},
  ^

It Keeps repeating this error everytime the gateway restarts.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #5 on: December 12, 2018, 09:06:54 AM »
OK. It says "SyntaxError: Unexpected identifier", and it even points where it is. So you must have missed a comma or something when you edited the metrics file.

Zachary

  • NewMember
  • *
  • Posts: 10
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #6 on: December 12, 2018, 01:43:32 PM »
Ok so this is the Temperature part in the metrics file. The only thing that I did was uncomment FtoC and FHtoC. When I went back into the gateway dashboard it was stuck at waiting for socket connection. So I comment the two lines again and the error was still there. I did not edit anything else. Also is this the correct way to change Fahrenheit to Celsius. 

//WeatherShield metrics
  //uncomment FtoC if you want a F:1234 to be valuated as a Centigrade isntead of F (the first match is picked up and will evaluate, any following defs are ignored)
  //FtoC : { name:'C', regexp:/F\:(-?\d+\.\d+)/i, value:'', duplicateInterval:3600, valuation:function(value) {return (value - 32) * 5/9;}, unit:'°', pin:1, graph:1, graphValSuffix:'C', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 }}}
  F : { name:'F', regexp:/\bF\:(-?\d+\.\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},
  //uncomment FHtoC if you want a F:1234 to be valuated as a Centigrade isntead of F (the first match is picked up and will evaluate, any following defs are ignored)
  //FHtoC : { name:'C', regexp:/\bF\:(-?\d+)\b/i, value:'', duplicateInterval:3600, valuation:function(value) {return (value/100 - 32) * 5/9;}, unit:'°', pin:1, graph:1, graphValSuffix:'C', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 }}}
  FH : { name:'F', regexp:/\bF\:(-?\d+)\b/i, value:'', duplicateInterval:3600, valuation:function(value) {return value/100;}, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 }}},
  C : { name:'C', regexp:/\bC\:([-\d\.]+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'C', graphOptions:{ legendLbl:'Temperature' }},
  H : { name:'H', regexp:/\bH\:([\d\.]+)\b/i, value:'', duplicateInterval:3600, unit:'%', pin:1, graph:1, graphOptions:{ legendLbl:'Humidity', lines: { lineWidth:1 }}},
  P : { name:'P', regexp:/\bP\:([\d\.]+)\b/i, value:'', duplicateInterval:3600, unit:'"', pin:1, },

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #7 on: December 12, 2018, 02:13:50 PM »
Ahh, there is a comma missing, oops.
Please add a "," at the end of the FtoC line.
Will be fixed in v9 release.

Zachary

  • NewMember
  • *
  • Posts: 10
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #8 on: December 12, 2018, 03:43:36 PM »
Ok thanks it worked. Also how do i make it so that there aren't 15 decimal places when you look at the temperature in the gateway dashboard. And is there a quick way of edit the settings for the THalert Event like changing the F to C or if i want it to send me a sms if the temperature goes higher then 80 Fahrenheit or would i need to create my own seperate event.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #9 on: December 12, 2018, 03:55:44 PM »
Try this instead:

Code: [Select]
FtoC : { name:'C', regexp:/F\:(-?\d+\.\d+)/i, value:'', duplicateInterval:3600, valuation:function(value) {return ((value - 32) * 5/9).toFixed(2);}, unit:'°', pin:1, graph:1, graphValSuffix:'C', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 }}},

Zachary

  • NewMember
  • *
  • Posts: 10
Re: Issue with Gateway when Converting fahrenheit to Celsius.
« Reply #10 on: December 12, 2018, 08:17:19 PM »
The code worked great. It Switched back and forth between a lot of decimal places and only 1 decimal place a few times but seems to be working good now.