MongoDB vs. Postgres; A specific use case
I’ve recently taken a job at Ansible working on the enterprise offering Tower. In case you don’t know, Tower is a front-end for your Ansible playbooks w/ enterprise permission management. I was tasked with evaluating our database needs for a new System Tracking feature that we released. Working remotely at the time forced me to create detailed presentations on my progress and evaluation. I ended up taking the internal presentations and created a blog post about the evaluation process.
http://www.ansible.com/blog/how-we-chose-mongodb-for-ansible-tower-system-tracking-feature
Devstack on EC2 via Ansible
So you want to get an instance of OpenStack running to poke around and see what all the fuss is about without going insane. Welcome to Devstack. Once Devstack is setup you will have access to a web-based control panel with prepopulated data and instances. You will also be able to explore the OpenStack API with v2.0 and v3 authentication (keystone).
Setup
git clone https://github.com/chrismeyersfsu/playbook-devstack
cd playbook-devstack/
sudo ansible-galaxy install -r requirements.yml
- Create an ec2 elastic ip address and override the playbook variable
ec2_elastic_ip
. - Map a domain/subdomain in route53 (or other dns service) to your elasic ip address. (i.e. devstack.example.com)
- Set your webportal login password by overriding the playbook variable
nova_password
Execution
Be aware that the playbook may take > 20 minutes on an ec2 instance to complete.
ansible-playbook site.yml -i ‘devstack.example.com,’
When finished you should be able to visit http://devstack.example.com and login using demo / nova_password
. You should then see the webpanel similar to the image above. The v2.0 and v3 APIs are accessabile via http://devstack.example.com:5000/v2.0/ and http://devstack.example.com:5000/v3/.
Debugging
So things maybe didn’t go according to plan. Here are some playbook invocation variations that you can be used to execute a subset of the tasks.
- Do not provision a new ec2 instance. Only run the devstack install task.
ansible-playbook site.yml -i ‘devstack.testing.ansible.com,` -vvvv –tags “devstack_setup”
- Do not provision a new ec2 instance nor run the devstack install task. Only run the vm instance creation tasks.
ansible-playbook site.yml -i ‘devstack.testing.ansible.com,` -vvvv –tags “devstack_nova”
Beaglebone + Ubuntu
We can install Ubuntu 2-ways.
- To the external SDCARD
- To the internal MMC
Installing to the internal MMC requires an SDCARD to install, but the sdcard is not required after that. The process is mostly the same. The MMC setup vs. the SDCARD setup depends on which image you download.
Installing Ubuntu
MMC: Download the latest file of the form BBB-eMMC-flasher-ubuntu-xx.xx-xxxx-xx-xx.img.xz
SDCARD: Download the latest file of the form ubuntu-12.10-console-armhf-xxxx-xx-xx.tar.xz
Extract the image
sudo apt-get install xz
xz -d *.img.xz
Insert the sdcard into your desktop and note the device path. In my case the device is at /dev/sdc.
meyers@mcbeefy:~/beaglebone$ dmesg
[ 1659.900631] usb 3-1: USB disconnect, device number 3
[ 2664.433700] usb 3-1: new high-speed USB device number 4 using xhci_hcd
[ 2664.709199] scsi7 : usb-storage 3-1:1.0
[ 2665.706903] scsi 7:0:0:0: Direct-Access Generic- SD/MMC 1.00 PQ: 0 ANSI: 0 CCS
[ 2665.707747] sd 7:0:0:0: Attached scsi generic sg3 type 0
[ 2666.334388] sd 7:0:0:0: [sdc] 15519744 512-byte logical blocks: (7.94 GB/7.40 GiB)
[ 2666.334770] sd 7:0:0:0: [sdc] Write Protect is off
[ 2666.334775] sd 7:0:0:0: [sdc] Mode Sense: 03 00 00 00
[ 2666.335066] sd 7:0:0:0: [sdc] No Caching mode page present
[ 2666.335071] sd 7:0:0:0: [sdc] Assuming drive cache: write through
[ 2666.336660] sd 7:0:0:0: [sdc] No Caching mode page present
[ 2666.336667] sd 7:0:0:0: [sdc] Assuming drive cache: write through
[ 2666.337339] sdc: sdc1 sdc2
[ 2666.338721] sd 7:0:0:0: [sdc] No Caching mode page present
[ 2666.338726] sd 7:0:0:0: [sdc] Assuming drive cache: write through
[ 2666.338730] sd 7:0:0:0: [sdc] Attached SCSI removable disk
[ 2666.821868] EXT4-fs (sdc2): mounted filesystem with ordered data mode. Opts: (null)
Flash the image to the sdcard. Substitute <mmc_or_sdcard>.img and /dev/sdX accordingly.
sudo dd if=<mmc_or_sdcard>.img of=/dev/sdX bs=1M
Upon completion remove the sdcard and perform the following:
- Ensure the beaglebone is off
- If you plan on powering the beaglebone with usb, ensure the ethernet is unplugged.
- Insert the sdcard into the beaglebone
- Hold down the button that is by itself near the SDCARD
- Insert the USB power or barrel jack power
- Once the lights begin blinking blue you may release the button
- Wait =~ 45 minutes until all the lights are blue
Once all the lights turn solid blue the MMC is successfully flashed and you may power down your beaglebone (unplug the power), remove the sdcard. Wait a couple seconds, then plug the power back in and the system will boot Ubuntu.
Verifying Ubuntu Install
Find the ip of your beaglebone on your network.
meyers@mcbeefy:~$ sudo nmap -sP 192.168.1.*
Starting Nmap 5.21 ( http://nmap.org ) at 2013-06-30 14:13 EDT
Nmap scan report for 192.168.1.1
Host is up (0.00086s latency).
MAC Address: 00:23:69:0E:20:D7 (Cisco-Linksys)
Nmap scan report for 192.168.1.2
Host is up (0.076s latency).
MAC Address: BC:AE:C5:C4:F6:AB (Unknown)
Nmap scan report for 192.168.1.103
Host is up (0.065s latency).
MAC Address: BC:AE:C5:C4:F6:AB (Unknown)
Nmap scan report for 192.168.1.106
Host is up (0.00023s latency).
MAC Address: 3C:07:71:24:21:4B (Unknown)
Nmap scan report for 192.168.1.107
Host is up.
Nmap scan report for 192.168.1.112
Host is up (0.075s latency).
MAC Address: BC:AE:C5:C4:F6:AB (Unknown)
Nmap scan report for 192.168.1.114
Host is up (0.062s latency).
MAC Address: BC:AE:C5:C4:F6:AB (Unknown)
Nmap scan report for 192.168.1.116
Host is up (0.00072s latency).
MAC Address: C8:A0:30:B2:8E:5D (Unknown)
Nmap scan report for 192.168.1.118
Host is up (0.017s latency).
MAC Address: BC:AE:C5:C4:F6:AB (Unknown)
Nmap done: 256 IP addresses (9 hosts up) scanned in 6.18 seconds
ssh to your beaglebone.
ssh [email protected]
[email protected]’s password: temppwd
Raspberry Pi + Arduino + SPI
This tutorial will show you how to communicate from your raspberry pi to your arduino using 3-wire SPI.
Requirements
- 1 Raspberry pi (running Raspbian)
- 1 Arduino
- 4 wires
Your raspberry pi should be running the newest version of Raspbian. To ensure your system is up-to-date please download and run rpi-update.
Wiring
Arduino
Open your Arduino ide and flash the below code to your Arduino.
Arduino code
Raspberry Pi
With your updated rasbian system you should have the drivers that you need. Now it’s time to load them.
modprobe spi_bcm2708
modprobe spidev
Check to be sure the modules loaded:
lsmod
Module Size Used by
spidev 5944 0
spi_bcm2708 5350 0
snd_bcm2835 21681 0
snd_pcm 81170 1 snd_bcm2835
snd_seq 59528 0
snd_timer 21602 2 snd_seq,snd_pcm
snd_seq_device 6924 1 snd_seq
snd 57427 5 snd_seq_device,snd_timer,snd_seq,snd_pcm,snd_bcm2835
snd_page_alloc 5343 1 snd_pcm
i2c_bcm2708 3822 0
Raspberry Pi Code
Save the below code as spidev_test.c on to your Raspberry Pi and compile it
gcc spidev_test.c -o spidev_test
Running
Plug your Arduino to your desktop via the serial cable. Open the arduino Serial Monitor and set the bitrate to 115200. Now, on the Raspberry Pi, run the compiled code
sudo ./spidev_test
You should see HELLO WORLD print in the Arduino IDE Serial Monitor.
Debugging
- Make sure that your kernel has the required drivers (spi-bcm2708.ko and spidev.ko)
pi@raspberrypi ~/spi $ ls -al /lib/modules/`uname -r`/kernel/drivers/spi/
total 64
drwxrwxr-x 2 pi pi 4096 Aug 10 10:53 .
drwxrwxr-x 23 pi pi 4096 Aug 10 10:53 ..
-rw-rw-r– 1 pi pi 14428 Aug 10 10:53 spi-bcm2708.ko
-rw-rw-r– 1 pi pi 10852 Aug 10 10:53 spi-bitbang.ko
-rw-rw-r– 1 pi pi 15803 Aug 10 10:53 spidev.ko
-rw-rw-r– 1 pi pi 10693 Aug 10 10:53 spi-gpio.ko
Thanks to Nick Gammon for the SPI slave code.
Thanks to Anton Vorontsov for the kernel Documentation spidev_test.c example code.
Arduino Poor Man’s Oscilloscope
This tutorial will show you how to use your Arduino as an oscilloscope. We end the tutorial with a verification portion that uses the Arduino to generate a square wave, requiring a single wire.
lxardoscope
Lxardoscope is another Arduino + real-time graphing project that has the potential to turn an Arduino into an oscilloscope. Unfortunately, I was unable to get any readings (the visual graph remained static).
Poor Man’s Oscilloscope
First, download processing.
http://processing.googlecode.com/files/processing-1.5.1-linux.tgz
gzip -d processing-1.5.1-linux.tgz
tar -xf processing-1.5.1-linux.tar
Desktop Application
Arduino uses a modified RXTXcomm.jar library. This causes a problem when the processing project runs poor man’s oscilloscope and loads the RXTXcomm.jar library bundles with the processing project. Instead, we wish for process to load the modified Arduino RXTXcomm.jar library. To remedy this problem we simply replace processing RXTXcomm.jar with the Android specific RXTXcomm.jar.
rm processing-1.5.1/modes/java/libraries/serial/library/linux64/librxtxSerial.so
rm processing-1.5.1/modes/java/libraries/serial/library/RXTXcomm.jar
ln -s /usr/share/arduino/lib/RXTXcomm.jar processing-1.5.1/modes/java/libraries/serial/library/
Run processing
cd processing-1.5.1
./processing
Running the processing command should result in a GUI application launching that looks a lot like the Arduino idea. Download and open the below code in processing and click play.
Arduino Code
Arduinoscope has a simple arduino component to poll and forward analog 0 to the desktop via the serial connection. Save the below code and flash it to your Arduino.
Verifying the Oscilloscope
To test the oscilloscope we will generate data using the Arduino and feed it in to the analog A0 port to be viewed on our Desktop. Flash the code below to your Arduino.
Connect pin digital pin 13 on the Arduino to analog pin A0. The above code will turn on and off the digital pin to produce a square wave.
Extras
- You can alter the baud rate from 9600 to 115200 in the arduino code as well as the processing code.
- Plus sign zooms in (shift and =) while – zooms out (just -, no shift)
- PWM at a normal 50 HZ is easily observable
- Raspberry Pi pin 18 can generate PWM and the arduino can be used to test it.
- An idle capture looks like:
Dropbox on Raspberry Pi via SSHFS
This tutorial will demonstrate how to mount Dropbox (or any filesystem) over the network on the Raspberry Pi using SSHFS (Secure SHell FileSystem). For this procedure to work for your Dropbox share, you will need another machine somewhere that is running Dropbox, and is accessible to the Raspberry Pi via SSH.
Note: The following is not actually specific to the Raspberry Pi, nor to Dropbox. The tutorial generalizes for other systems and architectures that are not officially supported by Dropbox, as well as for mounting of other non Dropbox shares over the network.
How it works
SSH is a secure protocol for communicating between machines. SSHFS is a tool that uses SSH to enable mounting of a remote filesystem on a local machine; the network is (mostly) transparent to the user.
On the local computer where the SSHFS is mounted, the implementation makes use of the FUSE (Filesystem in Userspace) kernel module. The practical effect of this is that the end user can seamlessly interact with remote files being securely served over SSH just as if they were local files on his/her computer.
Installation (remote host)
The first step is to configure the remote host that the Raspberry Pi will connect to via SSH. It will need to be running Dropbox, if you need to install it, follow the instructions for your respective OS here. If you are not yet a Dropbox user, and this has finally persuaded you to join, signup for Dropbox here.
Next, the remote machine will need to be running OpenSSH server. For Windows and Mac instructions on how to set up OpenSSH server, I recommend this tutorial on Lifehacker. For Linux users, OpenSSH server is available in most every package manager. To install on Ubuntu, for example:
sudo apt-get install openssh-server
Installation (Raspberry Pi)
Now that the remote host is configured, you can setup the mount on the Pi. This first requires installation of the sshfs package. Open a terminal on the Pi and install it like this:
sudo apt-get install sshfs
Then add the user pi to the FUSE users group:
sudo gpasswd -a pi fuse
Once added to the fuse group, log out and log back in again for the change to take effect. Next, create a directory to mount Dropbox (or other remote share)
mkdir ~/Dropbox
Now use sshfs to mount the remote share on the newly created mountpoint. Be sure to change the user@remote-host and path to Dropbox to match your own settings:
sshfs -o idmap=user user@remote-host:/home/user/Dropbox ~/Dropbox
For example, connecting to another machine on your local network will look something like this:
sshfs -o idmap=user [email protected]:/home/michael/Dropbox ~/Dropbox
The idmap=user option ensures that files owned by the remote user are owned by the local user. If you don’t use idmap=user, files in the mounted directory might appear to be owned by someone else, because your computer and the remote computer have different ideas about the numeric user ID associated with each user name. idmap=user will not translate UIDs for other users.
That’s all there is to it! To unmount,
fusermount -u ~/Dropbox
Automount Dropbox on boot
To configure the Dropbox SSHFS to automatically mount at startup, we first need to enable SSH keyless remote login. The first part of this task is to generate an RSA crypto key so we can securely login to the remote machine running Dropbox without entering a password. In a terminal on the Pi, run:
ssh-keygen -t rsa
Hit enter three times when prompted, accepting the default settings for the RSA ssh keys. Now copy the public part of the key to the remote host using the ssh-copy-id command:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-host
You will be prompted for the password on the remote one last time. Once entered, terminal output will confim the key was added sucessfully.
Now that you can login remotely without password, the final task is to configure the share to automatically mount on startup. There are a few ways this could be accomplished, I decided to use cron for the task. Open the global crontab for editing:
sudo crontab -e
And add a line to the end like this:
@reboot sshfs user@remote-host:/home/user/Dropbox /home/pi/Dropbox
Then press CTRL and X to exit the editor, then Y to confirm the changes (if using nano, the default text editior).
That’s it! Reboot the Pi, and your Dropbox share will mount automatically on startup.
Another method to accomplish this task would be to add a line to /etc/fstab to automatically mount the Dropbox SSHFS share.
Reference: https://help.ubuntu.com/community/SSHFS
MSP430 Launchpad + PWM
Inspired by this tutorial.
The following tutorial will describe how perform pulse width modulation using a MSP430g2553 TI Launchpad to control a sparkfun servo motor.
Prerequisites
Please see Cross-Compiling for TI MSP430 Launchpad to setup your development environment.
Hardware
- Servo motor
- MSP430
- Power
I’m using the Arduino to power the servo motors. Alternatively you may use USB, a wall plug, or a battery. The MSP430 is being used to generate the PWM for control.
Connect your servo control wire to MSP430 pin P1.2.
Software
Save the below code as pwm.c
Compile install and run the code!
sudo mspdebug rf2500
erase
prog pwm.elf
run
If your lucky then your device will have moved a bit and you might notice that the device didn’t reach its full range of motion. You will need to play with the SERVO_MIN and SERVO_MAX constants to achieve the devices full range of motion.
Debugging
This section contains hints and debug strategies if things didn’t just magically work for you.
Header File
The biggest trouble I had was getting the correct header file. An incorrect header file did not produce any warnings. The only feedback for a header file that didn’t match my board was the device moving less than 1 degree and behaving non-deterministic. Look at the documentation that came with your board to find the exact device. A list of device headers can be found in the directory /usr/msp430/include/.
Erase
The mspdebug program hosts a suite of commands. A list of commands can be gotten by typing help. The erase command is one that I found late into the night. Be sure to issue the erase command before you issue the load command.
Is it broke?
Often times when things aren’t working you will wonder if you broke the board because you touched some pin, got pissed off and threw it across the room, or your kitty cat Mr. Bigglesworth played kitty frisbee with it. Regardless of the reason you want some feedback that the board is still alive. I like to reload a piece of code that blinks the development board built-in lights LED blinking tutorial.