要想在arm linux下方便使用node-red,建议最好使用docker部署,这样可以使得你的node-red能够以最新的版本运行。node-red有很多开源库可以使用,因此搭建其开发环境非常重要,可以在arm linux 环境下编译很多源码。下面将我实际操作的方法分享给大家,本人基于全志T113i处理器进行编译,node.js 20版本。
1. 先在unbuntu 18.04 环境下把基础docker镜像下载
sudo docker pull balenalib/armv7hf-node:20
#再把该镜像另存为armv7hf-node.tar 文件
sudo docker save -o armv7hf-node20.tar balenalib/armv7hf-node:20
2. 在arm linux 下复制并导入镜像
docker load -i armv7hf-node20.tar
#启动arm linux 运行
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered balenalib/armv7hf-node:20 /bin/bash
3. 安装编译环境
apt update
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
4. 安装python3
apt install python3 python3-pip
#安装必要工具
apt install vim git
5.安装node-red环境
npm config set registry https://registry.npmmirror.com
npm config set registry https://registry.npmjs.org/
#npm config set registry https://registry.npm.taobao.org
npm install -g node-red
npm install -g node-gyp
npm install -g serialport
#这个socketcan必须要装编译环境才能正常安装
npm install -g socketcan
6. 保存镜像
docker commit ID.. armv7hf-node-dev:1.2
7. 源码安装
git clone https://github.com/node-red/node-red.git
node --max-old-space-size=2048 $(which npm) install
npm cache clean --force
npm install --no-package-lock --no-audit --no-fund --no-optional --legacy-peer-deps
8. 问题处理
#1. 增加 Node.js 的内存限制:
node --max-old-space-size=1024 $(which npm) install
#2. 减少 npm 的并发任务数:
npm install --no-package-lock --no-audit --no-fund --no-optional --legacy-peer-deps
#3. npm install安装问题多多,改成下面这样
npm install cnpm
node --max-old-space-size=1024 $(which cnpm) install
cnpm run build
done
cnpm start
cnpm install cors
lodash.clonedeep
json-stringify-safe clone
passport-http-bearer
passport-oauth2-client-password/
cnpm start
#还有错误:
cnpm install is-utf8 hash-sum on-headers media-typer
cnpm start
#到此为止:arm v7开发环境,全部启动正常
9. 开发环境
9.1. mount工作目录
在t113主机上mount linux x86虚拟机,/mnt/node-red-data 为开发工作目录
mount -t nfs 192.168.13.81:/home/uw/node-red /mnt/node-red-data -o nolock
9.2. 目录映射
.启动docker 时候把 开发板主机/mnt/node-red-data 目录映射到docker data 目录
#docker run -it -p 1880:1880 -v /mnt/node-red-data:/data --name mynodered armv7hf-node20-dev:v1.3 /bin/bash
docker run -it -p 1880:1880 -v /mnt/node-red-data:/data --name mynodered --network=host --privileged --device=/dev/ttyAS1 --device=/dev/ttyAS2 --device=/dev/ttyAS3 --device=/dev/ttyAS4 --device=/dev/ttyAS5 armv7hf-node20-dev:v1.3 bash
docker run -it -p 1880:1880 -v /mnt/node-red-data:/data --name mynodered --network=host --privileged --device=/dev/ttyAS1 --device=/dev/ttyAS2 --device=/dev/ttyAS3 --device=/dev/ttyAS4 --device=/dev/ttyAS5 armv7hf-node20-dev:v1.4 bash
9.3. 在linux x86虚拟机 设置Samba 共享,以便在windows 下编辑代码。
sudo vi /etc/samba/smb.conf
[cross]
path = /home/uw/cross
available = yes
valid users = uw
read only = no
browsable = yes
public = yes
writable = yes
#设置共享用户密码
sudo smbpasswd -a uw
#启用共享
sudo systemctl restart smbd
10. 开发调试
10.1. 串口节点
npm install serialport --build-from-source
dependencies:
+ serialport ^13.0.0
10.2. can 调试
ip link set can0 down
ip link set can0 up type can bitrate 50000 loopback on
cansend can0 123#deadbeef
cnpm install socketcan
dependencies:
+ socketcan ^4.0.5
10.3. 安装sqllite节点
npm cache clean --force
cd ~/.node-red
rm -rf node_modules package-lock.json
#npm install -g cnpm --registry=https://registry.npmmirror.com
npm config set registry https://registry.npmmirror.com/
cnpm install node-red-node-sqlite
1万+

被折叠的 条评论
为什么被折叠?



