Setup Magic Mirror 2 in RPi 4

From CMEE4K
Jump to navigation Jump to search

MagicMirror GUI

MM RPi4b 4GRAM 8GSDHC PlusA1.png MagicMirrorRegion.png

Setup Magic Mirror2 in RPi 4

Always update/upgrade

  • sudo apt-get update
  • sudo apt-get upgrade

Manual Installation

Document site: Easy to install MagicMirror2

  1. Download and install the latest Node.js version
  2. Clone the repository and check out the master branch
    git clone https://github.com/MichMich/MagicMirror
  3. Enter the repository: cd MagicMirror/
  4. Install the application: npm install
  5. Make a copy of the config sample file: cp config/config.js.sample config/config.js
  6. Start the application: npm run start
    For Server Only use: npm run server
Installation Note

For #4 npm install command, it reports the following warning message:

MagicMirror installation finished successfully! 

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})

added 1052 packages from 1150 contributors and audited 1054 packages in 100.999s

75 packages are looking for funding
  run `npm fund` for details

found 25 vulnerabilities (23 low, 2 moderate)
  run npm audit fix to fix them, or npm audit for details

Enter: npm audit fix --force

Start Up Note

Execute: npm run start command

> magicmirror@2.11.0 start /home/pi/MagicMirror
> DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js

[2020-05-18 17:49:09.707] [LOG]    Starting MagicMirror: v2.11.0
[2020-05-18 17:49:09.714] [LOG]    Loading config ...
[2020-05-18 17:49:09.722] [LOG]    Loading module helpers ...
[2020-05-18 17:49:09.725] [LOG]    No helper found for module: alert.
[2020-05-18 17:49:09.776] [LOG]    Initializing new module helper ...
[2020-05-18 17:49:09.777] [LOG]    Module helper loaded: updatenotification
[2020-05-18 17:49:09.778] [LOG]    No helper found for module: clock.
[2020-05-18 17:49:10.132] [LOG]    Initializing new module helper ...
[2020-05-18 17:49:10.133] [LOG]    Module helper loaded: calendar
[2020-05-18 17:49:10.136] [LOG]    No helper found for module: compliments.
[2020-05-18 17:49:10.137] [LOG]    No helper found for module: currentweather.
[2020-05-18 17:49:10.139] [LOG]    No helper found for module: weatherforecast.
[2020-05-18 17:49:10.170] [LOG]    Initializing new module helper ...
[2020-05-18 17:49:10.171] [LOG]    Module helper loaded: newsfeed
[2020-05-18 17:49:10.172] [LOG]    All module helpers loaded.
[2020-05-18 17:49:10.319] [LOG]    Starting server on port 8080 ... 
[2020-05-18 17:49:10.332] [LOG]    Server started ...
[2020-05-18 17:49:10.333] [LOG]    Connecting socket for: updatenotification
[2020-05-18 17:49:10.334] [LOG]    Connecting socket for: calendar
[2020-05-18 17:49:10.334] [LOG]    Starting node helper for: calendar
[2020-05-18 17:49:10.335] [LOG]    Connecting socket for: newsfeed
[2020-05-18 17:49:10.336] [LOG]    Starting module: newsfeed
[2020-05-18 17:49:10.337] [LOG]    Sockets connected & modules started ...
[2020-05-18 17:49:10.529] [LOG]    Launching application.
[2020-05-18 17:49:12.744] [LOG]    Create new calendar fetcher for url: http://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics - Interval: 300000
[2020-05-18 17:49:12.789] [LOG]    Create new news fetcher for url: http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml - Interval: 300000

Configure MM

Update npm: sudo npm install -g npm
Check the configuration file

  • In MagicMirror directory, enter npm run config:check

MM Configuration

Upgrade Guide

Upgrade Guide
Always backup your config.js, custom.css and modules folder before you start the upgrade process!
git pull && npm install

Use pm2

https://github.com/MichMich/MagicMirror/wiki/Auto-Starting-MagicMirror
Install PM2: sudo npm install -g pm2

Freeze a process list on reboot: pm2 startup
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi

Autostart pm2 on boot

Now execute this line: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
Target path
/etc/systemd/system/pm2-pi.service
Command list
[ 'systemctl enable pm2-pi' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-pi.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-pi...
Created symlink /etc/systemd/system/multi-user.target.wants/pm2-pi.service -> /etc/systemd/system/pm2-pi.service.
[PM2] [v] Command successfully executed.

Remove pm2 from init script

pm2 unstartup systemd

Stop pm2 process

Stop PM2: pm2 stop 0


Make MM start script

cd ~
vi mm.sh
chmod +x mm.sh
mm.sh file
cd ~/MagicMirror
DISPLAY=:0 npm start
Stop MagicMirror

Press CTRL-Q

Starting MM with PM2

pm2 start mm.sh

PM2 will restart MM

pm2 will watch mm process. When we CTRL-Q to terminate mm process, pm2 will restart it. To stop mm, use pm2 stop mm

Enable restarting of the MM script

Freeze a process list on reboot: pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/pi/.pm2/dump.pm2

Controlling MM via PM2

pm2 restart mm<br>
pm2 stop mm<br>
pm2 logs mm<br>
pm2 show mm

Don't use PM, setup Desktop start menu

Stop MM in PM

  • pm2 stop mm
  • pm2 save

Create MM desktop entry

Switch to root

  • Create a MM logo (48x48) png file: /usr/share/pixmaps/mm.png
    mm.png
  • Create a new file: /usr/share/applications/MM.desktop
[Desktop Entry]
Type=Application
Name=MM
Comment=Magic Mirror
Icon=/usr/share/pixmaps/mm.png
Exec=/home/pi/mm.sh
Terminal=false
Categories=
  • Restart lxde environment: lxpanelctl restart

Create MM icon

Desktop application icon

  • Menu > Other > MM
  • Right click on MM > Add to desktop

Menu bar icon

  • Right click on Menu bar > Add / Remove Panel Items
  • In the pop-up Panel Preference window
    • In the Panel Applets tag
    • Add > Application Launch Bar (A + sign will be created in the menu bar)
    • Use Up / Down to move the + to the right position, then Close the Panel Preference window
  • Click the + in the Menu bar, an Application Launch Bar window will pop-up
    • Expand Other and select MM
    • Click Add, and then Close

Referenece

Useful links

Run program on startup

Install Modules

Install Magic Mirror 2 modules