Suprise 2014

I’m going to make something for “Sinterklaas”. Everybody will create something that resembles the person you are giving it to. This is called a “suprise”.
Because everyone can read this I won’t tell what I’m going to make yet. But I’ll write down all the technical details.


The suprise will be build arround an beaglebone with a wifi module and 4 servo’s attached.
The beaglebone:

Adhoc network
– Hostapd
– Dhcp server
– httpd webserver
– cgi script controlling the servo’s

Setting up the beaglebone


I got an standard Ubuntu Image:

https://rcn-ee.net/deb/rootfs/trusty/ubuntu-14.04-console-armhf-2014-08-13.tar.x

Because this should cost a minimum amount of time and it’s going to be quite some project.

Controling the servo’s

Note: the driver of the beaglebone is glitchy. You can only set the duty cycle of one of the 3 channels. A0, A1 or A2. To get around this issue get your self this driver:
https://github.com/SaadAhmad/beaglebone-black-cpp-PWM

Setup the PWM’s

#!/bin/bash
cape_mgr=/sys/devices/bone_capemgr.8/slots
pwm_dir=/sys/devices/ocp.3/

pwm0="${pwm_dir}pwm_test_P9_14.*"
pwm1="${pwm_dir}pwm_test_P9_21.*"
pwm2="${pwm_dir}pwm_test_P8_46.*"

#Param 1: pwm
init () {
echo Init $1
echo 0 > $1/run
echo 0 > $1/polarity
echo 20000000 > $1/period
echo 1500000 > $1/duty
echo 0 > $1/polarity
echo 1 > $1/run
}


echo $cape_mgr
echo am33xx_pwm > $cape_mgr
echo bone_pwm_P9_14 > $cape_mgr
echo bone_pwm_P9_21 > $cape_mgr
echo bone_pwm_P8_46 > $cape_mgr

sleep 5

init ${pwm0}
init ${pwm1}
init ${pwm2}

Controlling the servo's

#!/bin/bash pwm_dir=/sys/devices/ocp.3/ pwm0="${pwm_dir}pwm_test_P9_14.*" pwm1="${pwm_dir}pwm_test_P9_21.*" pwm2="${pwm_dir}pwm_test_P8_46.*" minimum=1050000 #ns maximum=1950000 #ns range=`expr $maximum - $minimum` #ns hs311_range=90 #degrees step_degree=`expr $range / $hs311_range` echo range is $range with range per step $step_degree #Param 1: pwm #Param 2: Degrees motor_degrees () { duty=$(( $step_degree * $2 + $minimum )) echo $1 selected duty cycle $duty echo $duty > $1/duty } motor_degrees ${pwm0} $1 motor_degrees ${pwm1} $2 motor_degrees ${pwm2} $3

Setting up httpd

– Install httpd
– It was already installed but to get CGI working I had to execute:

Required:

sudo a2enmod cgi
sudo service apache2 restart

Setting up adhoc network with wireless tool

Edit /etc/network/interfaces

auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-mode ad-hoc
wireless-essid "Suprise2014"

Setting up dhcp server

Install udhcpd (it was already installed )
Edit /etc/udhcpd.conf

start      192.168.1.2
end        192.168.1.50
interface  wlan0
max_leases 50
option subnet 255.255.255.0

And your done! Reboot your system and everything becomes active!

Hostapd

The general idea was to connect to the adhoc network with an android device, bummer android doesn’t support adhoc…
So I’m going to replace the adhoc solution with hostapd.
Default hostapd from the package manager didn’t support nl80211 drivers
As a refference follow the guid on http://wireless.kernel.org/en/users/Documentation/hostapd or perform the steps below.

So I had to compile it my self:

– Clone repo
– Edit default config and remove the comment character “#”  from the line:\

CONFIG_DRIVER_NL80211=y

Steps taken:

git clone git://w1.fi/srv/git/hostap.git
cd hostap/hostapd
cp default_config
apt-get install libnl-dev libssl-dev openssl
make
make install

Config hostapd (source http://fleshandmachines.wordpress.com/2012/10/04/wifi-acces-point-on-beaglebone-with-dhcp/)

Edit /etc/hostapd/hostapd.conf

### Wireless network name ###
interface=wlan1
#
### Set your bridge name ###
#bridge=br0

#driver
driver=nl80211

country_code=HU

ssid=beaglebone

channel=7

hw_mode=g

# # Static WPA2 key configuration
# #1=wpa1, 2=wpa2, 3=both
wpa=2

wpa_passphrase=yourpassword

## Key management algorithms ##
wpa_key_mgmt=WPA-PSK
#
## Set cipher suites (encryption algorithms) ##
## TKIP = Temporal Key Integrity Protocol
## CCMP = AES in Counter mode with CBC-MAC
wpa_pairwise=TKIP
#rsn_pairwise=CCMP
#
## Shared Key Authentication ##
auth_algs=1
## Accept all MAC address ###
macaddr_acl=0
#enables/disables broadcasting the ssid
ignore_broadcast_ssid=0
# Needed for Windows clients
eapol_key_index_workaround=0

Test your config

hostapd /etc/hostapd/hostapd.conf

Remove all trailing whitespacing if you get any errors.

New /etc/network/interfaces

auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
hostapd /etc/hostapd/hostapd.conf
#wireless-mode ad-hoc
#wireless-essid Suprise2014

The same DHCP config could be used because we are on the same interface.

Leave a Reply

Your email address will not be published. Required fields are marked *