From ca60d62fb1af989421584463d78912bcf50c2381 Mon Sep 17 00:00:00 2001 From: ardean Date: Wed, 1 Feb 2017 19:39:36 +0100 Subject: [PATCH] remove production env mode, refactor readme --- README.md | 19 ++++++---- dist/server/am2302.js | 8 +++-- dist/server/package.json | 75 ---------------------------------------- dist/server/relay.js | 6 +++- package.json | 5 ++- src/am2302.js | 7 ++-- src/cli.js | 2 +- src/relay.js | 5 ++- 8 files changed, 35 insertions(+), 92 deletions(-) delete mode 100644 dist/server/package.json diff --git a/README.md b/README.md index 7c5067c..dfb1c32 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,15 @@ **A Web Based Sauna Control System written in JavaScript** I use this package to control my sauna with my **Raspberry pi**. -There is a solid state relay to switch the heater *On* and *Off*, as well as a *temperature* and *humidity* sensor to measure the surroundings. +There is a solid state relay to switch the heater `On` and `Off`, as well as a `temperature` and `humidity` sensor to measure the surroundings. -- DHT Sensor: https://www.adafruit.com/product/393 -- Solid State Relay: https://www.sparkfun.com/products/13015 +- DHT Sensor: [https://www.adafruit.com/product/393](https://www.adafruit.com/product/393) +- Solid State Relay: [https://www.sparkfun.com/products/13015](https://www.sparkfun.com/products/13015) ![jsSauna - Webapp](docs/images/ui.png) +Pick a `target temperature` and switch the sauna `On` / `Off`. + ## Quick Start Install jsSauna globally: @@ -69,11 +71,14 @@ $ npm start ## Production -please set the environment variable for production use: +I'm using [pm2](https://www.npmjs.com/package/pm2) on my production system to start jsSauna. -```sh -NODE_ENV="production" jsSauna --rp 14 --sp 4 -``` +Make sure you install jsSauna with all optional dependencies! +Otherwise you will use **testdata** for the sensors and On / Off requests will be **ignored** for the relay! + +### Troubleshooting + +If you have problems installing jsSauna globally as root using `sudo npm i -g jssauna`, you can try the option `--unsafe-perm`. ## TODO diff --git a/dist/server/am2302.js b/dist/server/am2302.js index 3b31da1..2b4d850 100644 --- a/dist/server/am2302.js +++ b/dist/server/am2302.js @@ -3,10 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); -let dhtSensor; -if (process.env.NODE_ENV === "production") { +var _util = require("util"); + +let dhtSensor; +try { dhtSensor = require("node-dht-sensor"); +} catch (e) { + (0, _util.log)("node-dht-sensor is not installed! Using test data!"); } class AM2302 { diff --git a/dist/server/package.json b/dist/server/package.json deleted file mode 100644 index c89b48a..0000000 --- a/dist/server/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "jssauna", - "version": "0.1.0", - "description": "A Web Based Sauna Control System written in JavaScript", - "main": "src/index.js", - "author": "ardean", - "repository": "https://github.com/ardean/jsSauna", - "bugs": "https://github.com/ardean/jsSauna/issues", - "license": "MIT", - "scripts": { - "start": "babel-node src/cli.js --username admin --pw 1234", - "export": "npm run build && npm run export-server && npm run export-html && npm run export-css && npm run export-img", - "export-server": "cpy package.json dist/server", - "export-html": "cpy public/*.html dist/public", - "export-css": "cpy public/*.css dist/public", - "export-img": "cpy public/*.jpg dist/public", - "debug-export": "npm run export && babel-node dist/server/cli.js", - "build": "npm run cleanup && npm run bundle && npm run build-server", - "build-server": "babel src --out-dir dist/server", - "cleanup": "del dist", - "bundle": "jspm build src/index.js dist/public/index.js --minify --skip-source-maps" - }, - "bin": { - "jsSauna": "./bin/index.js" - }, - "dependencies": { - "commander": "^2.9.0", - "express": "^4.14.1", - "socket.io": "^1.7.2" - }, - "optionalDependencies": { - "node-dht-sensor": "0.0.32", - "onoff": "^1.1.1" - }, - "devDependencies": { - "babel-cli": "^6.22.2", - "babel-preset-node6": "^11.0.0", - "cpy-cli": "^1.0.1", - "del-cli": "^0.2.1", - "jspm": "^0.17.0-beta.37" - }, - "jspm": { - "directories": { - "baseURL": "public" - }, - "dependencies": { - "events": "npm:jspm-nodelibs-events@^0.2.0", - "jquery": "npm:jquery@^3.1.1" - }, - "devDependencies": { - "babel-runtime": "npm:babel-runtime@^5.8.24", - "core-js": "npm:core-js@^1.1.4", - "fs": "npm:jspm-nodelibs-fs@^0.2.0", - "path": "npm:jspm-nodelibs-path@^0.2.0", - "plugin-babel": "npm:systemjs-plugin-babel@^0.0.20" - }, - "peerDependencies": { - "assert": "npm:jspm-nodelibs-assert@^0.2.0", - "process": "npm:jspm-nodelibs-process@^0.2.0", - "util": "npm:jspm-nodelibs-util@^0.2.0" - }, - "overrides": { - "npm:babel-runtime@5.8.38": { - "main": false, - "dependencies": {}, - "optionalDependencies": { - "core-js": "^1.2.0" - } - }, - "npm:jquery@3.1.1": { - "format": "amd" - } - } - } -} diff --git a/dist/server/relay.js b/dist/server/relay.js index 4ec07a3..bdc2502 100644 --- a/dist/server/relay.js +++ b/dist/server/relay.js @@ -4,11 +4,15 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _util = require("util"); + var _events = require("events"); let Gpio; -if (process.env.NODE_ENV === "production") { +try { Gpio = require("onoff").Gpio; +} catch (e) { + (0, _util.log)("onoff is not installed! Ignoring On / Off requests!"); } class Relay extends _events.EventEmitter { diff --git a/package.json b/package.json index 64514ac..aed50f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jssauna", - "version": "0.1.3", + "version": "0.1.4", "description": "A Web Based Sauna Control System written in JavaScript", "main": "src/index.js", "author": "ardean", @@ -21,8 +21,7 @@ ], "scripts": { "start": "babel-node src/cli.js --username admin --pw 1234", - "export": "npm run build && npm run export-server && npm run export-html && npm run export-css && npm run export-img", - "export-server": "cpy package.json dist/server", + "export": "npm run build && npm run export-html && npm run export-css && npm run export-img", "export-html": "cpy public/*.html dist/public", "export-css": "cpy public/*.css dist/public", "export-img": "cpy public/*.jpg dist/public", diff --git a/src/am2302.js b/src/am2302.js index 9b36360..fee8be9 100644 --- a/src/am2302.js +++ b/src/am2302.js @@ -1,7 +1,10 @@ -let dhtSensor; +import { log } from "util"; -if (process.env.NODE_ENV === "production") { +let dhtSensor; +try { dhtSensor = require("node-dht-sensor"); +} catch (e) { + log("node-dht-sensor is not installed! Using test data!"); } export default class AM2302 { diff --git a/src/cli.js b/src/cli.js index 63c07f4..d227efc 100644 --- a/src/cli.js +++ b/src/cli.js @@ -4,7 +4,7 @@ import { Sauna, SaunaControl, AM2302, Relay } from "./"; import program from "commander"; program - .version("0.1.0") + .version("0.1.4") .option("-p, --port ", "override default webserver port", parseInt) .option("-t, --target-temperature ", "override default target temperature (50°C)", parseInt) .option("-m, --max-temperature ", "override default max temperature (60°C)", parseInt) diff --git a/src/relay.js b/src/relay.js index 9dd7570..a3f922b 100644 --- a/src/relay.js +++ b/src/relay.js @@ -1,8 +1,11 @@ +import { log } from "util"; import { EventEmitter } from "events"; let Gpio; -if (process.env.NODE_ENV === "production") { +try { Gpio = require("onoff").Gpio; +} catch (e) { + log("onoff is not installed! Ignoring On / Off requests!"); } export default class Relay extends EventEmitter {