NodeJs On VoCore Works
Posted: Sat May 23, 2015 2:02 pm
I tried compiling Nodejs for openwrt ramips and it works on the vocore using openwrt 14.07.
It was quite easy due to this git repository which has the makefile ready to go.
https://github.com/majklovec/wrtnode-packages
Just download the zip and uncompress in the packages directory of your build. Then "make menuconfig" and select it for build and build the image.
It runs and fits on the VoCore rom, due to the 16MB of space! When nodejs runs it allocates 30MB of ram, this isn't a problem, as it doesn't actually use 30MB of ram. I tried a simple web server and setup a bunch of bots to hit it and it worked great. Just be careful with program size as the kernel will kill the process if it uses too much memory. The other issue is that VoCore has not been told to compile images above 8MB. Since we have a 16MB rom the compiler wont make the image because Nodejs is like 5MB compressed - My total squashfs image was 10MB. To fix this you need to edit:
"<build_dir>/target/linux/ramips/image/Makefile"
Search for "vocore"
You will see "IMAGE_SIZE := $(ralink_default_fw_size_8M)" Somewhere under the vocore definition.
and replace "ralink_default_fw_size_8M" with "ralink_default_fw_size_16M"
Now it will happily make an image up to 16MB in size.
Some notes about NodeJS on openwrt:
You can reduce nodejs memory useage by playing with its settings on start.
nodejs --stack_size=1024 --max_old_space_size=20 --max_new_space_size=2048 --max_executable_size=5 --gc_global --gc_interval=100
The git above has sockets and serial makefiles, so making a socket server to control GPIO and serial port should be fairly simple.
I personally prefer to use libwebsocket for websockets as it is much more lightweight and faster. But Nodejs is nicer to code in than pure c.
Hope this helps the nodejs fans.
It was quite easy due to this git repository which has the makefile ready to go.
https://github.com/majklovec/wrtnode-packages
Just download the zip and uncompress in the packages directory of your build. Then "make menuconfig" and select it for build and build the image.
It runs and fits on the VoCore rom, due to the 16MB of space! When nodejs runs it allocates 30MB of ram, this isn't a problem, as it doesn't actually use 30MB of ram. I tried a simple web server and setup a bunch of bots to hit it and it worked great. Just be careful with program size as the kernel will kill the process if it uses too much memory. The other issue is that VoCore has not been told to compile images above 8MB. Since we have a 16MB rom the compiler wont make the image because Nodejs is like 5MB compressed - My total squashfs image was 10MB. To fix this you need to edit:
"<build_dir>/target/linux/ramips/image/Makefile"
Search for "vocore"
You will see "IMAGE_SIZE := $(ralink_default_fw_size_8M)" Somewhere under the vocore definition.
and replace "ralink_default_fw_size_8M" with "ralink_default_fw_size_16M"
Now it will happily make an image up to 16MB in size.
Some notes about NodeJS on openwrt:
You can reduce nodejs memory useage by playing with its settings on start.
nodejs --stack_size=1024 --max_old_space_size=20 --max_new_space_size=2048 --max_executable_size=5 --gc_global --gc_interval=100
The git above has sockets and serial makefiles, so making a socket server to control GPIO and serial port should be fairly simple.
I personally prefer to use libwebsocket for websockets as it is much more lightweight and faster. But Nodejs is nicer to code in than pure c.
Hope this helps the nodejs fans.