New Top

All Products By Category

Arduino Yún: Connecting a JeeNode to the Internet

Last week Paul handed me one of our new Arduino Yún boards and asked me to get a project going. I know the Uno and the Arduino environment well, but the Yún has an Atheros processor running Linux. I had little idea how I was going to wrap my head around the command-line oriented Linux part of the equation. I figured I’d give it a shot and see if I could have my way with the Yún’s Linux processor. As you’ll see, I had a lot more success than I thought I would.

Setting up the Yún’s wi-fi for the first time is fairly straightforward, so I’m not going to bother explaining how to do that when you can find a great start-up guide at the Ardiuno website. The only thing I’d add is that accessing the setting in my browser was hit or miss when I tried accessing http://[board name].local. Instead, I recommend memorizing the Yún’s IP address from the configuration window because accessing it that way (http://[IP address]) worked every time and the IP address is how you access the Linux processor through SSH. I should also mention that only the absolute latest version of the Arduino IDE, version 1.5.6-r2, actually supports the Yún, so make sure you install that too (you can find it here).

For my first Yún project, I wanted to focus on the Atheros processor because the Atmel processor is identical to that of the Arduino Leonardo and functions essentially the same. But what to do? As it turns out, we have a hot box that we use to keep the radios dry for our JeeLabs products, and when it was first set up we added a humidity sensor connected to a JeeNode USB that output humidity and temperature data to a LCD screen via an LCD plug (for the sake of product placement, I might as well mention that a Jee ProtoBoard was involved as well). The thing is, every now and then the darn thing would freeze and need to be reset, and with everything that goes on here no one really has time to check on the hot box with any kind of regularity. Clearly we needed a way to be able to check the status of the hot box from anywhere. That’s where the Arduino Yún would come in.

To start, let’s see how the data gets from the box to the Yún. Here’s the code for the JeeNode USB on the hot box itself. It’s pretty straightforward; the data points are collected, sent to the LCD for display, and cast to integers after multiplying by 100 to preserve two decimal places before being broadcast by the radio. There’s a one-second delay and then the whole thing repeats. Note the group number 68 from rf12_initialize; we’ll need to make sure the JeeLink on the other end gets configured with the same number.

The code for the JeeLink that receives the data is even simpler. It just receives, unpacks, and prints the data sent by the JeeNode USB. You should also note the group number, 68, which matches the code on the transmitting JeeNode USB, and the serial baud rate, 57600, which we’ll need later.

Now that we’ve got the JeeLink streaming data over Serial, we can use the Yún to put it on the web. To do this, we’ll need to go directly to the Atheros processor, which we can do with a simple SSH in Terminal.

The first time you do this it will give you a security warning, so just enter “yes” to connect to the Yún. Once you’ve done that, we’ll need to install the FTDI drivers so the Yún can interpret serial data sent through the USB port. Luckily, the Yún’s Linux distribution Linino uses a package system that makes installing such things incredibly simple from the command line, so we’ll also install a second package we’ll need later.

The first command just updates the package list so you only have to do this once. If you ever have trouble finding a package, try running update again.

With the FTDI drivers installed, the Yún can now interpret serial data sent to it from the JeeLink through the USB port. To put that data on the web, we need a Python script. That script, in all its in-line commented glory, is as follows:

To make this available on the web, we have to move it to a special directory for files that we want the Yún’s server to host called “/www/”. We’ll also move our code (we named the file upload.py) to its own subfolder because it’s going to create a file.

In a new terminal window, navigate to the folder containing upload.py, then use the following command to copy it to our target directory.

Enter the password, then go back to your original Terminal window.

The last step is to build the webpage around the data to make it look nice. The index.html file, which will need to be moved to the same directory as upload.py, is as follows. I didn’t write this part (credit goes to Noah Beford), so I’m just going to call it a magical box. What I can tell you is that the stylesheet isn’t necessary, we just wanted it to look like the rest of our website.

Now that everything’s in place, we can access the data stream by going to http://[Yún IP address].local/humidity. To make it available to the public, we set up a redirect for port 80 of our external IP address to the internal Yún IP address (more on that in a future post; for now, you can just ask a friend who’s a gamer). We also set up a special subdirectory on our website so you can see the final results by going to humidity.moderndevice.com.

Resources
GitHub repository for this project
Buy your own Arduino Yún

Stay tuned for more!