本文硬件采用之前吃灰的树莓派2B,安装系统为Raspberry Pi OS with desktop,Debian version: 12 (bookworm)。魔镜软件使用MagicMirror²

1.基础环境配置

MagicMirror²本质是一个Nodejs的项目,能跑nodejs的平台其实都可以运行基础功能。所以首先按照之前的文章安装Nodejs,再clone Magic Mirror项目,安装依赖项:

1
2
3
4
cd ~
git clone https://github.com/MagicMirrorOrg/MagicMirror
cd MagicMirror/
npm run install-mm

MagicMirror²部分插件还需要request模块,直接安装:

1
npm install request

2.Raspbian系统设置

本工程使用的屏幕为一块5寸800x480的屏幕,设置竖屏向左旋转显示使用。

2.1 设置屏幕常亮

rapsi-config中设置,进入Dsiplay Options选项,选择Screen Blanking,将其设置为disable,这样保证屏幕常亮显示,同时需要关闭各种桌面的屏保。

2.2 开关机时竖屏设置

修改cmdline.txt文件,在最后添加如下内容:

1
video=HDMI-A-1:800x480M@60,rotate=270,panel_orientation=left_side_up

修改config.txt文件,添加如下内容:

1
2
display_hdmi_rotate=3
gpu_mem=128

2.3 修改plymouth开关机界面

按上述操作plymouth开关机界面也变成了竖屏,可修改为MagicMirror²对应的开关机界面:

1
2
3
4
5
6
7
8
9
cd /usr/share/plymouth/themes/
sudo mkdir MagicMirror

sudo cp ~/MagicMirror/splashscreen/splash.png /usr/share/plymouth/themes/MagicMirror/splash.png
sudo cp ~/MagicMirror/splashscreen/splash_halt.png /usr/share/plymouth/themes/MagicMirror/splash_halt.png
sudo cp ~/MagicMirror/splashscreen/MagicMirror.plymouth /usr/share/plymouth/themes/MagicMirror/MagicMirror.plymouth
sudo cp ~/MagicMirror/splashscreen/MagicMirror.script /usr/share/plymouth/themes/MagicMirror/MagicMirror.script

sudo plymouth-set-default-theme -R MagicMirror

2.4 进入X时竖屏设置

进入桌面直接运行arandr,可以设置屏幕旋转方向,图形化操作很简单,这里不再赘述。

2.5 添加关机按钮

修改config.txt文件,添加如下内容:

1
dtoverlay=gpio-shutdown,gpio_pin=21

这样把39、40pin口与一个按钮开关的OUT和GROUD接口相连,短接实现关机。

2.6 设置MagicMirror²开机启动

按照官方教程,使用PM2实现。

首先安装PM2:

1
2
sudo npm install -g pm2
pm2 startup

P.S. 安装pm2和pm2启动时会提示需要安装完成后需要运行的命令,复制代码运行即可。

首先设置MagicMirror²的启动脚本:

1
2
cp ~/MagicMirror/installers/mm.sh ~/mm.sh
chmod +x mm.sh

使用如下命令用PM2设置MagicMirror²开机启动:

1
2
pm2 start mm.sh
pm2 save

使用PM2设置开机启动后MagicMirror²将一直在前难以运行其它图形操作,如果需要临时停止,可以ssh上去运行如下命令:

1
pm2 stop mm

取消MagicMirror²开机启动可以运行如下命令:

1
2
pm2 delete mm
pm2 save --force

3.配置MagicMirror²

3.1 自定义字体和主题

MagicMirror²的主题保存在css\main.css下,直接修改即可,不过官方建议最好修改css/custom.css:

1
cp css\custom.css.sample css\custom.css

这里纯粹就是网页的css定义了,我把字体--font-size: 20px;改为--font-size: 15px;,减小字体,以便能够在低分辨率屏幕上显示,--font-primary也可以改为自己喜欢的,当然其它配色什么的也可以自行修改。

3.2 安装插件

MagicMirror²提供了很多第三方模块,可在MagicMirror²查找。我这里安装了MMM-BurnInMMM-BackgroundSlideshow插件防止烧屏和滚动显示图片,安装过程可参考插件文档,在此不再赘述。

3.3 设置插件

MagicMirror²配置文件保存在config/config.js

1
cp config/config.js.sample config/config.js

也很典型,可以根据自定义需求增删修改插件和对应的配置,基本每个插件的配置项在其说明文档介绍的很详细了,也没什么好多介绍的,其中languagelocale设置为zh-cn可以让系统显示中文,其它根据安装的插件修改为自己喜欢的形式即可,提供我的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
let config = {
address: "localhost", // Address to listen on, can be:
// - "localhost", "127.0.0.1", "::1" to listen on loopback interface
// - another specific IPv4/6 to listen on a specific interface
// - "0.0.0.0", "::" to listen on any interface
// Default, when address config is left out or empty, is "localhost"
port: 8080,
basePath: "/", // The URL path where MagicMirror² is hosted. If you are using a Reverse proxy
// you must set the sub path here. basePath must end with a /
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
// or add a specific IPv4 of 192.168.1.5 :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
// or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],

useHttps: false, // Support HTTPS or not, default "false" will use HTTP
httpsPrivateKey: "", // HTTPS private key path, only require when useHttps is true
httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true

language: "zh-cn",
locale: "zh-cn",
logLevel: ["INFO", "LOG", "WARN", "ERROR"], // Add "DEBUG" for even more logging
timeFormat: 24,
units: "metric",

modules: [
{
module: 'MMM-BackgroundSlideshow',
position: 'fullscreen_below',
config: {
imagePaths: ['/home/pi/Pictures/'],
transitionImages: true,
randomizeImageOrder: true
}
},
{
module: "MMM-BurnIn",
position: "bottom_bar", // whatever, doesn't render anything
config: {
updateInterval: 15, // in Minutes
invertDuration: 5 // in Seconds
}
},
{
module: "updatenotification",
position: "top_bar"
},
{
module: "clock",
position: "top_left",
config: {
timeFormat: 24,
showWeek: true,
}
},
{
module: "weather",
position: "top_right",
config: {
weatherProvider: "openweathermap",
type: "current",
location: "Hefei",
locationID: "1808722", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
apiKey: "请自己申请KEY",
showSun: false
}
},
{
module: "newsfeed",
position: "bottom_bar",
config: {
feeds: [
{
title: "人民网—时政频道",
url: "http://www.people.com.cn/rss/politics.xml"
},
{
title: "人民网—国际频道",
url: "http://www.people.com.cn/rss/world.xml"
}
],
showSourceTitle: true,
showPublishDate: true,
broadcastNewsFeeds: true,
broadcastNewsUpdates: true,
showDescription: false,
updateInterval: 30000
}
},
]
};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { module.exports = config; }

至此软件端设置完成,当然魔镜可以根据自身需求选择不同的插件。