pedalPusher68 / node-red-contrib-brads-i2c-nodes

A collection of node-red nodes for assorted i2c devices
MIT License
5 stars 7 forks source link

Node-RED crash when running this node with error "ReferenceError: BigNumber is not defined" #6

Open inakil opened 6 years ago

inakil commented 6 years ago

Hi, I get the following error when running this node.

`Nov 23 20:32:08 localhost Node-RED[4814]: 23 Nov 20:32:08 - [info]

Nov 23 20:32:08 localhost Node-RED[4814]: Welcome to Node-RED

Nov 23 20:32:08 localhost Node-RED[4814]: ===================

Nov 23 20:32:08 localhost Node-RED[4814]: 23 Nov 20:32:08 - [info] Node-RED version: v0.17.5

Nov 23 20:32:08 localhost Node-RED[4814]: 23 Nov 20:32:08 - [info] Node.js version: v6.12.0

Nov 23 20:32:08 localhost Node-RED[4814]: 23 Nov 20:32:08 - [info] Linux 4.9.59-v7+ arm LE

Nov 23 20:32:09 localhost Node-RED[4814]: 23 Nov 20:32:09 - [info] Loading palette nodes

Nov 23 20:32:12 localhost Node-RED[4814]: 23 Nov 20:32:12 - [info] Dashboard version 2.6.2 started at /ui

Nov 23 20:32:14 localhost Node-RED[4814]: 23 Nov 20:32:14 - [info] Settings file : ~/.node-red/settings.js

Nov 23 20:32:14 localhost Node-RED[4814]: 23 Nov 20:32:14 - [info] User directory : ~/.node-red

Nov 23 20:32:14 localhost Node-RED[4814]: 23 Nov 20:32:14 - [info] Flows file : ~/.node-red/flows_localhost.json

Nov 23 20:32:14 localhost Node-RED[4814]: 23 Nov 20:32:14 - [info] Server now running at http://127.0.0.1:1880/

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] Starting flows

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] {"id":"bc8a0fad.6ae328","type":"bmp280","z":"52493605.509888","name":"bmp280","topic":"","address":"118","powermode":"3","treso

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] node.t_oversampling -> {"display":"+/- 0.0050 ℃","displayF":"+/- 0.0090 ℉","timeMs":7,"value":0.005,"bits":32}

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] node.p_oversampling -> {"display":"+/- 2.62 Pa","displayHg":"+/- 0.00077 inches Hg","timeMs":7,"value":2.62,"bits":4}

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] ctrl_meas = 100111 (0x27)

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] opened i2cBus -> [object Object]

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] ic2Bus -> [object Object]

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] about to do Promise.all(...)

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] Started flows

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] bmp280 Device ID: 0x58 (expected 0x58)

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280]

Nov 23 20:32:15 localhost Node-RED[4814]: bmp280 calibration parameters loaded.

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x8889 digT1 -> 0x6ac3 27331

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x8a8b digT2 -> 0x6778 26488

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x8c8d digT3 -> 0x-3e8 -1000

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x8e8f digP1 -> 0x93c9 37833

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9091 digP2 -> 0x-29a3 -10659

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9293 digP3 -> 0xbd0 3024

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9495 digP4 -> 0xcdd 3293

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9697 digP5 -> 0xaf 175

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9899 digP6 -> 0x-7 -7

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9a9b digP7 -> 0x3c8c 15500

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9c9d digP8 -> 0x-3908 -14600

Nov 23 20:32:15 localhost Node-RED[4814]: Calibration Address: 0x9e9f digP9 -> 0x1770 6000

Nov 23 20:32:15 localhost Node-RED[4814]: 23 Nov 20:32:15 - [info] [bmp280:bmp280] bmp280 ready.

Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - [info] [bmp280:bmp280] measure() ...

Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - [info] [bmp280:bmp280] {"_msgid":"9314d213.11a45","topic":"","payload":"measure"}

Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - [info] [bmp280:bmp280] Operating in debugMode = true

Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - [info] [bmp280:bmp280] adc_Ti: 506976 0x7bc60 1111011110001100000

Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - [info] [bmp280:bmp280] adc_Pi: 432560 0x699b0 1101001100110110000 **Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - [red] Uncaught Exception:

Nov 23 20:32:35 localhost Node-RED[4814]: 23 Nov 20:32:35 - ReferenceError: BigNumber is not defined

Nov 23 20:32:35 localhost Node-RED[4814]: at i2cBus.readI2cBlock (~/.node-red/node_modules/node-red-contrib-brads-i2c-nodes/sensors/bmp280-node.js:375:108)**

Nov 23 20:32:35 localhost systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE

Nov 23 20:32:35 localhost systemd[1]: nodered.service: Unit entered failed state.

Nov 23 20:32:35 localhost systemd[1]: nodered.service: Failed with result 'exit-code'.

Nov 23 20:32:36 localhost systemd[1]: nodered.service: Service hold-off time over, scheduling restart.

Nov 23 20:32:36 localhost systemd[1]: Stopped Node-RED graphical event wiring tool..

Nov 23 20:32:36 localhost systemd[1]: Started Node-RED graphical event wiring tool.. `

I have trying installing bignumber.js either and both in ~/.node-red and ~/.node-red/node_modules/node-red-contrib-brads-i2c-nodes and I get always the same error. I even tried installing as global. Can you help me? Thanks.

EDIT: censoring some data and formatting

creuzerm commented 6 years ago

I hit the same error. I think we are missing https://github.com/MikeMcl/bignumber.js/ ?

I don't see anywhere that it's actually used in the code. I don't see a "new BigNumber()" call anywhere. The "toString" call maybe, but that should be the base Number type and not from the BigNumber function as it is not invoked.

I am going to try taking out the BigNumber requirement and see if the code runs. Best I can sort out, it's not used.

I was inspecting BME260.js not BMP260.js

creuzerm commented 6 years ago

I spent some more time and I think I found the issue. I think it's a scoping issue with the require statement for the BigNumbers library.

After line 27 of bmp280.js I added "const BigNumber = require('bignumber.js');" and the error doesn't occur anymore and I get some temperature readings from the sensor.

 22   "use strict";
 23   // require any external libraries we may need....
 24   // Node.js Imports
 25   const os = require('os');
 26   // NPM Imports
 27   const i2c = require('i2c-bus');
 28   const BigNumber = require('bignumber.js');