A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
  • How to best process an [object Promise]?

    9
    0 Votes
    9 Posts
    3k Views
    E
    I’ve got a partially working function, but it’s a bit funny. For some reason the call to cleanup the JSON is not liked, because it seem that the actual result is not returned, but the Promise . This is the code snippet: radarPing: function() { console.log("ENTER (inside)"); Promise.all([ radar(-8.20917,114.62177,-9.28715,115.71243) ]).then(function(results) { var ping = results; console.log("PING1:"); console.log(ping); var cleanData = jZen(ping); console.log("PING2: ", cleanData); self.sendSocketNotification("NEW_DATA", ping); //"PING" return cleanData; //ping; }); console.log("EXIT (inside)"); }, readData: function() { //const myfile = 'modules/MMM-FlightsAbove/demo.json'; // The demo API use improper JSON var radarData = ""; radarData = this.radarPing(); console.log("The DATA:\n", radarData); /* if ( radarData === "" ) { } */ //let cleanData = jZen(data); //let cleanData = jZen(radarData); let cleanData = radarData; if (isJSON(cleanData) ) { this.sendSocketNotification("NEW_DATA", cleanData); } else { // So WTF is it? console.log("- JSON: false"); console.log("- isAO(dirty): " + isAO(radarData)); console.log("- isAO(clean): " + isAO(cleanData)); console.log("- Data:\n", radarData); } }, ... }); // To check if something is JSON function isJSON(str) { try { return (JSON.parse(str) && !!str); } catch (e) { return false; } } // To check if something is an Array or Object (parsed JSON) function isAO(val) { return val instanceof Array || val instanceof Object ? true : false; } // -------------------------------------------------------------------------- // What: A dirt simple JSON cleanup function that also compactifies the data // NOTE: - Only use on flat and trustworthy ASCII JSON data! // - Cannot handle any characters outside [A-Za-z0-9_\-]. (e.g. UTF-8) // - Using remote data without further sanitation is a security risk! // -------------------------------------------------------------------------- const re1 = /([A-Za-z0-9_\-]+):/gm; // use const to make sure it is compiled function jZen(juice) { //let re1 = /([A-Za-z0-9_\-]+):/gm; // Find all ASCII words $1 before an ":" //let data = juice; let str = ""; str = juice.replace(/\s/gm, ''); // Remove all white-space str = str.replace(/\'/gm, '\"'); // Replace all ' with " str = str.replace(re1, '\"$1\":'); // Replace $1: with "$1": //console.log("Dirty JSON is:\n" + data.toString() ); //console.log("Clean JSON is:\n" + str); return str; } The output is: ... ENTER (inside) EXIT (inside) The DATA: undefined - JSON: false - isAO(dirty): false - isAO(clean): false - Data: undefined PING1: [ [ { id: '108be389', timestamp: 1519647028, registration: 'PK-GQL', flight: 'QG8816', callsign: 'CTV8816', ... As you can see, PING2 never happens…
  • How to pass a value between functions in a Module?

    5
    0 Votes
    5 Posts
    2k Views
    D
    getDom: function() is called initially to set up the content. Usually you have something like div.innerHTML = variable; but at the beginning, varibable might be empty. To make the variable usable globally (in the scope of your module), you set it up and call it as this.variable. When your function that fills this variable updates that variable content, you call updateDom(); That makes the dom reload and this time, this.variable has content to show. There’s other ways to fill the element with the content of a variable without totally rebuilding the DOM: In the function that handles the variable, you could say document.getElementbyId(elementId).innerHTML = variable; Edit: To complete this. If you want to pass a value from one function to another (but this is not working for the Dom, because that has to be set up initially): firstFunction: function () { var greeting: "Hello"; secondFunction(greeting); } secondFunction: function (word) { var greeting: word; Log.info(greeting); // "Hello" }
  • 0 Votes
    2 Posts
    2k Views
    goonerbeatyaaG
    search the forum for " how-to-add-modules-for-absolute-beginners "
  • I got sucked up into a magic mirror! (and need some help)

    14
    0 Votes
    14 Posts
    7k Views
    E
    @raywo It’s now working and I’ve pushed all updates to repo. :) My first module…that does nothing. :D
  • Creating a module with existing Nodejs client?

    3
    0 Votes
    3 Posts
    1k Views
    B
    @ninjabreadman Thanks for the explanation!!
  • What is the difference between require() and getScripts()?

    7
    0 Votes
    7 Posts
    3k Views
    Mykle1M
    @cowboysdude Both? ;-)
  • What is the difference between these function definitions?

    3
    0 Votes
    3 Posts
    2k Views
    E
    @ninjabreadman Fantastic! Again, the best explanation I’ve heard! I love that juice analogy! Thank you so much for having patience with all my dumb questions. Surely a lot of them are trivial to most developers. (If you’re a moderator, feel free to mark this as solved.)
  • What is the startup order in a Module with node_helper.js?

    1
    0 Votes
    1 Posts
    737 Views
    E
    What is the exact startup order of a module? What is processed first and how can I learn/understand the process?
  • Adding a jQuery Module

    7
    0 Votes
    7 Posts
    4k Views
    E
    @NiviJah Did you get jQuery to run at all?
  • 0 Votes
    3 Posts
    2k Views
    E
    @ninjabreadman Hi! Thanks, I knew about that, but was hoping to use the default lxterminal, but unfortunately it only allows --geometry=CHARACTERSxLINES as option. Your solution of using rxvt-unicode seem pretty good as it supports 256 colors etc. However, in the end, I decided that I’d rather have a native MMM, than just throwing a window on top of everything. That complicates things though. I simply don’t see how to go about implementing the JS version of xterm into a Module. Perhaps something to suggest in the requests area? Anyway, could be useful for all those people and command-line junkies, who want to see their raw python output.
  • Weather Forecast - maxNumberOfDays

    2
    0 Votes
    2 Posts
    1k Views
    R
    What count is return when requesting: https://api.openweathermap.org/data/2.5/forecast/daily?id=1234567&APPID=$APPID What is the max count possible: https://api.openweathermap.org/data/2.5/forecast/daily?id=1234567&APPID=$APPID&cnt=$COUNT
  • Module Developer Challenge - I surrender!

    Solved
    33
    0 Votes
    33 Posts
    19k Views
    cowboysdudeC
    @Mykle1 said in Module Developer Challenge - I surrender!: @E3V3A said in Module Developer Challenge - I surrender!: I’m very impressed with your progress. I appreciate that. Frankly, I’m amazed that I’ve gotten any of my modules to work. I joined this forum 13 months ago without the slightest idea of what linux or a raspberry pi even was. I realized quickly enough that I wanted to learn how things worked and started reading and asking questions. With the help of some very nice people I was able to make my first module, MMM-Cocktails. At this point, I was totally hooked. It’s still magic to me and I enjoy every minute of the learning process. HEYYYYYYYYYYYYYYYY hands above the desk…ABOVE…LOL
  • Homematic XMLAPI read system variable

    1
    0 Votes
    1 Posts
    844 Views
    M
    Hello, I just started with my first magic mirror project and I’m already using Homematic to control my smart home. Within there I have many system variables in order to summarize the status of several actors and collect informations. Now I want to display these variables on my mirror and for sure there must be a solution to access this via XMLAPI but until now I did not find the right way … I saw already two solutions in this forum to display actors (devices not variables) in the mirror, and I spend some hours to use them as a basis, but however I was not able to rework them by myself. Maybe someone of you has already a solution in place or can support me here to get such kind of variable data out of the Homematic XMLAPI?
  • Display values from a JSON file hosted online

    10
    0 Votes
    10 Posts
    6k Views
    E
    @yawns Was that re-load issue ever resolved? I have my own basic issues and I’m considering using this code instead…
  • Display a .png saved on the raspberry pi hard drive

    8
    0 Votes
    8 Posts
    5k Views
    N
    @snowman @cruunnerr You’re right. It is however baked into MMM-SimpleLogo. There is a time stamp query parameter appended to the image, so that it fetches a new version every time and does not load the cached version. Also, it has a refreshInterval config parameter to set how often it updates (e.g. "5*60*1000" for 5 minutes).
  • How to input a text from the user?

    keyboard input
    1
    0 Votes
    1 Posts
    1k Views
    H
    Dear all, I can imagine this is not a hard problem, but I haveing trouble to solve this. I am using the face recognition and when a face is detected, I would like to user to input his name. If the face is known, the view will switch to a personalized content. Can anybady help me, please?
  • Getting keyboard input

    2
    0 Votes
    2 Posts
    2k Views
    H
    Did you find a solution? I will make a new post because I have the same issue.
  • Newsfeeds module

    4
    0 Votes
    4 Posts
    2k Views
    S
    it worked ty
  • Wrote 2 modules already, but don't know where to start for another...

    4
    0 Votes
    4 Posts
    2k Views
    D
    Check the code of those modules that can switch modules on/off (if they don’t just hide them, that is). Basically, after changing the config, the browser has to be refreshed in order to load the the new configuration. What you want could be compared to that. Instead of removing a module, you change the language.
  • Simple welcome script

    4
    0 Votes
    4 Posts
    2k Views
    cruunnerrC
    You’re welcome ;)