I could fix this with the same workaround as the PIR Sensor.
now its runnig but electron start up everything and crashes after loading all data.
Any idea howto debug this? ther is nothing in my error logs…
/var/log/messages:
pi@raspberrypi:~/MagicMirror/modules/temperature $ tail -f /var/log/messages
Sep 14 13:16:05 raspberrypi kernel: [706942.834881] gpiomem-bcm2835 3f200000.gpiomem: gpiomem device opened.
Sep 14 13:16:32 raspberrypi kernel: [706969.575020] gpiomem-bcm2835 3f200000.gpiomem: gpiomem device opened.
Sep 14 13:17:00 raspberrypi kernel: [706997.192894] gpiomem-bcm2835 3f200000.gpiomem: gpiomem device opened.
thats all… :-(
node_helper.js:
'use strict';
/* Magic Mirror
* Module: temperatur.js
*
* By Benjamin Angst
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
const sensorLib = require('node-dht-sensor');
module.exports = NodeHelper.create({
start: function () {
console.log('Temperatur helper started ...');
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
const self = this;
if (notification === 'REQUEST') {
var sensor = {
initialize: function () {
return sensorLib.initialize(22, 27);
},
read: function () {
var readout = sensorLib.read();
console.log('Temperature: ' + readout.temperature.toFixed(2) + 'C, ' +
'humidity: ' + readout.humidity.toFixed(2) + '%');
setTimeout(function () {
sensor.read();
}, 2000);
// Send Temperatur
self.sendSocketNotification('DATA',{
temp: readout.temperature.toFixed(2),
humidity: readout.humidity.toFixed(2)
});
}
};
if (sensor.initialize()) {
sensor.read();
} else {
console.warn('Failed to initialize sensor');
}
}
}
});
temperature.js
/* Magic Mirror
* Module: temperatur.js
*
* By Benjamin Angst
* MIT Licensed.
*/
Module.register("temperature",{
// Default module config.
defaults: {
gpioPIN: 27,
sensorType: 22, // Can be 22 or 11
prependString: "Temperatur ",
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
wrapper.innerHTML = "T: " + this.temperature + " °C / H: " + this.humidity + " %";
return wrapper;
},
start: function() {
this.temperature = 'fetching...';
this.sendSocketNotification('REQUEST');
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'DATA') {
this.temperature = payload.temp;
this.humidity = payload.humidity;
this.updateDom();
}
},
});