User Tools

Site Tools


Launch of


What's Node.js ?

Node.js is a platform built on Chrome's JavaScript runtime V8 for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Node.js allows you to build scalable network applications using JavaScript on the server side. (Ex. Real Time Data Apps, WebSocket Server etc )

Prerequisites to install Node.js

  • Install fdisk
root@linino:~# opkg update
root@linino:~# opkg install fdisk
root@linino:~# opkg install e2fsprogs
root@linino:~# opkg install mtd-utils
  • Insert a new micro SD card (2GB or more) on the micro SD card reader
  • Create the /opt directory
root@linino:~# mkdir /opt
  • Create two partitions on micro SD using fdisk
root@linino:~#fdisk /dev/sda

Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sda: 7948 MB, 7948206080 bytes
19 heads, 10 sectors/track, 81704 cylinders, total 15523840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    13673922     6835937+  83  Linux
/dev/sda2        13673923    15523839      924958+  82  Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
  1. First partition formatted using ext3 file system
root@linino:~# mkfs.ext3 -L driveSD /dev/sda1
mke2fs 1.42.4 (12-June-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
427392 inodes, 1708984 blocks
85449 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1753219072
53 block groups
32768 blocks per group, 32768 fragments per group
8064 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
  1. Second partition (256MB or bigger) used as swap
root@linino:~# mkswap -L swapSD /dev/sda2
Setting up swapspace version 1, size = 947153408 bytes
root@linino:~# swapon -L swapSD
  • Modify /etc/config/fstab to have /opt mounted on /dev/sda1 adding the following lines
config swap
        option device '/dev/sda2'
        option enabled '1'        
config mount                
        option device '/dev/sda1'                
        option target '/opt'                        
        option fstype 'ext3'                                
        option enabled '1'                       
  • Change /etc/opkg.conf in order to install all the new pkgs on /opt and to use the linino_dev repository path. Add the following line :
dest mnt /opt
root@linino:~# cat /etc/opkg.conf
src/gz attitude_adjustment
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
option check_signature
dest mnt /opt
  • Be sure to run opkg update again to sync up with the linino_dev repository
root@linino:~# opkg update
Updated list of available packages in /var/opkg-lists/attitude_adjustment.
Signature check passed.
  • When you need to install a new packages use the command: opkg install <new-pkg> -d mnt
  • Change env settings on /etc/profile
export LD_LIBRARY_PATH=/opt/usr/lib
export PATH=$PATH:/opt/usr/bin
root@linino:~# env

* Restart the /etc/init.d/fstab

root@linino:~# /etc/init.d/fstab restart
root@linino:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                    7680       968      6712  13% /
/dev/root                 7168      7168         0 100% /rom
tmpfs                    30620       100     30520   0% /tmp
tmpfs                      512         0       512   0% /dev
/dev/mtdblock3            7680       968      6712  13% /overlay
overlayfs:/overlay        7680       968      6712  13% /
/dev/sda1              6728592     15036   6371760   0% /opt
root@linino:~# free
             total         used         free       shared      buffers
Mem:         61240        28496        32744            0         3720
-/+ buffers:              24776        36464
Swap:       924952            0       924952

Installing Node.js

root@linino:~# opkg install node -d mnt
Installing node (v0.10.25-1) to mnt...
Installing uclibcxx (0.2.4-1) to mnt...
Configuring uclibcxx.
Configuring node.

In this way all the node files wil bee installed on SD on the directory /opt. Reboot the board or reload the profile through source /etc/profile

  • Change the default vaule on npm config
npm config set userconfig /opt/.npmrc --global
npm config set userignorefile /opt/.npmignore --global
npm config set cache /opt/.npm --global
npm config set tmp /opt/tmp --global
npm config set prefix /opt/usr --global
  • to show the npm config list use
npm config ls -l

The next use of npm install -g <pkg> will download the js files on the /opt/usr/lib directory

How install serialport

In order to use the serial interface to communicate with the MCU, the serialport module needs to be installed. But since the serialport package contains some C files, the G++ compiler has to be present on the board. At the moment a g++ compiler for mips is not available so we are able to provide you the cross-compiled serialport.node binaries. So to install the serialport module, first of all download the package with :

$ cd /opt
$ wget -O serialport-1.6.1_mips-25-ubuntu.tar.gz

then untar it so to be detected “globally” by your system with :

$ tar xvf serialport-1.6.1_mips-25-ubuntu.tar.gz -C /opt/usr/lib/node_modules

Firmata on MCU

In order to have the communication between Node.Js and the MCU, the Firmata firmware has to be install on MCU.

$ cd /opt
$ wget -O firmataspi.tar.gz 
$ tar xvf firmataspi.tar.gz
$ run-avrdude FirmataSPI.hex

Firmata/johnny-five on Node.Js

Download the pre-built module for MIPS cpu architecture johnny-five.node :

$ cd /opt
$ wget -O johnny-five-0.8.47_mips-25-ubuntu.tar.gz

and then install it so to be detected “globally” by your system :

$ tar xvf johnny-five-0.8.47_mips-25-ubuntu.tar.gz -C /opt/usr/lib/node_modules

then perform this simple test :

$ cd /opt/usr/lib/node_modules/johnny-five/node_modules/firmata/examples
$ sed -i -e 's/\/dev\/cu.usbmodem1411/\/dev\/ttySPI0/g' blink.js
$ node blink.js
/var/www/ · Last modified: 2015/03/09 07:38 by arturo

2014 © dog hunter llc and the Linino Community. is a dog hunter sponsored community project. Credits