Smart Mirror complete walkthrough

Required Equipment:

Step 1: Setting up the Pi

Meteor:

The Raspberry Pi came with instructions on getting it up and running but to install the Meteor Platform I used for creating the app I had to follow this guide. Most other smart mirror tutorials don’t use Meteor so don’t have this step.

Chromium:

You need this web browser because it is easy to get it set up in “kiosk” (full screen) mode. It’s also useful since it has a javascript console so that made it easy to add documents into the Mongo DB. The link above was the best way I could find to get it installed. Next I needed to get Chromium to launch in kiosk mode when the Raspberry Pi boots up (without the spaces, wordpress won’t let me post that string of text for some reason):

 

sudo nano / etc / xdg / lxsession /  LXDE-pi / autostart

 

Disable the screen saver by commenting out the following line:

#screensaver -no-splash

Then add the following line to the end of the file:

@xset s off @xset -dpms @xset s noblank / usr / bin / chromium --noerrdialogs --kiosk --incognito "http://localhost:3000"

To get rid of the mouse cursor:

 sudo apt-get install unclutter

Rotating the display:

 sudo nano / boot / config.txt

At the bottom of this file add:

 DISPLAY_ROTATE=X

Where X is: 0, 1, 2, 3 corresponding to no rotation, 90 degrees, 180 degrees, 270 degrees of rotation.

Step 2: The application

The code for my application was based on the code from github user lambtron. The biggest change I made was to add the random compliment at the bottom of the mirror. The javascript to do this:


if (Meteor.isClient){
   var ONE_MIN = 1 * 60 * 1000;
   var chooseRandom = function() {
   var compliments = Compliments.find().fetch();
   var randomComp = Random.choice(compliments);
   Session.set('currentComp', randomComp);
};
Template.compliments.helpers({
   compliment: function() {
      var c = Compliments.findOne(Session.get('currentComp'));
      return c.text;
      }
});
Template.compliments.created = function() {
   this.handle = Meteor.setInterval(chooseRandom, ONE_MIN);
};
Template.compliments.destroyed = function() {
   Meteor.clearInterval(this.handle);
   };
}

I’ve been running the app locally on the raspberry pi and just pointing the browser to localhost:3000. I can update the app via ssh when I am at home on my local wifi but I don’t seem to be able to ssh to the pi from anywhere else. I’ve also had problems adding content to the database from a command prompt. I can however attach a mouse and keyboard and update the database through a javascript console in the browser.

So far this has been working well but I have since updated the app to include an admin panel and I could move it to a digital ocean droplet for $5/month which would give me better access to the database.

Mirror Website

I’ve managed to make a Meteor application that displays the current day, time, weather and a random compliment:

Screen Shot 2016-01-07 at 3.37.12 PMGetting the random compliment took the most time. I spent a lot of time trying to find out how to return a random document from the compliments collection I created. I found quite a few posts online but none seemed to work. I could return an object but it was not displaying the text of that object. In the end it was as simple as changing from find() to findOne().

Next I want to have it check the date and display custom messages such as “Happy Birthday”, “Happy Anniversary”, “Merry Christmas”, etc.

I also set up the Raspberry Pi this week. I want to see if I can get Meteor running on it. If so I can just have the application running locally on the Pi and point its browser to the localhost. I did find this walk-through online.  If not I can deploy it to Digital Ocean which may be the better choice in the end as I can update the database easily that way.

Raspberry Pi, Littlebits and Meteor

So I haven’t been teaching for the past few years due to lack of enrolment in continuing education (SD38 continuing ed has stopped offering all math and science based night school courses!) hence the lack of any new posts on this blog. Since I haven’t been teaching I started learning new skills, did some online Python tutorials and then got interested in Meteor. When I first started teaching full time in Powell River one of the classes I was given was Information Technology 11/12. Part of this was teaching basic HTML which I was comfortable with but the other part was Javascript which I wasn’t. It was a quick and steep learning curve. Since meteor is based on JS I thought it would be a good way to revive that forgotten skill set. So far it has been going well and I’ve even made a few apps.

Then for Christmas I was given a Rasperry Pi and some Littlebits. After looking through some possible projects I’ve decided to try and build a Magic Mirror. I can build the site using Meteor and it can run on the Pi and perhaps make use of some of the Littlebits to act as motion sensor to activate it.

This project should be a lot of fun and documenting it here will be a good excuse to revive this blog.