• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
  1. Home
  2. Squawk09
  3. Posts
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
S
Offline
  • Profile
  • Following 0
  • Followers 0
  • Topics 1
  • Posts 2
  • Groups 0

Posts

Recent Best Controversial
  • RE: sendNotification & notificationReceived does not seem to work, am I missing something.

    @strawberry-3.141 Yes, pasted below are the two files. I am new to JS modules and node.js servers so I was not aware you had to log if you’re receiving a notification. What are you notifying and where do you declare the notification? Do you know of any good documentation on this? I pasted in the code ianperrin suggested to see if it would work but it still displays this.temp as undefined. I must be missing something basic. Thanks for the help!

    /* global Module */
    
    /* Magic Mirror
     * Module: Bike
    
     * MIT Licensed.
     */
    
    Module.register("bike",{	
    
    // Default module config.
    defaults: {
    	text: "Hello good!"	
    },
    start: function() {
    	this.temp = "This should change";
    },
    notificationReceived:function(notification, payload, sender) {
        if (notification === 'Temperature' && sender.name === 'currentweather') {
            var currentweather = payload;
            if ( currentweather && currentweather.hasOwnProperty('temperature') ) {
                this.temp = currentweather.temperature;
                Log.log('The current temperature is ' + currentweather.temperature);
            }
        }
    },	
    // Override dom generator.
    getDom: function() {
    	var wrapper = document.createElement("div");
    	var myTemp = document.createElement("div");
    	myTemp.innerHTML=this.temp;
    	
    	wrapper.innerHTML = this.config.text;
    	wrapper.appendChild(myTemp);
    	return wrapper;
      }
    });
    

    Here is the current weather function that contains the submission.

    processWeather: function(data) {
    	this.temperature = this.roundValue(data.main.temp);
    	
    	if (this.config.useBeaufort){
    		this.windSpeed = this.ms2Beaufort(this.roundValue(data.wind.speed));
    	}else {
    		this.windSpeed = parseFloat(data.wind.speed).toFixed(0);
    	}
    
    
    	this.windDirection = this.deg2Cardinal(data.wind.deg);
    	this.weatherType = this.config.iconTable[data.weather[0].icon];
    
    	var now = new Date();
    	var sunrise = new Date(data.sys.sunrise * 1000);
    	var sunset = new Date(data.sys.sunset * 1000);
    
    	// The moment().format('h') method has a bug on the Raspberry Pi.
    	// So we need to generate the timestring manually.
    	// See issue: https://github.com/MichMich/MagicMirror/issues/181
    	var sunriseSunsetDateObject = (sunrise < now && sunset > now) ? sunset : sunrise;
    	var timeString = moment(sunriseSunsetDateObject).format('HH:mm');
    	if (this.config.timeFormat !== 24) {
    		//var hours = sunriseSunsetDateObject.getHours() % 12 || 12;
    		if (this.config.showPeriod) {
    			if (this.config.showPeriodUpper) {
    				//timeString = hours + moment(sunriseSunsetDateObject).format(':mm A');
    				timeString = moment(sunriseSunsetDateObject).format('h:mm A');
    			} else {
    				//timeString = hours + moment(sunriseSunsetDateObject).format(':mm a');
    				timeString = moment(sunriseSunsetDateObject).format('h:mm a');
    			}
    		} else {
    			//timeString = hours + moment(sunriseSunsetDateObject).format(':mm');
    			timeString = moment(sunriseSunsetDateObject).format('h:mm');
    		}
    	}
    
    	this.sunriseSunsetTime = timeString;
    	this.sunriseSunsetIcon = (sunrise < now && sunset > now) ? "wi-sunset" : "wi-sunrise";
    
    	this.sendNotification('Temperature', {temperature:this.temperature});
    
    	this.loaded = true;
    	this.updateDom(this.config.animationSpeed);
    },
    
    posted in Development
    S
    Squawk09
    Sep 26, 2016, 11:59 PM
  • sendNotification & notificationReceived does not seem to work, am I missing something.

    Ok,

    I am making a module that wants to use the current temperature from the default Currentweather module. In the README file for modules it appears that I can just have the currentweather module call the sendNotification() function and my module will receive it with the notificationReceived() function. For example,

    In the currentweather.js file:

    this.sendNotification('Temperature', {temperature:this.temperature});
    

    In the receiving .js file:

    notificationReceived: function(notification, payload) {
    	if(notification === 'Temperature')
    			this.temp=notification;
    },
    

    Am I missing something? I dont think I would have to create a node_helper to have one module send a payload to another. The issue I am getting is that this.temp remains undefined and I don’t know why this is happening.

    Thanks!

    posted in Development sendnotification
    S
    Squawk09
    Sep 26, 2016, 1:34 AM
  • 1 / 1
Enjoying MagicMirror? Please consider a donation!
MagicMirror created by Michael Teeuw.
Forum managed by Sam, technical setup by Karsten.
This forum is using NodeBB as its core | Contributors
Contact | Privacy Policy