Internet of Things (IoT)

Running a Persistant Node.js Server on an Arduino Yún

We recently had occasion to set up a Node.js web server on an Arduino Yún. It's a bit more complicated than we thought when we set out, so it seemed useful to share the process.


We recently had occasion to set up a Node.js web server on an Arduino Yún. It's a bit more complicated than we thought when we set out, so it seemed useful to share the process. To accomplish this, we need to update the system image, expand the device storage, install node, and launch our server. You'll need a couple things:

Once your supplies are lined up, you can get started with the instructions below. Note: This guide assumes a working knowledge of unix systems, and a basic familiarity with the Yún.

Updating the system image

Copy the system image (download) onto the SD card, then plug it into the Yún. Now log into the Yún’s web admin, and there should be a message indicating that it has found the update, and a button to reset from the image.

Install the update, then get your Yún back on the proper wifi network.

Expanding device storage

Once you're updated to the latest system image (if you do this before updating, your progress will be lost) load the YunDiskSpaceExpander sketch onto the Yún, and connect to the serial console. Follow the on-screen prompts to expand your partition. When it asks you for a partition size, Make sure it's at least 1GB, so there's enough room for your software updates, and a swapfile.

Installing Node

After expanding your device storage, ssh into your Yún. Once connected, run opkg update then opkg install node. This will install Node.js, and all its dependencies.

Next, install forever. The Yún doesn't have enough memory to install this module on its own, so we need a swap file.

Follow this guide to create one. You can stop at step 5, since the Yún wipes out your fstab on every reboot anyway (a problem for another blog post). Once you've finished Step 5, verify you have swap space with free -m

Once your swap is set up, install the module with npm install forever -g. Finally, launch the server with forever start server.js. If everything went according to plan, you should now be able to access your server persistently. Finally, you can run swapoff [swapfile] and rm [swapfile] to reclaim your disk space.

Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.