Here it is a complete, standalone and efficient media system based on UDOO Board designed to be an easy plug-n-play solution. In case you are wondering, this is not a simple media server or NAS (Network Attached Storage), although it does that too. It is everything your run-of-the-mill Linux server can do (routing? firewall? NAT? VPN? No problem!) plus a built-in Arduino!
By the way, it's basically an Arduino-Linux project realized using the Arduino Due built inside the UDOO Board. If you want to take a deeper insight of the project, take a look at this simple tutorial I wrote for you.Requirements
The target users are also non-tech savvy people, thus the top requirements are:
- Small form factor
- Energy efficient
- Cheap to build
- Large storage capacity
- Network connectivity
A bit of knowledge in hardware, chassis building, networking, Linux OS, BASH Scripting, building simple electronic circuits, Arduino programming is required.Objectives
Our device will finally be able to:
- Run CouchPotato. A movie downloading front-end to search and manage downloads
- Run SickBeard. A TV series downloading front-end to search and manage downloads
- Run MiniDLNA. A service which streams all media content to any compatible device
- Run OpenVPN. This instance runs as a client to a server the author has in USA, allowing us to stream USA-only services like Netflix
- Run Squid Proxy. Used for any devices on the network to proxy their traffic through which is then source-routed through the VPN tunnel to USARun OpenVPN. This instance runs as a server to allow remote connections to the network. This isn’t needed for media services, but is handy to have Networking configured so that certain services are accessible from the local network and/or internet
- Monitor temperature of the machine and trigger a fan if temperature passes a threshold
- Use an LCD screen to show temperature, running service status and other alarms
To fulfil the requirements, a board able to run Linux OS is required.
Raspberry Pi would be the obvious choice, but as far as it hasn't got SATA and it's not so powerful, UDOO Quad Core has been my natural choice.Project in a nutshell
- Build a UDOO-based computer
- Install Linux and related services
- Build basic electronic circuit
- Arduino coding (optional)
- Shell scripting (optional)
- Build enclosure for hardware (optional / not documented)
If you have no experience at all with hardware tinkering, UDOO will be mostly straight-forward for you. The tricky part is powering up your hard drive. At the beginning I had a 2.5" hard drive requiring 5v which is obtained from the red/black wires you see below.
Then I changed the disk to a 3.5" hard drive, that requires 12v and 5v. The 12v is obtained from the yellow/black wires you can see in the picture above. You maybe don't know how to wire up a SATA power plug, do you? If you don't feel confident with it, just click here (note: you do not need to supply the 3.3v wire at all)
Hardware and OS
You will need HDMI cable, keyboard and monitor. You also have to build a SATA Power Cable. This requires 12v, 5v and ground wires. If you have instead a 2.5" SATA disk you just need 5v and ground wires. Just grab yourself any spare SATA-to-Molex power cable you have somewhere and cut off the Molex end. You will then be left with the SATA plug with four wires coming out of it, as below.
If your cable comes with a fifth wire (usually grey or orange coloured) you can cut this off, you won't need it. Wire up the cable as you see in the diagram above. If you do not have a connector for the 5V plug you can pull 5V from the header pin circled in red and use the same ground as you are using for the 12V. [Just a tip: the pins on the UDOO should be labelled underneath the board] Once completed it is as simple as plugging in the other pieces. Once you have the pieces together, you should have something that looks similar to below. This is the hardest part of putting the hardware together.
The electronic side of the project is just composed by:
- LCD screen
- 5V Relay for 12V fan
- Thermistor/temperature sensor
Required parts are:
- 12V DC fan (an old CPU fan will do or this one from Little Bird)
- 16×2 LCD screen (available at Little Bird Electronics)
- 10K Ohm thermistor
- 56 Ohm resistor
- 4.7K Ohm resistor
- 1 Ohm resistor
- 10K Ohm resistor
- 2n2222 (or similar) NPN transistor
- 1N4001 (or similar) diode
- 5v relay switch (available at Little Bird Electronics)
UDOO utilises a Micro SD Card for booting. I’ve used a fast speed 32GB card. 32GB or larger-sized are highly recommended, but be sure it is the fastest you can find (it makes a difference!). I’ve installed Linaro Ubuntu 12.04 which you can find on the UDOO download page. The actual installation of the OS is beyond the scope of this tutorial. There are plenty of instructions on how to do this at udoo.org. However, I found I needed to recompile the kernel in order to use the kernel modules needed for iptables/nat and tap/tun driver (used for the servers firewall and VPN service, respectively). A UDOO forum post explaining how to do this can be found here. Once you are successfully able to boot in to Linux you will be performing the following tasks:
- Install MiniDLNA
- Install CouchPotato
- Install Transmission
- Install OpenVPN
- Install Squid Proxy
- Configure VPN
- Configure firewall/NAT
While it is outside the scope of this post to give instructions on how to install the softwares, you will need to ensure that the softwares starts at boot and you have access to the PID file for the process so that we can alert the Arduino when a process starts and/or fails. There is some great information on using upstart to get your processes to start at boot. The configuration files usually allows you to also specify a PID file location. Below you can find an example of one of my upstart .conf files you could use as a template.
# MiniDLNA launcher. Made by Eddy March 2014 # See related Evernote note for more information # www.makeitbreakitfixit.com description "MiniDLNA is a DLNA server" author "Eddy <email@example.com>" # Stanzas # # Stanzas control when and how a process is started and stopped # See a list of stanzas here: # http://upstart.ubuntu.com/wiki/Stanzas#respawn # When to start the service. My default runlevel is 3 start on runlevel  # When to stop the service stop on runlevel  # Automatically restart process if crashed # respawn # (no arguments after 'respawn' will use # the default of 10 times within 5 seconds) respawn 15 5 # Essentially lets upstart know the process will # detach itself to the background expect fork # Run after process post-start script /root/bin/arduino_serial.sh "Started MiniDLNA" # This doesnt seem to work. I suspect it is because # at this point of boot process Arduino is not ready. # So I will use a different cron script end script # Start the process # This will run the process like you normally would exec /etc/init.d/minidlna start
I can then use a cron script to look for the PID. If the PID file is missing or the PID is not present in the process list, then I run another script to send a message to Arduino (more on this later). I won't go in to detail about the VPN/Proxy/Routing configuration. If you don't know how to access Netflix in your country, just take a look at this other tutorial.ARDUINO & iMX 6 communication
Final steps of this tutorial involves a BASH/Cron solution, because I wasn't a Perl or Python dev when I start tinkering around this project. However, there are many possible solutions you can share if you like, also forking my Github project.
But first of all, you have to focus on the communication between Atmel SAM3X8E and iMX6: you can realize it in many ways.
My favorite, and probably the most natural one, is via a handy serial comms interface /dev/ttymxc3. This is available on the UDOO as it was designed for this type of communication. See the UDOO website for more details and be sure to check out their technical manual.
If you do not have a UDOO, you could still communicate with the Arduino using the serial pins on the Arduino and a serial interface on your Linux machine. This is a little more difficult to do and not covered here.Scripting
The BASH script is simple and scalable. It accepts two arguments via the command line:
- Location of the processes PID file
- Name of the process (this is printing to the Arduino LCD screen, so be careful of character length)
The script assumes that you have given it the correct information. If your PID is renamed or is not able to be read by the script (due to permissions or being locked) then the script will assume the process is down, even though it may not be. Normally this isn’t a problem if you test your script properly.
The script has two main functions:
- Tell the Arduino what to display (or not to) on its LCD screen
- Send the current date and time to the Arduino
Careful how quickly you write to serial comms. Writing too quick will flood the line, especially when using slower baud rates
The Arduino relies on Linux to get the date and time. This is sent if the last time the date/time was sent was > 30 minutes ago.
Grab the latest version of the script I prepared for you below.Schedule Frequency of Process Checks
Cron is used to run the script once a minute. Each process has its own cron line.
Edit your cron by using the crontab -e command. My entries look like:
Now you should be able to test your project by killing processes and seeing if the LCD screen shows you any errors.