• 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. mattlugar
  3. Posts
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 2
  • Posts 18
  • Groups 0

Posts

Recent Best Controversial
  • RE: readFileSync

    @KirAsh4 Yeah, it is working for me as I want it. I figured it wouldn’t be overly useful to others anyhow since there was a lot of back-end work to do (namely setting up json streams that match the module code from the weather station, uploading to an appropriate location).

    Screenshot of my current display is below. It updates every 5 seconds using data from my local Davis weather station running Cumulus software. The rain information (total daily rain on top left, current rain rate at bottom left) only display if there has been rain today or it is currently raining respectively. It will also display winds like “12 G23” if the winds hit gust criteria (over 18MPH gusts and more than 10MPH over the wind speed). It is pretty trivial to put any information you can get into the json file to display.

    I’d be happy to try to properly modularize this if there is some interest, there’s just so many options and variations of stations/json exports/etc that I’m not sure I’d know where to start.

    alt text

    posted in Development
    M
    mattlugar
    May 19, 2016, 7:04 PM
  • RE: Weatherforecast Wunderground module question

    I’m modifying for wunderground now too. I’m finding openweathermap horribly wrong sometimes (today they say showers here and every other forecast system says sun).

    posted in Development
    M
    mattlugar
    May 19, 2016, 11:07 AM
  • RE: readFileSync

    Yeah, I went about it differently than I wanted to. I ended up porting everything to an apache directory so it serves itself as a webapp. Had a few bugs to work out (it was locking up if the json was in the middle of writing when it was retrieved) but I have it working and bug free now best I can tell :)

    posted in Development
    M
    mattlugar
    May 19, 2016, 12:54 AM
  • RE: readFileSync

    That’s where my lack of knowledge on how to debug in this new environment was hurting me. Was able to figure out a better way to debug and now have something to work with.

    Uncaught ReferenceError: require is not defined
    

    Off to roll up my sleeves and do some mad google-fu.

    Thank you! :)

    posted in Development
    M
    mattlugar
    May 18, 2016, 2:26 PM
  • readFileSync

    I’ll preface this by saying I’m fairly new at nodejs, so maybe I’m doing something totally stupid. I’ve been beating my head on this for a while now… Not making any sense to me whatsoever, googling like crazy and still totally stuck.

    I have bigger plans (reading a locally updated JSON file and displaying frequently updated data to the screen), but as nothing seemed to work I kept paring and paring the project back to where I’m now simply trying to display static contents of a local file to the screen. I altered helloworld to try to do this simple task. Note that the file ‘/home/pi/test.txt’ is simply the word “test”, and has permissions set to where anyone can read it. I’m also loading other modules just so I know something’s working.

    The following code locks up the mirror, displaying simply a black screen. Note that I am not even attempting to display the file at this point, I’m simply trying to load it into the variable ‘file’.

    Module.register("helloworld",{
    
            getDom: function() {
                    var wrapper = document.createElement("div");
                    var file = require('fs').readFileSync('/home/pi/test.txt', 'utf8');
                    wrapper.innerHTML = "Hello";
                    return wrapper;
            }
    });
    

    I can tell that the issue is my loading line because I can comment it out thusly and all the modules display, including the “Hello” text:

    Module.register("helloworld",{
    
            getDom: function() {
                    var wrapper = document.createElement("div");
    //              var file = require('fs').readFileSync('/home/pi/test.txt', 'utf8');
                    wrapper.innerHTML = "Hello";
                    return wrapper;
            }
    });
    

    OK, so maybe there’s a problem with my loading statement. Easy to check, copy/past the line into a js file and run it:

    test.js:

    var file = require('fs').readFileSync('/home/pi/test.txt', 'utf8');
    console.log(file);
    

    And here’s what happens:

    pi@lugarpi:~ $ nodejs test.js
    test
    

    Works perfectly fine in nodejs but if I put that line of code into the module it locks up the mirror. Am I missing something here? Also, I’m launching mirror through pm2. I understood any errors should show up in ~/.pm2/logs but the error log doesn’t show anything.

    posted in Development
    M
    mattlugar
    May 17, 2016, 8:43 PM
  • RE: Load data from json file

    @paviro Ah, well thanks for the feedback. I’m hoping to get a bit of a hybrid between that app and pulling data from my own weather station. I’d like to keep the sunrise/sunset and the current conditions coming in from openweathermap and put my own station’s temp/wind. Was thinking modifying his would be a little easier than from scratch. :) Maybe I’ll get lucky and he’ll see this and point me in the right direction.

    posted in Development
    M
    mattlugar
    May 16, 2016, 9:51 PM
  • RE: Load data from json file

    @paviro Difference on mine is I’m pulling in a straight value from a text file, not JSON. The file is a text file that has current temperature. No markups tags or anything else.

    I’m no expert at Java so maybe I’m missing something?

    posted in Development
    M
    mattlugar
    May 16, 2016, 9:20 PM
  • RE: Load data from json file

    I’m not exactly in the same boat, but similar I guess… Maybe we can put our heads together or someone more knowledgeable will notice the thread…

    I’ve got a local weather station that I have putting plain text data (for temperature) on the SD card of MagicMirror . My goal is to put a ‘realtime’ (updated every minute or so) temperature on the display, directly from my own weather station.

    As an initial step to test this out, I went into currentweather.js and changed the following in the processWeather function:

    Removed:

    this.temperature = this.roundValue(data.main.temp);
    

    Added:

     var fs = new require('fs');
     this.temperature = fs.readFileSync('/var/www/html/wx/temp.txt');
    

    I anticipated that this would put the contents of my file in place of the temperature data from openweathermap. Unfortunately, it results in the currentweather module sticking at Loading...

    Just to check I’m not insane, I replaced my code with:
    this.temperature = '56.0';

    The module loads with 56.0 as the temperature. This leads me to believe I’m having an issue reading the file from disk. I threw together a quick js file to test I’m doing the fs.readFileSync command right:

    var sys = require("sys");
    var fs = new require('fs');
    var temp = fs.readFileSync('/var/www/html/wx/temp.txt');
    sys.puts(temp);
    

    Low and behold, my file contents show up just fine.

    As far as I can tell, this SHOULD work, but it clearly isn’t. Maybe you and I are running into similar issues reading from file? Anyone out there that can assist us?

    posted in Development
    M
    mattlugar
    May 16, 2016, 5:06 PM
  • 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