Skip to content

Commit

Permalink
Prep 0.4.0. Initial iSpindel support
Browse files Browse the repository at this point in the history
  • Loading branch information
cwilling committed Sep 9, 2017
1 parent 4a87b34 commit ecaaf14
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST_FILES = test-status.js \

DESTDIR ?=

PKGVERSION ?= 0.3.2
PKGVERSION ?= 0.4.0

# Where any app files are installed
RUNDIR = /usr/share/brewable
Expand Down
2 changes: 1 addition & 1 deletion makeself.make
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
NODEEXE=$(which node)
BREWTEMPDIR=`mktemp -d /tmp/brewtemp.XXXXXX` || exit 1
TARGET=$(pwd)/brewable
VERSION=0.3.2
VERSION=0.4.0

echo './node brewableserverbundle.js "$@"' > $BREWTEMPDIR/run.sh
chmod a+x $BREWTEMPDIR/run.sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"clean": "rm -r build/*"
},
"name": "brewable",
"version": "0.3.2",
"version": "0.4.0",
"description": "Nodejs version of brewable",
"main": "src/scripts/brewable.js",
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/modules/configuration.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from "fs";
import mkdirp from "mkdirp";
import path from 'path';
var home = require('os').homedir();
import os from 'os';

//var home = os.homedir();

var defaultConfigValues = function() {
return {
Expand All @@ -19,7 +20,7 @@ var defaultConfigValues = function() {
function Configuration (passed_options) {
var options = passed_options || {};
this._project = options.name || 'brewable';
this._projectConfigDir = path.join(home, this._project);
this._projectConfigDir = path.join(os.homedir(), this._project);
this.topicDirs = ['jobs', 'history', 'archive'];
this._configFileName = path.join(this._projectConfigDir, this._project + '.conf');
this._configuration = {};
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/modules/cpuinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(https://sourceforge.net/p/raspberry-gpio-python/code/ci/default/tree/source/cpuinfo.c)
*/

var fs = require("fs");
import fs from "fs";

function cpuinfo () {
this.possibleHardware = [
Expand Down
45 changes: 11 additions & 34 deletions src/scripts/modules/ds18b20.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ const FUDGE = Symbol();
// ds18b20Device object
class ds18b20Device {
constructor (val) {
//this.name = val;
//this.id = val;
this[DSNAME] = val;
this[FUDGE] = parseFloat(0.7);
this[FUDGE] = parseFloat(0.0);

console.log("ds18b20Device constructor() name = " + this.name);

//console.log('New ds18b20Device with id = ' + this.id + ', fudge = ' + this.fudge);
console.log('New ds18b20Device with id = ' + this.id + ', fudge = ' + this.fudge);
}

// Return a list of sensor devices
Expand All @@ -36,22 +32,22 @@ class ds18b20Device {
get id () { return this[DSNAME]; }

set fudge (fudgeFactor) {
this[FUDGE] = fudgeFactor;
this[FUDGE] = parseFloat(fudgeFactor);
}
get fudge () {
return this[FUDGE];
}

get temp () {
getTemp () {
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
var data = fs.readFileSync(dpath, 'utf8');
console.log('(ds18b20Device) ' + this.id + ' data = ' + data);
console.log('(ds18b20Device) fudge ' + this.fudge);
console.log('(ds18b20Device) ' + parseFloat(data.split(' ')[20].split('=')[1]) / 1000);
return parseFloat(this.fudge) + parseFloat(data.split(' ')[20].split('=')[1]) / 1000;
}

getTempAsync (callback) {
if (!arguments.length || arguments.length && typeof arguments[0] !== "function") {
return this.getTemp();
}
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
var id = this.id;
var fudge = this.fudge;
Expand All @@ -65,31 +61,12 @@ class ds18b20Device {
});
}

get temp () {
return this.getTemp();
}

}
export default ds18b20Device;


/*
ds18b20Device.prototype.getTempAsync = function (callback) {
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
var id = this.id;
var fudge = parseFloat(this.fudge);
fs.readFile(dpath, 'utf8', function (err, data) {
if (err) {
console.log('Error reading device data: ' + dpath);
} else {
var result = parseFloat(fudge) + parseFloat(data.split(' ')[20].split('=')[1]) / 1000;
callback(result, id);
}
});
};
ds18b20Device.prototype.getTemp = function () {
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
var data = fs.readFileSync(dpath, 'utf8');
console.log("getTemp(): " + parseFloat(data.split(' ')[20].split('=')[1]) / 1000);
return (parseFloat(this.fudge) +parseFloat(data.split(' ')[20].split('=')[1]) / 1000);
};
*/

/* ex:set ai shiftwidth=2 inputtab=spaces smarttab noautotab: */
12 changes: 4 additions & 8 deletions src/scripts/modules/fhem.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,13 @@ class fhemDevice {
// Check for existing configuration
var configObj = new Configuration();
var config = configObj.getConfiguration();
console.log("Configurations: " + JSON.stringify(config));
console.log("Configurations: " + Object.keys(config));
console.log("Configurations: " + Object.keys(config.iSpindels));

this.timeout;
for (var i=0;i<config.iSpindels.length;i++) {
console.log("Comparing " + config.iSpindels[i].name + " vs. " + raw.name);
//console.log("Comparing " + config.iSpindels[i].name + " vs. " + raw.name);
if (config.iSpindels[i].name == raw.name) {
this.timeout = 1000 * parseInt(config.iSpindels[i].timeout);
console.log("Comparing was OK");
//console.log("Comparing was OK");
break;
}
}
Expand Down Expand Up @@ -192,22 +189,21 @@ class fhemDevice {
60 * 60 * 1000 = 3600000
*/
deviceReaper (caller) {
//console.log("Reaping ... fhemDeviceList length = " + fhemDeviceList.length);
var reap = false;
var i;
for (i=0;i<fhemDeviceList.length;i++) {
if (fhemDeviceList[i].name == caller.name ) {
//console.log("dur: " + (new Date() - new Date(fhemDeviceList[i].stamp)));
//console.log("timeout = " + caller.timeout);
if ((new Date() - new Date(fhemDeviceList[i].stamp)) > caller.timeout ) {
console.log("Planning removal of " + fhemDeviceList[i].name + ", caller = " + caller.name);
//console.log("Planning removal of " + fhemDeviceList[i].name + ", caller = " + caller.name);
reap = true;
}
break;
}
}
if (reap ) {
console.log("Removing " + fhemDeviceList[i].name + ", caller = " + caller.name);
console.log("Reaping " + fhemDeviceList[i].name + ", caller = " + caller.name);
clearInterval(caller.reaper);
fhemDeviceList.splice(i, 1);
}
Expand Down
16 changes: 9 additions & 7 deletions src/scripts/modules/jobprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ function JobProcessor(options) {
job_status['running'] = 'recovered';
}

//this.jobSensorIds.forEach( function (sensor, index) {
// Apply fudges to job configuration
var fudges = options.parent.configObj.getConfiguration()['sensorFudgeFactors'];
var keys = Object.keys(fudges);
this.jobSensorIds.forEach( function (sensor) {
for (var sensorKey in keys) {
if (keys[sensorKey] == jSensors[sensor].name) {
console.log("Setting fudge of " + keys[sensorKey] + " to " + fudges[keys[sensorKey]]);
jSensors[sensor].fudge = fudges[keys[sensorKey]];
}
}
job_status['sensors'].push(sensor);
console.log("jobStatus() jSensors: " + JSON.stringify(jSensors));
//job_status[sensor] = jSensors[sensor].getTemp();
job_status[sensor] = jSensors[sensor].temp;
});
console.log("job_status: " + JSON.stringify(job_status));
Expand Down Expand Up @@ -210,7 +216,6 @@ JobProcessor.prototype.jobStatus = function (nowTime, obj) {
//obj.jobSensorIds.forEach( function (sensor, index) {
obj.jobSensorIds.forEach( function (sensor) {
job_status['sensors'].push(sensor);
//job_status[sensor] = obj.jobSensors[sensor].getTemp();
job_status[sensor] = obj.jobSensors[sensor].temp;
});
//console.log("job_status: " + JSON.stringify(job_status));
Expand Down Expand Up @@ -541,11 +546,8 @@ JobProcessor.prototype.temperatureAdjust = function (target) {
take the first sensor's reading into account at all.
*/
if (this.jobSensorIds.length == 1) {
//temp = this.jobSensors[this.jobSensorIds[0]].getTemp();
temp = this.jobSensors[this.jobSensorIds[0]].temp;
} else if (this.jobSensorIds.length > 1) {
//var temp0 = parseFloat(this.jobSensors[this.jobSensorIds[0]].getTemp());
//var temp1 = parseFloat(this.jobSensors[this.jobSensorIds[1]].getTemp());
var temp0 = parseFloat(this.jobSensors[this.jobSensorIds[0]].temp);
var temp1 = parseFloat(this.jobSensors[this.jobSensorIds[1]].temp);
var mswm = parseFloat(this.parent.configuration['multiSensorMeanWeight']);
Expand Down
3 changes: 1 addition & 2 deletions src/scripts/modules/jsogpio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
nodefs internal fs interface).
*/

//const cpuInfo = require('./cpuinfo');
import cpuInfo from './cpuinfo';
var fs = require('fs');
import fs from 'fs';


var cpuinfo = new cpuInfo();
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/modules/requestHandlers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require("fs");
var path = require('path');
import fs from "fs";
import path from 'path';
import { newReading } from './fhem.js';

function index(response) {
Expand Down
5 changes: 2 additions & 3 deletions src/scripts/modules/server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//var WebSocketServer = require('websocket').server;
//var createServer = require("http").createServer;
var http = require("http");
var url = require("url");
import http from "http";
import url from "url";
import { server as WebSocketServer } from "websocket";
//import http from "http";

function start(route, handle, clients, msgQueue, opts) {
var options = opts || {};
Expand Down

0 comments on commit ecaaf14

Please sign in to comment.