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

    Topics

    • M

      Wunderlist shuts down May 6th

      Watching Ignoring Scheduled Pinned Locked Moved General Discussion
      9
      1 Votes
      9 Posts
      2k Views
      lavolp3L
      @thobach are you still working on MMM-MicrosoftToDo. I’d like to start now to implement it (faced first reference errors) and have several things in mind I would like to add. touch support Keyboard input multiple list Before messing too much with your code I’d like to know if you still aim to develop further.
    • M

      Module not updating data, other modules work fine, how to debug?

      Watching Ignoring Scheduled Pinned Locked Moved Solved Troubleshooting
      2
      0 Votes
      2 Posts
      600 Views
      M
      So i ended up looking at pullrequests on the module and it looks like someone already made a fix for this. sorry for wasting forum space :) this should be a fix https://github.com/funsocietyirc/MMM-Wunderlist-Enhanced/pull/18/files
    • M

      help developing an outofmilk.com module

      Watching Ignoring Scheduled Pinned Locked Moved Development
      8
      0 Votes
      8 Posts
      2k Views
      D
      Uh, interesting topic. I like API calls. :D Back when I started, my main issue was understanding the node_helper.js – and that it was neccessary. I’m still struggling to make sense of your token complexity. Apart from that, your files would be something like this: MMM-OutOfMilk.js: Module.register("MMM-OutOfMilk",{ defaults: { // your defaults }, start: function() { var payload = "start"; // example this.sendSocketNotification("GetMyShoppingList", payload); }, socketNotificationReceived: function(notification, shoppingList) { if (notification === "ShoppingListRecieved") { this.handeShoppingList(shoppingList); } }, handleShoppingList: function(shoppingList) { // do something with your shopping list } } node_helper.js: var NodeHelper = require("node_helper"); var request = require("request"); // needed? see below var fs = require("fs"); // needed? see below var timer = 0; // needed? see below "I added a timer" var token; module.exports = NodeHelper.create({ start: function() { }, socketNotificationReceived: function(notification, payload) { if (notification === "GetMyShoppingList") { // start the logic to recieve the shopping list // get token? // make call this.getShoppingList(payload); } }, getToken: function(payload) { // however you get your token getShoppingList(payload); }, getShoppingList: function(payload) { var self = this; var source = ; // your source URL if (token) { request({ url: source, json: true }, function (error, response, body) { if (!error && response.statusCode === 200) { self.sendSocketNotification("ShoppingListRecieved", body); } else { // check error if it's a token issue // if so, get new token self.getToken(payload); } }) } } } From another project I know that sometimes a token can be used for a while. In that case I’d directly call the getShoppingList and only on an error that read “wrong token” or something like that, I’d call getToken which saves the token to a global variable and calls back getShoppingList to try again. That way you don’t have to get a new token for every call. Alternatively? getShoppingList: function(token) { var self = this; var source = ; // your source URL var rawdata = fs.readFileSync(source); var history = JSON.parse(rawdata); self.sendSocketNotification("ShoppingListRecieved", history); } I’d also use a timer to request data on the first call and after that automatically only every full hour: So, in the node_helper.js, in the socketNotificationReceived I don’t forward the payload to this.updateTimer(payload) instead of getToken or getShoppingList to do this: updateTimer: function(payload) { var self = this; var d = new Date(); var h = d.getHours(); var min = d.getMinutes(); var sec = d.getSeconds(); if (timer === 0) { timer ++; // prevent unnecessary timer by double calls this.getShoppingList(payload); if((min == '00') && (sec == '00')){ // console.log(h + ":" + min + ":" + sec + " - update and wait 1 hour"); // console.log("restart timer"); setTimeout(() => { this.clearTimer(payload); }, 60*1000*60); // 60 sec * 1000 ms = 1 min * 60 = 1 hour } else { // console.log(h + ":" + min + ":" + sec + " - update waits for " + (59-min) + " min and " + (60-sec) + "sec"); // console.log("restart timer"); setTimeout(() => { this.clearTimer(payload); }, ((60-sec)*1000)+(60*1000*(59-min))); } } else { // console.log("timer already running, data displayed outside of timer run"); this.getShoppingList(payload); } }, clearTimer: function(payload) { timer --; this.updateTimer(payload); } For one of my modules I couldn’t use fs.readFile... or request because of CORS issues. In that case I had to use a php proxy. I’d strongly suggest trying to solve this with fs.readFile... or request but just for the sake of completeness and maybe to help you understand: In order to use PHP within nodeJS via Child Process Dependency you have to have PHP installed and in your PATH! You can read how I used it, here: https://forum.magicmirror.builders/topic/5830/call-api-no-cors-used-to-do-it-with-php-proxy/9
    • 1 / 1