树莓派实现桌面时钟
背景
- 硬件为树莓派3b和3.5寸LCD显示屏,外接显示器也可以
- 系统为树莓派官方Raspiberry OS桌面版,nodejs18.+,MagicMirror仓库源码
- MagicMirror官方文档,可查询详细的配置项
夫人整理屋子发现陈年树莓派3B+一块,欲丢之,甚恐,曰:勿扔!有用。遂Google寻项目欲用其装逼。
寻得MagicMirror,模块众多,功能丰富,喜甚,部署之
效果如下
1.MagicMirror安装
安装nodejs
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
从GitHub下载项目源码
git clone https://github.com/MichMich/MagicMirror
进到MagicMirror路径
cd MagicMirror/
安装依赖
npm run install-mm
创建初始配置
config/config.js.sample config/config.js
运行
#electron客户端及服务的同时运行
npm run start
#仅运行服务端
npm run server
警告
我测试的时候项目路径内的electron始终显示不存在,最后全局安装了electron并更改package.json
启动命令使用全局electron
npm install -g electron
将下面两行的./node_modules/.bin/electron
"start": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js",
"start:dev": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js dev",
改为
"start": "DISPLAY=\"${DISPLAY:=:0}\" /usr/bin/electron js/electron.js",
"start:dev": "DISPLAY=\"${DISPLAY:=:0}\" /usr/bin/electron js/electron.js dev",
2.配置
用到的配置模块为,其他的都禁用了用处不大,还有很多第三方模块,显示屏大的可以扩展功能
- calendar,显示节假日的模块
- clock,显示时间日期
- weather,显示当前及未来天气
- newsfeed,使用rss订阅获取最新资讯消息
最终配置文件为
/* MagicMirror² Config Sample
*
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*
* For more information on how you can configure this file
* see https://docs.magicmirror.builders/configuration/introduction.html
* and https://docs.magicmirror.builders/modules/configuration.html
*
* You can use environment variables using a `config.js.template` file instead of `config.js`
* which will be converted to `config.js` while starting. For more information
* see https://docs.magicmirror.builders/configuration/introduction.html#enviromnent-variables
*/
let config = {
address: "127.0.0.1", // server only的时候改成网口IP
// - "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: [], // IP白名单
// 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",
logLevel: ["INFO", "LOG", "WARN", "ERROR"], // Add "DEBUG" for even more logging
timeFormat: 24,
units: "metric",
modules: [
{
module: "alert",
},
//{
// module: "updatenotification",
// position: "top_bar"
//},
{
module: "clock",
position: "top_left",
config: {
dateFormat: "ddd,L" //更改日期格式默认是dddd,LL感觉太长
}
},
{
module: "calendar",
header: "节假日",
position: "top_left",
config: {
maximumEntries: "5",
//原本使用的是美国节假日日历,改为下面中国大陆日历,支持通用的ical日历
calendars: [
{
fetchInterval: 7 * 24 * 60 * 60 * 1000,
symbol: "calendar-check",
url: "https://www.shuyz.com/githubfiles/china-holiday-calender/master/holidayCal.ics"
}
]
}
},
//{
// module: "compliments",
// position: "lower_third"
//},
{
module: "weather",
position: "top_right",
config: {
weatherProvider: "openweathermap",
type: "current",
location: "Shenzhen",
locationID: "1795565", //通过这个文件进行ID 查询 http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
apiKey: "须注册openweathermap账号获取自己的apikey,每日免费调用1000次"
}
},
{
module: "weather",
position: "top_right",
header: "Weather Forecast",
config: {
weatherProvider: "openweathermap",
type: "forecast",
location: "Shenzhen",
locationID: "1795565", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
apiKey: "须注册openweathermap账号获取自己的apikey,每日免费调用1000次"
}
},
{
module: "newsfeed",
position: "bottom_bar",
config: {
ignoreOldItems: true,
ignoreOlderThan: 86400000,
//网上找的一些可用的rss订阅源
feeds: [
{
title: "机核网",
url: "https://www.gcores.com/rss"
},
{
title: "博客园",
url: "https://feed.cnblogs.com/blog/sitehome/rss"
},
{
title: "豆瓣书评",
url: "https://www.douban.com/feed/review/book"
},
{
title: "FreeBuf网络安全",
url: "https://www.freebuf.com/feed"
},
{
title: "极客公园",
url: "https://www.geekpark.net/rss"
},
{
title: "奇客",
url: "https://www.solidot.org/index.rss"
},
{
title: "互联网一些事儿",
url: "https://feed.yixieshi.com/"
}
],
showSourceTitle: true,
showPublishDate: true,
broadcastNewsFeeds: true,
broadcastNewsUpdates: true
}
},
]
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = config;}