Jacques Blog

Blog about stuff I do?

NTFS External HD With ownCloud on the Raspberry Pi

Attempting to leave Dropbox, I decided to setup a cloud and sync solution. Dan from BitTorrent.com has a great blog post on how to setup both BTSync and ownCloud up on a Raspberry Pi. I decided to use the same type of setup. Jimmy, a mad iPhone developer, secured it a bit more and made a helpful guide. Not being a sysadmin, this helped me a lot.

Dan’s guide uses an ext4 formatted thumb drive as storage location. I want to use my external hard drive that’s ntfs. I don’t want to format it because I already have tons of stuff on there I don’t want to lose.

The default ntfs file system on Raspbian is read-only so you need to begin by installing ntfs-3g

1
$ apt-get install ntfs-3g

Next you need to have it auto mount on start up using /etc/fstab. Doing a basic mount /etc/sda1 /media/exthdd ntfs-3g defaults 0 0 won.t work. The reason is because by default it mounts to root and the permissions are 777. In order for ownCloud to allow the drive to be used you need 770 as permissions on whatever directory/file you want to use and you want ownCloud to be the owner.

To change permissions on a mounted HD you need to define the uid, gid, fmask and dmask options in /etc/fstab. Depending on your distribution the uid and gid will change. See the ownCloud admin manual

In my case I want www-data to be the owner.

1
2
$ id -u www-data
$ id -g www-data

Say they both return 33 here is what you would add in /etc/fstab

1
/etc/sda1 /media/exthdd ntfs-3g defaults,uid=33,gid=33,fmask=007,dmask=007 0 0

Hope this helps anyone with similar problems.

Document Your Shit

I’m the type of guy who has way too many things on the go. An idea comes to mind, I start working on it for a weekend, then something comes up and I stop. Then if I’m lucky I get back to it 6 months later. I also have a few projects where I work on them a bit more actively but still won.t see an end in the near future. For some of these projects I have some raspberry pies running at home and a VPS for stuff that requires more power.

A while ago I noticed myself forgetting where things where, what server was what on. And I would end up spending half of my time researching stuff I already done just so I could start working on it again. The next day I had the same problem at work, except that I had a wiki to go to and quickly lookup the information.

That’s when I realised I needed to document not only my work stuff, but also my stuff at home. Leave it to a programmer to not have his stuff properly documented or even some of his projects not checked into a repo.

We use confluence at work. I have grown to like it. So I thought why not use it at home? Did you know you could have a 10 user license for only 10$ as long as you host it yourself. That’s pretty sweet. I thought about buying it and setting it up but then I also thought of what I was about to document. I really didn’t need an enterprise level wiki solution. In the end I went with Bootstrap and basic HTML. I basically ripped off the Bootstraps documentation page

The important thing though is that I have my stuff documented. I do have a git repository on my VPS that I host a few of my bigger projects, but my next step is putting up some smaller things I’ve worked on. I’m also thinking of putting up a gitlab.

Laser Trip Wire Activated Missle Launcher!!

Yeah, I’m terrible at updating this blog. Going to work on fixing that.

Ok so a while back I got the missile turret on thinkgeek. The actual company is dreamcheaky. http://www.dreamcheeky.com/thunder-missile-launcher

It only ships with a cheap gui app to control it. However, lots of people online quickly figured out how to talk to it in their code via USB.

I also got Sparkfun’s inventors kit for Arduino recently (Yeah I’m late to the party :P) https://www.sparkfun.com/products/11227

So I decided it would be fun to combine both and make myself a laser trip wire activated missile launcher!

From what I could tell, Python was the easiest way to talk to the missile launcher. I don’t really know Python, but I was able to get something working.

I started off by cloning the stormLauncher project on GitHub https://github.com/nmilford/stormLauncher

Had to install PyUSB since it’s being used to communicate with the missile launcher. http://sourceforge.net/apps/trac/pyusb/

PyUSB uses libusb so you should make sure that’s installed. For windows use libusb-win32 http://sourceforge.net/apps/trac/libusb-win32/wiki

The wiki explains how to install it for a certain device. For the Thunder Misslie Launcher its:

1
2
idVendor=0x2123
idProduct=0x1010

Now came time to test the stormLauncher code. It didn’t seem to work for me. I don’t remember what errors I was getting so I decided to look into the code and strip it down to try and see if I can get it working.

I got a test working with this:

Test missile launcher
1
2
3
4
5
6
7
import usb.util #don't remember if this is actually needed
import usb.core
if __name__ == "__main__"
    dev = usb.core.find(idVendor=0x2123, idProduct=0x1010)
    if dev is None:
        raise ValueError('Turret not found')
    dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00]) # Command to fire the missile

Using an arduino and photo sensor, I made a trip wire that just sends the value of the sensor through the serial cable. I used the same circuit as in this tutorial: http://arduino.cc/en/Tutorial/SwitchCase

The sketch is quite simple. Just output the light level.

Test missile launcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const int sensorPin = 0;
int lightLevel, high = 0, low = 1023;

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    lightLevel = analogRead(sensorPin);
    Serial.print(" Light level: ");
    Serial.println(lightLevel);
    delay(1000);
}

After that I looked up how to do serial communication with python. Basically the program reads the serial input coming from the arduino. Once the value passed by the arduino hits a certain threshold, this means the laser is no longer in contact with the light sensor so fire away! I got the light value by testing around with the laser so that might have to change. I also added a sleep time because the missile launcher isn’t the fastest. Note that I have code in there to remove the “Light level: ” part that is sent. I could/should have just ommited that so that I didn’t have to parse it out.

Like I said I don’t really know python so this was the result of playing around and reading a few things online. It works but it can be improved.

Here is the code:

Laser trip wire triggered missile launcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import serial
import usb.core
import usb.util
import re
import time

def main():
  # find our device
  dev = usb.core.find(idVendor=0x2123, idProduct=0x1010)
  
  # was it found?
  if dev is None:
      raise ValueError('Turret not found')

  # Set up serial communication with arduino
  sp = serial.Serial()
  sp.port = 'COM4'
  sp.baudrate = 9600
  sp.parity = serial.PARITY_NONE
  sp.bytesize = serial.EIGHTBITS
  sp.stopbits = serial.STOPBITS_ONE
  sp.timeout = 2
  sp.xonxoff = False
  sp.rtscts = False
  sp.dsrdtr = False

  sp.open()
  pattern = re.compile('[a-zA-Z: ]*([0-9]+)')
  value = None
  #confirm we are reading data from the serial port
  while not value:
      value = sp.readline()
  print value
  
  # loop and wait for wire to be tripped
  while 1:
      value = sp.readline()
      m = pattern.match(value)
      lightValue = m.group(1)
      #print lightValue
      if int(lightValue) > 100:
          print "fire in the hole"
          dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00])
          time.sleep(5) # the missle launcher can only shoot about once every 5 seconds
  
  
  sp.close()

if __name__ == "__main__":
  main()

My next plan is hooking up the missle launcher to my RaspberryPi and and having the light sensor hooked up to an XBee Module. This way it’s more mobile.

Getting the USB-UIRT to Work With the Raspberry Pi

One thing I’m working on is controlling my living room with my Raspberry Pi. Eventually I want to get lighting and wall sockets working but for now I’m concentrating on my multimedia. My projector and audio system work with IR remotes so I decided to use the USB-UIRT in order to control them. Unfortunately, there isn’t much up to date information on how to get it working on linux. However, most of it still works.

I’m using the Arch Linux ARM distribution for my Raspberry Pi so what I did might not work with other distributions. From what I can tell, it shouldn’t be all that different to get it working on Wheezy.

To get the USB-UIRT working you need LIRC (Linux Infrared Remote Control) using the uirt2_raw drivers.

First thing you need to do is make sure you have initscripts installed.

1
$ pacman -S initscripts

Then you can install LIRC.

1
$ pacman -S lirc

After this I plugged in the USB-UIRT and checked to see if it was detected.

1
$ dmesg | grep -i usb

Look for something like “FTDI USB Serial Device converter now attached to ttyUSB0”.

Now I know my USB-UIRT is attached to ttyUSB0. And we know we have to use uirt2_raw as the driver. Time to configure LIRC. On some sites I read that you had to configure /etc/lirc/hardware.conf but I couldn’t find the file and creating it did nothing for me. Eventually I found that the file we want to edit is /etc/conf.d/lircd.conf. It also had different variable names. Similar but different. I tried searching for up to date documentation on the file but didn’t really find much. I didn’t really search to hard though, but it wasn’t hard to guess what to put where. Here is my configuration file.

1
2
3
4
5
6
7
8
#
# Parameters for lirc daemon
#

LIRC_DEVICE="/dev/ttyUSB0"
LIRC_DRIVER="uirt2_raw"
LIRC_EXTRAOPTS=""
LIRC_CONFIGFILE=""

Now before you can send and receive ir commands from a remote, you need tell lirc about that remote. This is done in the /etc/lirc/lircd.conf file. You can find a bunch of remotes already defined at http://lirc.sourceforge.net/remotes/.

I was lucky to find one of my remotes and load it up.

1
2
$ wget http://lirc.sourceforge.net/remotes/logitech/Z-5500D
$ cp z-5500D /etc/lirc/lircd.conf

You can have more then one remote loaded (just append to current lircd.conf file).

Start up lirc.

1
$ /etc/rc.d/lircd start

Run irw.

1
$ irw

Now push buttons on the remote to test it.

1
2
3
4
0000000000000001 00 vol+ logitech_z5500
0000000000000001 01 vol+ logitech_z5500
0000000000000001 02 vol+ logitech_z5500
0000000000000001 03 vol+ logitech_z5500

If you can’t find your remote there is a wizard to help create a configuration file. You can read how to use it at https://wiki.archlinux.org/index.php/LIRC#Making_a_configuration_file

Remember to set the device and driver for irrecord.

1
$ irrecord -d /dev/ttyUSB0 -H uirt2_raw /tmp/my_remote

Well that’s what got it working for me. I Hope I didn’t forget anything (did this last week) and that it helps. Here are the links I used:

https://help.ubuntu.com/community/Lirc_USB-UIRT

https://wiki.archlinux.org/index.php/LIRC

Eventually I’ll settup a comment section. Feel free to email me some feed back. Although my email isn’t listed, I’m sure you can figure it out ;)

Obligatory First Post

So I’m starting a blog. I’m not sure how much I’m going to post, but hopefully it’s going to be often enough. What is it about? I’m not exactly sure yet. So far the idea is to document stuff I’m working on. Posting my solutions to problems I have. Hopefully something comes of this. If you learn something, awesome. If you can help me out in what I’m doing by pointing out stuff I miss or have wrong, even better. Ok well not better.. I guess it’s just as awesome as you learning something. I don’t want to be selfish here.

A few things to keep in mind. I’m not the best writer. I plan on using spell check. If you’re going to grammar Nazi me, be cool about it please. No one likes a douche.

Oh and bare with me while I learn this octopress stuff.

Thanks.