• 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. Baxer
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
B
Offline
  • Profile
  • Following 0
  • Followers 1
  • Topics 5
  • Posts 18
  • Groups 0

Baxer

@Baxer

3
Reputation
690
Profile views
18
Posts
1
Followers
0
Following
Joined Jul 14, 2017, 12:25 PM
Last Online Aug 24, 2018, 5:43 PM

Baxer Unfollow Follow

Best posts made by Baxer

  • RE: MMM-SL how to trigger update?

    @Jopyth I figured it out myself but thanks for the help, i used MMM-ModuleScheduler and put this

                     {
            module: 'MMM-ModuleScheduler',
            config: {
                notification_schedule: {
                    notification: 'UPDATE_SL',
                    schedule: '*/5 * * * *',
                    payload: {
                        type: "UPDATE_SL",
                        title: 'sl!',
                        action: "notification"
                    }
                }
            }
    

    to make it update every 5 minutes

    posted in Troubleshooting
    B
    Baxer
    Jul 20, 2017, 12:14 PM
  • RE: PM2 do not start at bootup on my RPI 2? Works fine on my RPI 3.

    @tomyboy96 said in PM2 do not start at bootup on my RPI 2? Works fine on my RPI 3.:

    errors in crontab file, can’t install.

    do you have the @reboot before pm2 start mm.sh if you dont try with that

    posted in Troubleshooting
    B
    Baxer
    Jul 19, 2017, 1:56 PM
  • RE: MMM-cryptocurrency - v1.4

    Is Bitcoin Cash available?

    posted in Utilities
    B
    Baxer
    Nov 26, 2017, 4:23 PM

Latest posts made by Baxer

  • RE: Stuck in development

    @patex said in Stuck in development:

    populate the standings object yourself

    If i would send the entire teams data how would i go about doing that? thx btw for the answer

    posted in Development
    B
    Baxer
    May 5, 2018, 8:51 PM
  • Stuck in development

    So im trying to build my own module without any real programming experence. With help from This post and MagicMirror-Module-Template i have gotten really really far but right now im stuck, im getting the results from the api in the console instead of it printing on the screen
    Any help would be greatly appreciated

    SHL.js

    Module.register("SHL", {
    	defaults: {
    		updateInterval: 60000,
    		retryDelay: 5000
    	},
    
    	requiresVersion: "2.1.0", // Required version of MagicMirror
    
    	start: function() {
    		var self = this;
    		var dataRequest = null;
    		var dataNotification = null;
    
    		//Flag for check if module is loaded
    		this.loaded = false;
    
    		// Schedule update timer.
    		this.getData();
    		setInterval(function() {
    			self.updateDom();
    		}, this.config.updateInterval);
    	},
    
    	/*
    	 * getData
    	 * function example return data and show it in the module wrapper
    	 * get a URL request
    	 *
    	 */
    	getData: function() {
    		var self = this;
    
    		var urlApi = "https://jsonplaceholder.typicode.com/posts/1";
    		var retry = true;
    
    		var dataRequest = new XMLHttpRequest();
    		dataRequest.open("GET", urlApi, true);
    		dataRequest.onreadystatechange = function() {
    			console.log(this.readyState);
    			if (this.readyState === 4) {
    				console.log(this.status);
    				if (this.status === 200) {
    					self.processData(JSON.parse(this.response));
    				} else if (this.status === 401) {
    					self.updateDom(self.config.animationSpeed);
    					Log.error(self.name, this.status);
    					retry = false;
    				} else {
    					Log.error(self.name, "Could not load data.");
    				}
    				if (retry) {
    					self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay);
    				}
    			}
    		};
    		dataRequest.send();
    	},
    
    
    	/* scheduleUpdate()
    	 * Schedule next update.
    	 *
    	 * argument delay number - Milliseconds before next update.
    	 *  If empty, this.config.updateInterval is used.
    	 */
    	scheduleUpdate: function(delay) {
    		var nextLoad = this.config.updateInterval;
    		if (typeof delay !== "undefined" && delay >= 0) {
    			nextLoad = delay;
    		}
    		nextLoad = nextLoad ;
    		var self = this;
    		setTimeout(function() {
    			self.getData();
    		}, nextLoad);
    	},
    
    	getDom: function() {
    		var self = this;
    
    		// create element wrapper for show into the module
    		var wrapper = document.createElement("div");
    		// If this.dataRequest is not empty
    		if (this.dataRequest) {
    			var wrapperDataRequest = document.createElement("div");
    			// check format https://jsonplaceholder.typicode.com/posts/1
    			wrapperDataRequest.innerHTML = this.dataRequest.title;
    
    			var labelDataRequest = document.createElement("label");
    			// Use translate function
    			//             this id defined in translations files
    			labelDataRequest.innerHTML = this.translate("TITLE");
    
    
    			wrapper.appendChild(labelDataRequest);
    			wrapper.appendChild(wrapperDataRequest);
    		}
    
    		// Data from helper
    		if (this.dataNotification) {
    			var wrapperDataNotification = document.createElement("div");
    			// translations  + datanotification
    			wrapperDataNotification.innerHTML =  this.translate("UPDATE") + ": " + this.dataNotification.date;
    
    			wrapper.appendChild(wrapperDataNotification);
    		}
    		return wrapper;
    	},
    
    	getScripts: function() {
    		return [];
    	},
    
    	getStyles: function () {
    		return [
    			"SHL.css",
    		];
    	},
    
    	start: function () {
    		this.sendSocketNotification("GET_STANDINGS")
    	},
    
    	// Load translations files
    	getTranslations: function() {
    		//FIXME: This can be load a one file javascript definition
    		return {
    			en: "translations/en.json",
    			es: "translations/es.json"
    		};
    	},
    
    	processData: function(data) {
    		var self = this;
    		this.dataRequest = data;
    		if (this.loaded === false) { self.updateDom(self.config.animationSpeed) ; }
    		this.loaded = true;
    
    		// the data if load
    		// send notification to helper
    		this.sendSocketNotification("SHL-NOTIFICATION_TEST", data);
    	},
    
    	// socketNotificationReceived from helper
    	socketNotificationReceived: function (notification, payload) {
    		if(notification === "STANDINGS"){
    			// set dataNotification
    			this.dataNotification = payload;
    			this.updateDom();
    		}
    	},
    });
    

    node_helper.js

    
    var NodeHelper = require("node_helper");
    const shl = require("open-shl");
    const client = shl.connect({
        clientId:"XXXX", 
        clientSecret:"XXXX"
    });
    
    module.exports = NodeHelper.create({
    	
    	
    	teamStandings: function() {
    			  client.season(2017).statistics.teams.standings({teamIds: []})
    			     .then(teams => {
          			for (i = 0; i < 14; i++) {
            			a = i + 1;
           			  console.log(a + ": " + teams[i].team_code);
         				 };
    				     var standings = {};
    				     this.sendSocketNotification('STANDINGS', standings);
     			 });
    		},
    	// Override socketNotificationReceived method.
    
    	/* socketNotificationReceived(notification, payload)
    	 * This method is called when a socket notification arrives.
    	 *
    	 * argument notification string - The identifier of the noitication.
    	 * argument payload mixed - The payload of the notification.
    	 */
    	socketNotificationReceived: function(notification, payload) {
    		if (notification === "SHL-NOTIFICATION_TEST") {
    			// console.log("Working notification system. Notification:", notification, "payload: ", payload);
    			console.log("Working notification system.", notification) 
    		}
    		if (notification === "GET_STANDINGS"){
    			this.teamStandings();
    		}
    	},
    
    	// this you can create extra routes for your module
    	extraRoutes: function() {
    		var self = this;
    		this.expressApp.get("/SHL/extra_route", function(req, res) {
    			// call another function
    			values = self.anotherFunction();
    			res.send(values);
    		});
    	},
    
    	// Test another function
    	anotherFunction: function() {
    		return {date: new Date()};
    	}
    });
    
    
    posted in Development
    B
    Baxer
    Apr 23, 2018, 5:18 PM
  • RE: Creating a module with existing Nodejs client?

    @ninjabreadman Thanks for the explanation!!

    posted in Development
    B
    Baxer
    Feb 21, 2018, 8:30 AM
  • Creating a module with existing Nodejs client?

    Is it possible to create a module with a existing Nodejs Client?

    posted in Development
    B
    Baxer
    Feb 20, 2018, 7:36 PM
  • Help getting started

    I trying to create a module for stats from the Swedish hockey league, im new to programming but im trying to learn as i go since there is such good documentation on creating a module, but im wondering one thing
    The Api from SHL already have a npm client and as i understand the files in the “lib” subfolder handles all the connection.
    How do i make so my module to load these files?

    posted in Development
    B
    Baxer
    Dec 7, 2017, 5:49 PM
  • RE: MMM-cryptocurrency - v1.4

    Is Bitcoin Cash available?

    posted in Utilities
    B
    Baxer
    Nov 26, 2017, 4:23 PM
  • RE: MMM-SL how to trigger update?

    @Jopyth I figured it out myself but thanks for the help, i used MMM-ModuleScheduler and put this

                     {
            module: 'MMM-ModuleScheduler',
            config: {
                notification_schedule: {
                    notification: 'UPDATE_SL',
                    schedule: '*/5 * * * *',
                    payload: {
                        type: "UPDATE_SL",
                        title: 'sl!',
                        action: "notification"
                    }
                }
            }
    

    to make it update every 5 minutes

    posted in Troubleshooting
    B
    Baxer
    Jul 20, 2017, 12:14 PM
  • RE: MMM-SL how to trigger update?

    @Jopyth Holy shit it works, thanks man
    the reason the author doesnt think the timer is a good idea its because the API have an maximum amount of calls you can make in a month which is 30 000, but if i wanted to go against his advice and make it update every 5 minute or so, how would i do that

    posted in Troubleshooting
    B
    Baxer
    Jul 20, 2017, 12:02 PM
  • RE: MMM-SL how to trigger update?

    @Mykle1 thanks for the tips unfortunately i dont have a button to test this with.

    posted in Troubleshooting
    B
    Baxer
    Jul 19, 2017, 11:57 PM
  • RE: PM2 do not start at bootup on my RPI 2? Works fine on my RPI 3.

    @tomyboy96 said in PM2 do not start at bootup on my RPI 2? Works fine on my RPI 3.:

    errors in crontab file, can’t install.

    do you have the @reboot before pm2 start mm.sh if you dont try with that

    posted in Troubleshooting
    B
    Baxer
    Jul 19, 2017, 1:56 PM
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