ni-c / heimcontrol.js

Home-Automation with node.js and Raspberry PI
MIT License
1.41k stars 297 forks source link

Error handler - wrong formula given to Arduino #56

Open V4P3 opened 10 years ago

V4P3 commented 10 years ago

Hi,

I wanted to try a temperature sensor on the arduino with the following formula:

0.00335402+(0.0002439*ln((1023/x)-1))

When I hit SAVE, Heimcontrol freezes and throws me the following error:

undefined:1
0.00335402+(0.0002439*ln((1023/560)-1))
^
ReferenceError: ln is not defined
    at eval (eval at <anonymous> (/home/pi/heimcontrol.js/plugins/arduino/index.js:190:54), <anonymous>:1:1)
    at null.<anonymous> (/home/pi/heimcontrol.js/plugins/arduino/index.js:190:36)
    at EventEmitter.emit (events.js:98:17)
    at null.<anonymous> (/home/pi/heimcontrol.js/node_modules/duino/lib/sensor.js:35:12)
    at EventEmitter.emit (events.js:117:20)
    at SerialPort.<anonymous> (/home/pi/heimcontrol.js/node_modules/duino/lib/board.js:32:14)
    at SerialPort.EventEmitter.emit (events.js:95:17)
    at /home/pi/heimcontrol.js/node_modules/duino/node_modules/serialport/parsers.js:24:17
    at Array.forEach (native)
    at Object.parser (/home/pi/heimcontrol.js/node_modules/duino/node_modules/serialport/parsers.js:23:13)

How can I fix this error? Is there a possibility to catch the error before it freezes Heimcontrol?

ConnorRoberts commented 10 years ago

The problem is that after replacing the x with the value, the formula is just ran through eval(), and there isn't a 'ln' function in javascript, it's actually Math.log() so you should use that instead

so using the formula:

0.00335402+(0.0002439*Math.log((1023/x)-1))

should work :)