DIY NAS with Openmediavault and UDOO – pt. 3 Hardware set up


In this third and last part of our UDOO Powered Network Attached Storage, we are going to see how to spice things up.
What we really don’t like about our shiny brand new NAS is that it only goes from A to B, just doing perfectly fine its job. We’re makers, and we want our devices to be smarter, funnier and more interactive. So, what’s the plan?
Nerdgasm!

One of the main purposes of our NAS (at least here, in UDOO’s HQ) is to download and seed our OS images torrents. We’re eager to test new distros as soon as they come out, so we are patiently waiting for those torrents to finish. Why not having a feedback when this happens?
Complying to nerd’s bible, we are going to hack a little our NAS, enabling it to give us a visual and auditory feedback when a torrent is completed.
The idea is this. At a torrent completition, a sound will come out from our NAS. It will be a ringing “Bazinga”. You know why.

Then, we’ll have a LED to turn on and light up a small spinning disk, with the word Bazinga on it.

How are we going to make it happen? We setup OpenMediaVault to launch a bash script when a torrent download is completed. This script launchs two kind of actions:

  • Plays the file Bazinga.wav on the Analog jack, with aplay
  • Sets the serial port properly, and sends “1” on it

Then, we upload an Arduino sketch on UDOO’s SAM3x, which will turn pin 7 (LED) and pin 8 (motor) to HIGH state for 4 seconds when “1” is received via serial. That way, the motor will spin and the light will turn on when a torrent is completed.

Let’s do it!

This is the software configuration guide, to see how to wire things up, just refer to the Video of this project.

First, let’s configure OpenMediaVault, to launch the Bazinga.sh script on Torrent Completition.
Before doing that, we just want to make sure the serial port is properly set, at the same speed of the serial reading set in the Arduino Sketch, and with proper permissions. So we connect to OpenMediaVault with SSH add this line to /etc/rc.local

sudo stty -F /dev/ttymxc3 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

This ensures that both Imx6 and SAM3x could talk to each other via serial.
Then, we create the bazinga.sh script, on /bazinga/bazinga.sh

cd /
mkdir bazinga
nano bazinga.sh

And we write the bazinga script:

sudo echo 1 > /dev/ttymxc3 &
sudo aplay /bazinga/bazinga.wav

Ctrl + x to save.

Then, give execution permission to our script with

sudo chmod a+x bazinga.sh

This is a very basic script: it just writes 1 on serial (/dev/ttymxc3) and plays bazinga.wav, which we previously uploaded into /bazinga/.

To be sure that the script is executed with proper permission, we just give Transmission root privileges. To do so, we just edit the transmission starting script with

sudo nano /etc/init.d/transmission-daemon

and edit the USER line, making it look like that

NAME=transmission-daemon
DAEMON=/usr/bin/$NAME
USER=root
STOP_TIMEOUT=30

Save with ctrl+x. And reboot

Please note that this is a dirty trick, as giving Transmission root privileges may not be the best idea in the world. But we can be safe with that, as it is the quickest way. If you plan to implement this, it is strongly suggested that you just give openmediavault root privileges only for that file.

Then we configure OpenMediaVault to launch this script, on torrent completition. To do so we log in into the OpenMediaVault administration panel, select Transmission then server, and scroll till the end. Then simply select “Run script at torrent completition”, and insert
/bazinga/bazinga.sh on script path. Then save it .
transmissionbazinga
To check that everything is allright, we just read on /dev/ttymxc3 with

cat /dev/ttymxc3 

And, if we start a torrent, when it completes we should have as output:

1

Ok, then we just upload the Arduino Sketch on the Arduino compatible controller, the SAM3x.

This is our sketch. It basically listens on serial, and when it reads “1” it sets pin 7 and 8 to HIGH state for 4 seconds. This will make the LED to turn on, and our motor to spin.

int LEDPIN   = 7;
int SERVOPIN = 8;

void setup() {
  Serial.begin(115200);
  pinMode(LEDPIN, OUTPUT);
  pinMode(SERVOPIN, OUTPUT);  
}

void loop() { 
  int slot = 0;
  while (Serial.available()) {
	char inChar = (char)Serial.read(); 

	if (inChar == '1') {
  	digitalWrite(LEDPIN, HIGH);
  	digitalWrite(SERVOPIN, HIGH);
  	delay(4000);
  	digitalWrite(LEDPIN, LOW);
  	digitalWrite(SERVOPIN, LOW);
	} 
  }

  delay(15); 
}

As you may have noticed, there’s delay(15); at the end of the sketch. This is just a precaution in order to avoid serial overload. We just tell the SAM3x to wait 15 milliseconds from one read to another.
After it has been compiled and uploaded, here we are! Our software configuration is completed.
Just set the wirings as shown in the Video, and your UDOO Powrered NAS with UberNerd powers is complete!

By:

Submit a comment