OpenWRT 18.06 & Nodejs installing onoff node module [ solved ]
Jeff Seese last edited by
After upgrading to the latest OpenWRT per this blog post OpenWRT 18 available for omega2 & omega2+ I had some issues getting past working nodejs apps to work.
The root cause was the old onoff-node located at /usr/bin/onoff-node is no longer available via opkg install onoff-node. It is now possible to use the standard onoff module via npm.
However, to get there is a combination of several steps so I am going to explain the steps I went through to get it to work.
In short, make and gcc need to be installed so that npm can compile the onoff module. To be able to do that it's necessary to point opkg to the OpenWRT LEDE repos so they can be installed via opkg.
To compile onoff the omega will run out of ram so it's necessary to enable a swap file.
The Omega2S+ that I was working on didn't have enough room for python, nodejs and npm so I used an external SD card.
- upgrade to the latest OS. OpenWRT 18 available for omega2 & omega2+
After this finishes and you log back in you should see something like this.
Ω-ware: 0.3.2 b218
- boot from the SD card. Booting from external storage
opkg update opkg install kmod-usb-storage-extras e2fsprogs kmod-fs-ext4 block-mount umount /tmp/mounts/SD-P1 echo -e "y" | (mkfs.ext4 /dev/mmcblk0p1) mkdir /mnt/mmcblk0p1 mount /dev/mmcblk0p1 /mnt/mmcblk0p1 block detect > /etc/config/fstab uci set fstab.@mount.target=/overlay uci set fstab.@mount.enabled=1 uci commit mount /dev/mmcblk0p1 /mnt/ ; tar -C /overlay -cvf - . | tar -C /mnt/ -xf - ; umount /mnt/
now reboot, and log back in. You should see a large overlay in your df -h output, something like this for an 8G SD carrd.
df -h overlayfs:/overlay 7.2G 480.8M 6.4G 7% /
- Create a swap file and activate it. Extending Omegas Available Memory
opkg update; opkg install swap-utils
Make a swap file, I made min in my root directory since I now have additional space by mounting the SD card.
dd if=/dev/zero of=/root/swap.page bs=1M count=256
Turn on the swap file
I didn't permanently mount mine I only need the swap file for this instance. To check the swap file sue the free command.
free total used free shared buffers cached Mem: 124920 71360 53560 8 6888 40624 -/+ buffers/cache: 23848 101072 Swap: 262140 2560 259580
You should see the Swap: line
- Install python, nodejs, npm.
opkg install python nodejs node-npm
- install node-gyp https://docs.onion.io/omega2-docs/node-red-article.html#
node --max_old_space_size=512 $(which npm) install -g node-gyp
- Switch back to LEDE packages so that make and gcc can be installed. https://docs.onion.io/omega2-docs/using-opkg.html#using-opkg-switch-to-lede-repos
This is what my /etc/opkg/distfeeds.conf ended up looking like.
src/gz openwrt_core http://downloads.openwrt.org/releases/18.06-SNAPSHOT/targets/ramips/mt76x8/packages src/gz openwrt_base http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/base src/gz openwrt_luci http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/luci src/gz openwrt_onion http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/onion src/gz openwrt_packages http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/packages src/gz openwrt_routing http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/routing src/gz openwrt_telephony http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/telephony src/gz omega2_core http://repo.onioniot.com/omega2/packages/core src/gz omega2_base http://repo.onioniot.com/omega2/packages/base src/gz omega2_packages http://repo.onioniot.com/omega2/packages/packages src/gz omega2_routing http://repo.onioniot.com/omega2/packages/routing src/gz omega2_onion http://repo.onioniot.com/omega2/packages/onion
basically I just uncommitted everything.
- Install make and gcc https://docs.onion.io/omega2-docs/node-red-article.html#
opkg update opkg install make gcc ar -rc /usr/lib/libpthread.a
Go get a cup of coffee, this will take a few minutes.
- Finally ready to install npm onoff This will take a few minutes.
node --max_old_space_size=512 $(which npm) install onoff
That's it. You should see onoff in your node_modules directory now.
I verified that it works with a quick test .js to toggle a GPIO.
Jeff Seese last edited by
Oh one thing I forgot to mention, after I got all this working I was able to tar the node_modules directory up and move it to an Omega2S+ with no SD card.
After updating it to OpenWRT18, the nodejs install is small enough no external boot is necessary and there is no need for NPM on the production boards since they will never install a package. So that is nice to be able to eliminate the SD card.