教程列表
Home Assistant 搭建日志(一)——安装树莓派系统
Home Assistant 搭建日志(二)——配置树莓派系统
Home Assistant 搭建日志(三)——安装与启动Home Assistant
Home Assistant 搭建日志(四)——外网访问Home Assistant
Home Assistant 搭建日志(五)——让蓝牙音箱唱歌
Home Assistant 搭建日志(六)——MPD播放器
Home Assistant 搭建日志(七)——安装NodeRed
对于NodeRed
的安装,最简单的就是直接使用apt
来安装,但是这样会出现个问题,就是安装NodeRed
时,要安装依赖NodeJS
和NPM
,而当前buster
源里,NodeJS
的版本是10.15.2~dfsg-2+rpi1
,NPM
的版本是5.8.0+ds6-4
,这两个版本之间并不是完全兼容的,所以使用的时候会一直报警告,使用npm install
有些情况还出现错误。例如在安装 NeteaseCloudMusicApi 就一直失败。
虽然可以通过命令npm install -g npm
把NPM
升级到新版,但是之前apt
是把NPM
安装在/usr/bin
里,升级命令是把新的NPM
安装到/usr/local/bin
里,造成同时存在两个版本的NPM
,系统也会默认使用久的NPM
。现在尝试一下非常规的安装方法,看看后续会不会发生一些神奇的问题。
1. 手动查看软件源
有一次,我好奇到软件源里看了下,看下是不是真的只有NPM 5.8.0+ds6-4
这个版本。
NPM安装包的软件源位置
发现有其它的NPM
版本
但是在apt-cache
里只能查到5.8.0+ds6-4
这个版本
pi@pi:~ $ apt-cache show npm
Package: npm
Version: 5.8.0+ds6-4
Installed-Size: 8439
Maintainer: Debian Javascript Maintainers <[email protected]>
Architecture: all
Depends: nodejs (>= 6.11~), ca-certificates, node-abbrev (>= 1.1.1~), node-ansi-regex (>= 3.0~), node-ansistyles (>= 0.1.3~), node-aproba (>= 1.2~), node-archy (>= 1.0~), node-cacache (>= 10.0.4~), node-bluebird (>= 3.5.1~), node-call-limit (>= 1.1~), node-chownr (>= 1.0.1~), node-config-chain (>= 1.1.11~), node-detect-indent (>= 5.0~), node-detect-newline (>= 2.1~), node-editor (>= 1.0~), node-fs-vacuum (>= 1.2.10~), node-fs-write-stream-atomic (>= 1.0.10~), node-glob (>= 7.1.2~), node-graceful-fs (>= 4.1.11~), node-has-unicode (>= 2.0.1~), node-hosted-git-info (>= 2.6~), node-iferr (>= 0.1.5~), node-inflight (>= 1.0.6~), node-inherits (>= 2.0.3~), node-ini (>= 1.3.5~), node-npm-package-arg, node-promzard, node-jsonstream (>= 1.3.2~), node-json-parse-better-errors (>= 1.0.1~), node-lazy-property (>= 1.0~), node-libnpx (>= 10.0.1~), node-lockfile (>= 1.0.3~), node-lru-cache (>= 4.1.1~), node-mississippi (>= 3.0~), node-mkdirp (>= 0.3.3), node-move-concurrently (>= 1.0.1~), node-nopt, node-normalize-package-data (>= 2.4~), node-gyp (>= 3.6.2~), node-resolve-from (>= 4.0~), node-encoding, node-errno, node-npmlog (>= 4.1.2~), node-once (>= 1.4~), node-opener (>= 1.4.3~), node-osenv (>= 0.1.5~), node-path-is-inside (>= 1.0.2~), node-promise-inflight (>= 1.0.1~), node-ansi, node-qw (>= 1.0.1~), node-read (>= 1.0.7~), node-read-package-json (>= 2.0.13~), node-request (>= 2.83~), node-retry (>= 0.10.1~), node-rimraf (>= 2.6.2~), node-safe-buffer (>= 5.1.1~), node-semver (>= 5.5~), node-sha (>= 2.0.1~), node-slide (>= 1.1.6~), node-sorted-object (>= 2.0.1~), node-from2, node-stream-iterate, node-ssri (>= 5.2.4~), node-strip-ansi (>= 4.0~), node-tar (>= 4.4~), node-text-table (>= 0.2~), node-uid-number (>= 0.0.6~), node-unique-filename (>= 1.1~), node-unpipe (>= 1.0~), node-boxen (>= 1.2.1~), node-import-lazy, node-is-npm (>= 1.0~), node-latest-version (>= 3.0~), node-semver-diff (>= 2.0~), node-xdg-basedir (>= 3.0~), node-validate-npm-package-name (>= 3.0~), node-which (>= 1.3~), node-wrappy (>= 1.0.2~), node-write-file-atomic (>= 2.3~)
Size: 1016092
SHA256: 47e13b69e221046fcba1eced1f8474937729012d223e046620cf18455e3d13b4
SHA1: b62536f17ad1b6c1fe4b2f808c1a92d479590033
MD5sum: 83302ec272e96d5ffe53f06e3dd2863c
Description: package manager for Node.js
Node.js is an event-based server-side javascript engine.
.
npm is the package manager for the Node JavaScript platform. It puts
modules in place so that node can find them, and manages dependency
conflicts intelligently.
.
It is extremely configurable to support a wide variety of use cases.
Most commonly, it is used to publish, discover, install, and develop
node programs.
Description-md5: 85ba8bf129c09297837a706dcf08eb1f
Homepage: https://docs.npmjs.com/
Section: web
Priority: optional
Filename: pool/main/n/npm/npm_5.8.0+ds6-4_all.deb
然后就在百度查查查查查了一下,发现了这样个网页
https://packages.debian.org/bullseye/npm
里面可以看到,6.13.4+ds-2
这个版本的NPM
在bullseye
发行版本可以下载,在buster
版本下只能下载5.8.0+ds6-4
,那么,如果我直接把下载源更换到bullseye
发行版本,那不就可以下载NPM 6.13.4+ds-2
?尝试一下。
2. 更换软件源
sudo vi /etc/apt/source.list
# 把之前旧的
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib
=>
# 更换为新的
deb http://mirrors.aliyun.com/raspbian/raspbian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ bullseye main non-free contrib
更新下软件源
sudo apt-get update
查看下NPM
的版本
pi@pi:~ $ apt-cache show npm
Package: npm
Version: 6.13.4+ds-2
Installed-Size: 3412
Maintainer: Debian Javascript Maintainers <[email protected]>
Architecture: all
Depends: nodejs (>= 6.11~), ca-certificates, node-abbrev (>= 1.1.1~), node-ajv, node-ansi, node-ansi-regex (>= 3.0~), node-ansi-styles, node-ansistyles, node-aproba, node-archy (>= 1.0~), node-are-we-there-yet, node-asap, node-asn1, node-assert-plus, node-asynckit, node-aws4, node-aws-sign2, node-balanced-match, node-bcrypt-pbkdf, node-bl, node-bluebird, node-boxen, node-brace-expansion, node-builtin-modules, node-builtins, node-cacache, node-call-limit, node-camelcase, node-caseless, node-chalk, node-chownr, node-ci-info, node-cli-boxes, node-cliui, node-clone, node-co, node-color-convert, node-color-name, node-colors, node-columnify, node-combined-stream, node-concat-map, node-concat-stream, node-config-chain, node-configstore, node-console-control-strings, node-copy-concurrently, node-core-util-is, node-cross-spawn, node-crypto-random-string, node-cyclist, node-dashdash, node-debug, node-decamelize, node-deep-extend, node-defaults, node-define-properties, node-delayed-stream, node-delegates, node-detect-indent, node-detect-newline, node-dot-prop, node-duplexer3, node-duplexify, node-ecc-jsbn, node-editor, node-encoding, node-end-of-stream, node-err-code, node-errno, node-es6-promise, node-escape-string-regexp, node-execa, node-extend, node-extsprintf, node-fast-deep-equal, node-find-up, node-flush-write-stream, node-forever-agent, node-form-data, node-from2, node-fs.realpath, node-fs-vacuum, node-fs-write-stream-atomic, node-function-bind, node-gauge, node-genfun, node-get-caller-file, node-getpass, node-glob (>= 7.1.2~), node-got, node-graceful-fs (>= 4.1.11~), node-gyp (>= 3.6.2~), node-har-schema, node-har-validator, node-has-flag, node-has-unicode, node-hosted-git-info (>= 2.6~), node-http-signature, node-iconv-lite, node-iferr, node-import-lazy, node-imurmurhash, node-inflight, node-inherits (>= 2.0.3~), node-ini (>= 1.3.5~), node-invert-kv, node-ip, node-ip-regex, node-isarray, node-isexe, node-is-npm, node-is-obj, node-is-path-inside, node-is-retry-allowed, node-is-stream, node-isstream, node-is-typedarray, node-jsbn, node-jsonparse, node-json-parse-better-errors, node-json-schema, node-json-schema-traverse, node-jsonstream (>= 1.3.2~), node-json-stringify-safe, node-jsprim, node-latest-version, node-lazy-property, node-lcid, node-libnpx, node-locate-path, node-lodash, node-lockfile (>= 1.0.3~), node-lowercase-keys, node-lru-cache (>= 4.1.1~), node-make-dir, node-mem, node-mime, node-mime-types, node-mimic-fn, node-minimatch, node-minimist, node-mississippi, node-mkdirp (>= 0.5.1~), node-move-concurrently, node-ms, node-mute-stream, node-nopt, node-normalize-package-data (>= 2.4~), node-npm-bundled, node-npm-package-arg (>= 6.1.1), node-npmlog (>= 4.1.2~), node-number-is-nan, node-oauth-sign, node-object-assign, node-once (>= 1.4~), node-opener, node-osenv (>= 0.1.5~), node-os-locale, node-os-tmpdir, node-package-json, node-parallel-transform, node-path-exists, node-path-is-absolute, node-path-is-inside, node-promise-inflight, node-promise-retry, node-promzard, node-performance-now, node-p-finally, node-pify, node-p-limit, node-p-locate, node-prepend-http, node-process-nextick-args, node-proto-list, node-prr, node-pseudomap, node-psl, node-pump, node-pumpify, node-punycode, node-qs, node-qw, node-rc, node-read (>= 1.0.7~), node-readable-stream, node-read-package-json (>= 2.0.13~), node-registry-auth-token, node-registry-url, node-request (>= 2.83~), node-require-main-filename, node-require-directory, node-resolve-from (>= 4.0~), node-retry (>= 0.10.1~), node-rimraf (>= 2.6.2~), node-run-queue, node-safe-buffer, node-semver (>= 5.5~), node-set-blocking, node-sha (>= 2.0.1~), node-shebang-command, node-shebang-regex, node-signal-exit, node-slide (>= 1.1.6~), node-sorted-object, node-slash, node-semver-diff, node-spdx-correct, node-spdx-exceptions, node-spdx-expression-parse, node-spdx-license-ids, node-sshpk, node-ssri, node-stream-each, node-stream-iterate, node-stream-shift, node-strict-uri-encode, node-string-decoder, node-string-width, node-strip-ansi (>= 4.0~), node-strip-json-comments, node-strip-eof, node-supports-color, node-tar (>= 4.4~), node-term-size, node-text-table, node-through, node-through2, node-timed-out, node-tough-cookie, node-tunnel-agent, node-tweetnacl, node-typedarray, node-uid-number, node-unique-filename, node-unique-string, node-unpipe, node-url-parse-lax, node-util-deprecate, node-uuid, node-validate-npm-package-name, node-verror, node-which (>= 1.3~), node-which-module, node-wide-align, node-widest-line, node-wrap-ansi, node-wrappy, node-wcwidth.js, node-write-file-atomic, node-xdg-basedir, node-xtend, node-yargs, node-yargs-parser, node-yallist, node-y18n
Size: 646912
SHA256: 00aba43c95437be619d5a94d138774f06aa866f972e2ddcfb10e07eb6a823aed
SHA1: e94e4f762a069060a29a19eed339f05f9f454c8d
MD5sum: 046c392aaaaf8e6008549b4cfc9d9630
Description: package manager for Node.js
Node.js is an event-based server-side javascript engine.
.
npm is the package manager for the Node JavaScript platform. It puts
modules in place so that node can find them, and manages dependency
conflicts intelligently.
.
It is extremely configurable to support a wide variety of use cases.
Most commonly, it is used to publish, discover, install, and develop
node programs.
Description-md5: 85ba8bf129c09297837a706dcf08eb1f
Homepage: https://docs.npmjs.com/
Section: web
Priority: optional
Filename: pool/main/n/npm/npm_6.13.4+ds-2_all.deb
可以看到版本是6.13.4+ds-2
3. 安装NodeRed
既然NPM
可以下载6.13.4+ds-2
版本,那就尝试下直接安装NodeRed
sudo apt-get install nodered
然后在安装的时候弹出了这样一个东西,吓Q死我
Google翻译一下,是说更新了一些服务,需要重启那些服务什么的,那就Yes
吧。
然后就直接安装完成了。
这里要记得把软件源从 bullseye 换回 buster,然后更新软件源
4. 启动NodeRed
sudo systemctl start nodered.service
# 查看下运行状态
systemctl status nodered.service
# 一发入魂,直接成功,设置开机自启
sudo systemctl enable nodered.service
5. 修改NodeRed配置
vi ~/.node-red/settings.js
-
惯例修改绑定端口
# 找到 uiPort: process.env.PORT || 1880, # 修改为(小心不要干掉最后的逗号,) uiPort: process.env.PORT || 新的端口,
-
网页进去的账号密码
现在在网页进入是不需要账号密码,直接进到NodeRed
的工作台的
首先安装一个加密库bcryptjs
用于生成密码
然后在配置文件里面找到npm install bcryptjs
adminAuth
模块,把这一整个模块
的注释去掉,编辑里面内容:
使用下面的命令生成加密后的密码,例如密码为adminAuth: { type: "credentials", users: [{ username: "你想要的用户名", password: "加密后的密码", permissions: "*" }] },
123456
生成出来加密后的密码node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" 123456
把这串字符串粘贴到上面配置$2a$08$2Jq.v9vMdmDmA6issbvRqO/OkNLXT8mH01BdkuYSWwGJI.Gwk/A9.
加密后的密码
那里,就可以通过用户名
和123456
登录到NodeRed
控制台了。当然,要先重启服务。sudo systemctl restart nodered.service
配置完毕,下一章尝试创建流程,用NodeRed
控制HA
的组件(貌似现在只有MPD
)。