could you create a file nodejs.sh
in /etc/profile.d/
that contains
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
export NODE_PATH
just to be sure ?
could you create a file nodejs.sh
in /etc/profile.d/
that contains
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
export NODE_PATH
just to be sure ?
I did but the result is the same (see error message above)
Just a curiosity… if the box is sealed…how you can think to measure external humidity, pressure and temperature?
Alex
there is an inside and an outside sensor
Ops sorry… Charles, what kind of material surrounding the SI7021?
It looks like the script automaticly first started and then quits unexpectedly:
ttn@ttn-gateway:~/ic880a-gateway/src/sensors_js $ sudo systemctl status sensors-js
● sensors-js.service - CH2i TTN Gateway Sensors service
Loaded: loaded (/lib/systemd/system/sensors-js.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-02-25 12:42:06 CET; 358ms ago
Main PID: 8841 (node)
CGroup: /system.slice/sensors-js.service
└─8841 /usr/bin/node /opt/ttn-gateway/bin/sensors.js
Feb 25 12:42:06 ttn-gateway systemd[1]: Started CH2i TTN Gateway Sensors service.
ttn@ttn-gateway:~/ic880a-gateway/src/sensors_js $ sudo systemctl status sensors-js
● sensors-js.service - CH2i TTN Gateway Sensors service
Loaded: loaded (/lib/systemd/system/sensors-js.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-02-25 12:42:09 CET; 2s ago
Process: 8864 ExecStart=/usr/bin/node /opt/ttn-gateway/bin/sensors.js (code=exited, status=1/FAILURE)
Main PID: 8864 (code=exited, status=1/FAILURE)
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Main process exited, code=exited, status=1/FAILURE
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Unit entered failed state.
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Failed with result ‘exit-code’.
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Service hold-off time over, scheduling restart.
Feb 25 12:42:09 ttn-gateway systemd[1]: Stopped CH2i TTN Gateway Sensors service.
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Start request repeated too quickly.
Feb 25 12:42:09 ttn-gateway systemd[1]: Failed to start CH2i TTN Gateway Sensors service.
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Unit entered failed state.
Feb 25 12:42:09 ttn-gateway systemd[1]: sensors-js.service: Failed with result ‘exit-code’.
Maybe it’s helpful to look into the system log, here is the depending part:
Feb 28 12:56:52 ttn-gateway systemd[1]: Started CH2i TTN Gateway Sensors service.
– Subject: Unit sensors-js.service has finished start-up
– Defined-By: systemd
– Support: Debian -- User Support
–
– Unit sensors-js.service has finished starting up.
–
– The start-up result is done.
Feb 28 12:56:52 ttn-gateway sudo[3730]: pam_unix(sudo:session): session closed for user root
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: /opt/ttn-gateway/bin/node_modules/bindings/bindings.js:88
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: throw e
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: ^
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: Error: Module version mismatch. Expected 46, got 48.
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Error (native)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Object.Module._extensions…node (module.js:434:18)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Module.load (module.js:343:32)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Function.Module._load (module.js:300:12)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Module.require (module.js:353:17)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at require (internal/module.js:12:17)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at bindings (/opt/ttn-gateway/bin/node_modules/bindings/bindings.js:81:44)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Object. (/opt/ttn-gateway/bin/node_modules/i2c-bus/i2c-bus.js:4:28)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Module._compile (module.js:409:26)
Feb 28 12:56:53 ttn-gateway sensors-js[3736]: at Object.Module._extensions…js (module.js:416:10)
Feb 28 12:56:53 ttn-gateway systemd[1]: sensors-js.service: Main process exited, code=exited, status=1/FAILURE
Feb 28 12:56:53 ttn-gateway systemd[1]: sensors-js.service: Unit entered failed state.
Feb 28 12:56:53 ttn-gateway systemd[1]: sensors-js.service: Failed with result ‘exit-code’.
Feb 28 12:56:53 ttn-gateway systemd[1]: sensors-js.service: Service hold-off time over, scheduling restart.
Feb 28 12:56:53 ttn-gateway systemd[1]: Stopped CH2i TTN Gateway Sensors service.
– Subject: Unit sensors-js.service has finished shutting down
– Defined-By: systemd
– Support: Debian -- User Support
–
– Unit sensors-js.service has finished shutting down.
No idea what’s going wrong?
What sensor did you used ?
would you min stop the service and start it by hand as indicated above to see what’s the output ?
looks like sensor not recognized, a clone one ?
As I wrote above: Starting by hand succeeded (see #7). I use a BME280 and it‘s not a clone.
Ok let’s restart from scratch
cd /opt/ttn-gateway
sudo systemctl stop sensors-js
sudo rm -rf node_modules
sudo npm install -g --unsafe-perm bme280-sensor
sudo npm install -g --unsafe-perm si7021-sensor
sudo npm install -g --unsafe-perm cayennejs
sudo npm link bme280-sensor
sudo npm link si7021-sensor
sudo npm link cayennejs
sudo systemctl start sensors-js
Does this works ?
BTW what nodejs version do you have ?
I tested on my new GW and this is working fine
loragw@ttn-gw04:/opt/loragw $ sudo systemctl status sensors-js.service
● sensors-js.service - CH2i Lora Gateway Sensors service
Loaded: loaded (/lib/systemd/system/sensors-js.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-13 18:35:31 CEST; 21min ago
Main PID: 10352 (node)
CGroup: /system.slice/sensors-js.service
└─10352 /usr/bin/node /opt/loragw/sensors.js
Apr 13 18:56:28 ttn-gw04 sensors-js[10352]: }
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: BME280 data = {
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: "temperature_C": 38.67,
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: "humidity": 18.941909695408516,
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: "pressure_hPa": 997.5175459059838
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: }
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: SI7021 data = {
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: "humidity": 32.761138916015625,
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: "temperature_C": 29.759372558593746
Apr 13 18:57:00 ttn-gw04 sensors-js[10352]: }
loragw@ttn-gw04:/opt/loragw $ node -v
v9.11.1
I’ve also updated new setup (take care it’s no more /opt/ttn-gateway but /opt/loragw so may be you’ll need to adapt to reflect your old setup)
Thank you for your response. I will try as soon as I can but now I’m away from my GW until end of April.
Hans
I did it without errors. But “sudo systemctl status sensors-js.service” always failed:
● sensors-js.service - CH2i TTN Gateway Sensors service
Loaded: loaded (/lib/systemd/system/sensors-js.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2018-04-28 19:08:27 CEST; 6s ago
Process: 5430 ExecStart=/usr/bin/node /opt/ttn-gateway/bin/sensors.js (code=exited, status=1/FAILURE)
Main PID: 5430 (code=exited, status=1/FAILURE)
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Main process exited, code=exited, status=1/FAILURE
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Unit entered failed state.
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Failed with result ‘exit-code’.
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Service hold-off time over, scheduling restart.
Apr 28 19:08:27 ttn-gateway systemd[1]: Stopped CH2i TTN Gateway Sensors service.
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Start request repeated too quickly.
Apr 28 19:08:27 ttn-gateway systemd[1]: Failed to start CH2i TTN Gateway Sensors service.
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Unit entered failed state.
Apr 28 19:08:27 ttn-gateway systemd[1]: sensors-js.service: Failed with result ‘exit-code’.
If I start the service by hand it succeeded.
I have node version 6.9.2. Could this cause the error? How can I update node to version 9.11.1?
Meanwhile, I’m on node v9.11.1 but the problem remains. Starting by hand works but not automatically:
Apr 29 07:19:00 ttn-gateway systemd[1]: Started CH2i TTN Gateway Sensors service.
– Subject: Unit sensors-js.service has finished start-up
– Defined-By: systemd
– Support: Debian -- User Support
–
– Unit sensors-js.service has finished starting up.
–
– The start-up result is done.
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: /opt/ttn-gateway/bin/node_modules/bindings/bindings.js:88
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: throw e
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: ^
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: Error: Module version mismatch. Expected 46, got 48.
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Error (native)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Object.Module._extensions…node (module.js:434:18)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Module.load (module.js:343:32)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Function.Module._load (module.js:300:12)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Module.require (module.js:353:17)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at require (internal/module.js:12:17)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at bindings (/opt/ttn-gateway/bin/node_modules/bindings/bindings.js
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Object. (/opt/ttn-gateway/bin/node_modules/i2c-bus/i2
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Module._compile (module.js:409:26)
Apr 29 07:19:01 ttn-gateway sensors-js[3647]: at Object.Module._extensions…js (module.js:416:10)
Apr 29 07:19:01 ttn-gateway systemd[1]: sensors-js.service: Main process exited, code=exited, status=1/FAILURE
Apr 29 07:19:01 ttn-gateway systemd[1]: sensors-js.service: Unit entered failed state.
Apr 29 07:19:01 ttn-gateway systemd[1]: sensors-js.service: Failed with result ‘exit-code’.
Apr 29 07:19:01 ttn-gateway systemd[1]: sensors-js.service: Service hold-off time over, scheduling restart.
Apr 29 07:19:01 ttn-gateway systemd[1]: Stopped CH2i TTN Gateway Sensors service.
– Subject: Unit sensors-js.service has finished shutting down
– Defined-By: systemd
– Support: Debian -- User Support
–
– Unit sensors-js.service has finished shutting down.
Any suggestion for me to try out? It would be great to get it work.
I did a workaround using tmux but it‘s not as elegant as your solution - if it really works!
It could be possible that You have more versions of node.js installed ot some problems with scope.
You can check, for example if “sudo node -v” and “node -v” give same version result.
A fast workaround, if is a multiple node.js versions problem, if more version are installed is to change ExecStart in service file from /usr/bin/node to /usr/local/bin/node (or other path to node).
But the best solution is to fix your node.js installation/s.
Thank you, that seems to be a good suggestion.
“sudo node -v” says “v6.9.2” and “node -v” “v9.11.1” so I think I have to delete the v6.9.2
How can I do without touching the v9.11.1?
Here my config, and it works since lot of days
loragw@ttn-gw04:~ $ node -v
v9.11.1
loragw@ttn-gw04:~ $ npm -v
5.6.0
loragw@ttn-gw04:~ $ sudo journalctl -f -u sensors-js
-- Logs begin at Tue 2018-05-22 12:38:23 CEST. --
May 22 16:05:34 ttn-gw04 sensors-js[358]: BME280 data = {
May 22 16:05:34 ttn-gw04 sensors-js[358]: "temperature_C": 39.64,
May 22 16:05:34 ttn-gw04 sensors-js[358]: "humidity": 17.388738295232756,
May 22 16:05:34 ttn-gw04 sensors-js[358]: "pressure_hPa": 1001.6689208701918
May 22 16:05:34 ttn-gw04 sensors-js[358]: }
May 22 16:05:35 ttn-gw04 sensors-js[358]: SI7021 data = {
May 22 16:05:35 ttn-gw04 sensors-js[358]: "humidity": 45.197052001953125,
May 22 16:05:35 ttn-gw04 sensors-js[358]: "temperature_C": 25.27628173828125
May 22 16:05:35 ttn-gw04 sensors-js[358]: }
May 22 16:05:35 ttn-gw04 sensors-js[358]: SI7021 data = {
May 22 16:05:35 ttn-gw04 sensors-js[358]: "humidity": 45.189422607421875,
May 22 16:05:35 ttn-gw04 sensors-js[358]: "temperature_C": 25.287006835937497
May 22 16:05:35 ttn-gw04 sensors-js[358]: }
May 22 16:05:36 ttn-gw04 sensors-js[358]: BME280 data = {
May 22 16:05:36 ttn-gw04 sensors-js[358]: "temperature_C": 39.65,
May 22 16:05:36 ttn-gw04 sensors-js[358]: "humidity": 17.360058411474203,
May 22 16:05:36 ttn-gw04 sensors-js[358]: "pressure_hPa": 1001.7239804856971
May 22 16:05:36 ttn-gw04 sensors-js[358]: }
loragw@ttn-gw04:~ $
Here the script file /opt/loragw/sensors.js
/*******************************************************************************
* NodeJS script to send sensors data to cayenne IoT dashboard
* you can have a BMP280/BME280 and SI7021/HTU21D conencted to I2C bus
* This sample has been written by Charles-Henri Hallard (ch2i.eu)
*
* Requires nodejs to be already installed
* https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
*
* Requires CayenneJS bme280 and si7021 libraries
* npm install bme280-sensor si7021-sensor cayennejs
*
* Don't forget to put your Cayenne credential in this script, all of this
* stuff can be done with the script installer install.sh of this folder
* installer will also make the as daemon to start/stop with the system
*
* sudo node sensors.js
*
*******************************************************************************/
const BME280 = require('bme280-sensor');
const Si7021 = require('si7021-sensor');
var Cayenne = require('cayennejs');
const bme280 = new BME280({ i2cBusNo : 1, i2cAddress : 0x76 });
const si7021 = new Si7021({ i2cBusNo : 1, i2cAddress : 0x40 });
// Update every x seconds
const updateInterval = 60;
// Initiate Cayenne MQTT API
const cayenneClient = new Cayenne.MQTT({
username: "############",
password: "###############",
clientId: "##############"
});
// Read BME280 sensor data, repeat
const readBME280SensorData = () => {
bme280.readSensorData()
.then((data) => {
console.log(`BME280 data = ${JSON.stringify(data, null, 2)}`);
// dashboard widget automatically detects datatype & unit
cayenneClient.celsiusWrite (0, data.temperature_C.toFixed(1));
cayenneClient.rawWrite(1, data.humidity.toFixed(0), "rel_hum" , "p" );
cayenneClient.hectoPascalWrite (2, data.pressure_hPa.toFixed(0));
setTimeout(readBME280SensorData, updateInterval*1000);
})
.catch((err) => {
console.log(`BME280 read error: ${err}`);
setTimeout(readBME280SensorData, updateInterval*1000);
});
};
const readSI7021SensorData = () => {
si7021.readSensorData()
.then((data) => {
console.log(`SI7021 data = ${JSON.stringify(data, null, 2)}`);
cayenneClient.celsiusWrite (4, data.temperature_C.toFixed(1));
cayenneClient.rawWrite(5, data.humidity.toFixed(0), "rel_hum" , "p" );
setTimeout(readSI7021SensorData, updateInterval*1000);
})
.catch((err) => {
console.log(`Si7021 read error: ${err}`);
setTimeout(readSI7021SensorData, updateInterval*1000);
});
};
cayenneClient.connect((err , mqttClient) => {
console.log('Cayenne connected')
// Initialize the BME280 sensor
bme280.init()
.then(() => {
console.log('BME280 initialization succeeded');
readBME280SensorData();
})
.catch((err) => console.error(`BME280 initialization failed: ${err} `));
// Initialize the si7021 sensor
si7021.reset()
.then(() => {
console.log('SI7021 initialization succeeded');
readSI7021SensorData();
})
.catch((err) => console.error(`Si7021 reset failed: ${err} `));
})
and the starting service systemd file /lib/systemd/system/sensors-js.service
# as root in terminal
#
# ln -s $PWD/sensors.js /opt/loragw/sensors.js
#
# Enable the service
# systemctl enable sensors-js.service
#
# Start the service
# systemctl start sensors-js.service
#
# Verify it is running
# systemctl status sensors-js.service
[Unit]
Description=CH2i Lora Gateway Sensors service
[Service]
ExecStart=/usr/bin/node /opt/loragw/sensors.js
Restart=always
RestartSec=30
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sensors-js
[Install]
WantedBy=multi-user.target
Hi Marco,
I changed ExecStart in sensors-js.service file from /usr/bin/node to /usr/local/bin/node an got it working!
Thank you very much
Hans