Monday, April 25, 2016

Tessel 2: Pairing JavaScript and the Internet of Things with Ease

The Tessel 2 is a microcontroller which allows you to build connected devices that run JavaScript and Node.js. It runs Linux at its core with Node.js running on top of that — providing access to plenty of npm modules and all of their potential. Over the next few weeks, I'll be covering some of the possibilities available for developers using the Tessel 2. This week we will start by looking at getting your Tessel 2 up and running with a simple test app.

[caption id="attachment_129041" align="aligncenter" width="800"]The Tessel 2 Microcontroller My Tessel 2 Microcontroller which I will be using for this demo![/caption]

Preparing Node.js

Make sure that you've got Node.js v4.2.0 or higher installed on your computer. You can check that using:

[code language="bash"]
node -v
[/code]

If you do not have Node.js installed yet, head over to the Node.js website and download Node.js v4.4.3.

If you are installing Node.js for the first time or looking to upgrade it to a newer version, I would recommend installing version 4.4.3 as later versions seem to have a bit of a bug with the Tessel 2 (particularly on Mac OS X). Feel free to try the latest version (chances are it was just my computer) but if you do have issues, try v4.4.3!

If you were like me and needed to upgrade Node.js, I did so initially by following this guide from David Walsh. However, it may be neater (and safer) to work with the NVM method if you have got a lot of Node dependencies running on your computer. I also reinstalled different versions with the .pkg download file from the Node.js site and it downgraded and upgraded with no issues. Whatever method you use, aim to install version 4.4.3.

The error in particular that you may see with later versions of Node after 4.4.3 occurs when trying to run t2 list. If you see the following error messages when running this command later in this guide, your version of Node may be the cause:

[code language="bash"]
node(12328,0x7fff7830b000) malloc: *** error for object 0xffffffff: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
[/code]

or:

[code language="bash"]
ERR! WARNING: No usb controller found on this system.
INFO Crash Reported: http://ift.tt/1NtUzoZ
[/code]

Installing The Tessel CLI

Once you've definitely got a compatible version of Node running on your computer, run the following command to install Tessel's CLI (command line interface) to your computer via npm:

[code language="bash"]
npm install -g t2-cli
[/code]

Finding Your Tessel

After the Tessel CLI has successfully installed, plug in your Tessel to one of your USB ports and let it boot up. After about 30 seconds, run the following command to find your tessel:

[code language="bash"]
t2 list
[/code]

That will run and should show a list of Tessels it can find that looks like so:

[code language="bash"]
INFO Searching for nearby Tessels...
USB Tessel-6465762064696E6572
[/code]

While a name like "Tessel-6465762064696E6572" is incredibly catchy, you can rename it to make that name even better! To do so, run the following command, replacing "Castiel" with your own choice of name:

[code language="bash"]
t2 rename Castiel
[/code]

You will see the following run through on the Tessel CLI, finishing with a success message:

[code language="bash"]
INFO Looking for your Tessel...
INFO Connected to Tessel-6465762064696E6572.
INFO Changed name of device Tessel-6465762064696E6572 to Castiel
[/code]

If you then run t2 list again, you should see your Tessel now has an incredibly catchy name:

[code language="bash"]
INFO Searching for nearby Tessels...
USB Castiel
[/code]

Connecting Your Tessel To Wi-Fi

The Tessel 2 comes with built in Wi-Fi, allowing it to connect to Wi-Fi networks relatively easily. To do so, run the following command:

[code language="bash"]
t2 wifi -n "Your Witty WiFi Name" -p yourwifipassword
[/code]

That'll show the following in the Tessel CLI, hopefully ending with a successful connection:

[code language="bash"]
INFO Looking for your Tessel...
INFO Connected to Castiel.
INFO Wifi Enabled.
INFO Wifi Connected. SSID: Your Witty WiFi Name, password: yourwifipassword, security: psk2
[/code]

Continue reading %Tessel 2: Pairing JavaScript and the Internet of Things with Ease%


by Patrick Catanzariti via SitePoint

No comments:

Post a Comment