index

Setting up a tool chain for Openwrt Attitude-adjustment
on a NSLU2 (Slug) and on a WR703N
in order to use an Easycap video capture USB dongle

There is an option to add an Easycap driver in Attitude-adjustment but it has to be specially called up
- it is not available in Backfire or earlier - you cannot create an ipkg

In Linux Mint 13 in VMWare on an iMac I did (with many thanks to Michel who did all the clever bits)

In a non-root folder checkout the Attitude Adjustment branch of OpenWrt-

svn co svn://svn.openwrt.org/openwrt/branches/attitude_adjustment

A patch was created by Michel to enable the Easycap driver in the kernel

The patch applies to the Intel IXP4xx target for the Linksys NSLU2
as well as ar71xx for the WR703N

It was put into /Michel/easycap.patch

Without changing anything to the downloaded files

patch -p0 < Michel/easycap.patch

then do

make menuconfig - choose Intel IXP4xx and nslu2 - (or ar71xx and WR703N) - nothing else chosen yet

make kernel_menuconfig
- does lots of work - does some compiles and installs - creates a dl directory -
- does a big download of ftp://ftp.all.kernel.org/pub/linux/kernel/v3.x/linux-3.3.8.tar.bz2

when the menu page shows (it takes some time)
in multimedia support make * not m
video for linux make * not m
sound card support make * not m
Advanced Linux sound Arch.. make * not m

then go back and get more drivers by doing

./scripts/feeds update
./scripts/feeds install -a

then

make menuconfig

and add

i2c - kmod-sound-core - kmod-usb-audio - kmod-usb-serial-ftdi - kmod-video-core and kmod-video-easycap and kmod-video-uvc

mjpg-streamer nano vsftpd luci and any others needed if router memory allows

then -

make -j3

Cross your fingers etc - - then after a long wait look in BIN for the files to flash the router

Blassic basic (for Slug at present)
I tried to cross compile Blassic in the attitude tool chain but it failed - also usbscale failed -(it was OK in the Backfire chain)

Blassic for Backfire runs after
opkg install libstdcpp

and usbscale for Backfire also runs OK


The Results

After getting the Slug to run with the new firmware I did -

opkj install usbutils

for lsusb to see what is on the USB bus

Running the Easycap dongle

I was not happy with the "muddy" picture quality
- the camera was known to be good (it is in the white box, pic below this pic) and gave this -

The USB camera shown above only costs about £4 on eBay
(it is the one with USB and audio plugs on it)
The cheap camera gets pictures like -

So is Easycap worth the effort?

There is a fix!
I did
-

opkg install v4l-utils

That lets you change the contrast etc - but it kills the MJPG stream - so I made and ran this script-

#!/bin/sh
# /www/pic-ctrl.sh

kill -9 `pidof mjpg_streamer`

v4l2-ctl --set-ctrl brightness=210
v4l2-ctl --set-ctrl contrast=250
v4l2-ctl --set-ctrl saturation=225

v4l2-ctl --list-ctrls

mjpg_streamer -i "input_uvc.so -d /dev/video0 -f 5 -y -q 80 -n" -o "output_http.so -p 8087 -w /webcam_www" -b
ps

You can run this for 2 or 3 times then the Slug crashes
- but having got the right values reboot and run it once and see a much improved picture -

Care - you can spend all day playing with the values!

to do

check this page for an error correcting stream (use Google Chrome to translate)


Misc notes

Before doing a build with make you can pre-set the contents of /etc/config/network

to

config 'interface' 'loopback'
option 'ifname' 'lo'
option 'proto' 'static'
option 'ipaddr' '127.0.0.1'
option 'netmask' '255.0.0.0'

config 'interface' 'lan'
option 'ifname' 'eth0'
option 'type' 'bridge'
option 'proto' 'static'
option 'netmask' '255.255.255.0'
option 'gateway' '192.168.0.230'
option 'dns' '192.168.0.230'
option 'ipaddr' '192.168.0.55'

by putting above file into
/home/user/attitude5/files/etc/network

Then it works on my 192.168.0.xxx network at first boot



 

Keep mjpg-streamer alive

Try this script (with thanks to from Janis and Dane) - -NB not yet working for me

#!/bin/sh
# file - /www/init_mjpg-streamer.sh

if ps |grep mjpg |grep -v grep; then
echo "mjpeg is running all OK"
else echo "mjpeg is not running, starting"

mjpg_streamer \
-i "input_uvc.so \
-d /dev/video0 -f 5 -y -q 80 -n" \
-o "output_http.so -w /www/webcam" \
-b

fi

but

running that I see

root@OpenWrt:~# /www/init_mjpg-streamer.sh
2529 root 8792 S mjpg_streamer -i input_uvc.so -d /dev/video0 -f 5 -y -q 80 -n -o output_http.so -p 8087 -w /webcam_www -b
2538 root 1228 S {init_mjpg-strea} /bin/sh /www/init_mjpg-streamer.sh
mjpeg is running all OK
root@OpenWrt:~#

but if I kill pid 2529 and run it again it still says

root@OpenWrt:~# /www/init_mjpg-streamer.sh
2564 root 1228 S {init_mjpg-strea} /bin/sh /www/init_mjpg-streamer.sh
mjpeg is running all OK

Make a cron job -
*/10 * * * * /www/init.sh

this makes /www/init.sh run every 10 minutes.



"Ready to run" images

Attitude-adjustment for nslu2
see the Readme file

- Attitude-adjustment seems to be a bit bloated but it is needed to run the Easycap driver
- there is no more room to run opkg install xxxx - but it it does what I need it to

usbscale
python-mini
Blassic basic
nano
httpd (with cgi scripting = part of busybox - NB! add cgi tools for httpd if compiling)
(web page push script fails - use Backfire bin for that) - I could not add the cgi package for lighttpd
lsusb (lets you see the usb devices)

Download

Backfire for nslu2
see the Readme file
usbscale
python-mini
Blassic basic (for device control within scripts)
nano
mjpg-streamer
vsftpd (for non secure ftp)
lighttpd (with cgi scripting)
(web page push script works)

Download

The PC equivalent of the Linux upslug2 works better than upslug2 on my LAN and my backup is here


Compiling simple C programs with a Makefile

I have a helloworld folder in the /package directory that compiles OK in my backfire toolchain but not my Attitude toolchain see this

I want to compile various i2c device driver programs and I attempted in all files to replace the text helloworld with i2c-driver-xxx and create a new C file in the /package/i2c-driver-xxx/src folder.
That never worked.

The easiest way is to paste the driver code into the helloworld.c file in place of the code that made the helloworld
NB! The helloworld program has to be selected with Y (*)
Then do -
make package/helloworld/compile V=99

Then rescue the binary called helloworld from
/home/user/backfire/build_dir/target-armeb_v5te_uClibc-0.9.30.1_eabi/


change the name from helloworld to i2c-driver-xxx and ftp it to the router

There is also a helloworld_1_ixp4xx.ipk in -
/home/user/backfire/build_dir/target-armeb_v5te_uClibc-0.9.30.1_eabi/

This backup of the helloworld folder is based on a helloworld folder that compiles OK within the /package folder in my backfire toolchain - it currently contains an i2c driver.
Paste the new code to replace that.

Programs created in the Backfire chain run OK in the Attitude-adjustment slug


Using the nslu2 LEDs to drive 4 outputs for external device control

The following commands control the LEDs - disk-1, disk-2, ready and status
(1 for ON and 0 for OFF) - used here with Attitude-adjustment firmware.
The ethernet activity LED is not modified.

echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-1/brightness
echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-1/brightness

echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-2/brightness
echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-2/brightness

echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:red:status/brightness
echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:red:status/brightness

echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:green:ready/brightness
echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:green:ready/brightness

The disk-1 and disk-2 LEDs are connected on one side to 3.3 volts (at the edge of the circuit board)
The ready and status LEDS are connected to 0 volts at the side away from the edge - they share a cube shaped plastic moulding

The circuit below uses transistors to drive diodes (these will control the LEDs on my birdbox cheap USB camera)

circuit
Almost any small signal transistor will do the job but note that the A type LEDs need a PNP transistor
The resistor values are not critical.

The NPN transistor collectors could each be connected to a relay to 5 volts (with back-emf catching diode).
With a suitable resistor to 5 volts the collectors could drive 5 volt TTL or MOS logic chips.

Switch the outputs with Blassic basic -

#!/usr/sbin/blassic
' /www/flash.bas

LABEL StartAgain

SHELL "echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-1/brightness"
PAUSE 100
SHELL "echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-1/brightness"

SHELL "echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-2/brightness"
PAUSE 100
SHELL "echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:green:disk-2/brightness"

SHELL "echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:red:status/brightness"
PAUSE 100
SHELL "echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:red:status/brightness"

SHELL "echo 1 > /sys/devices/platform/leds-gpio/leds/nslu2:green:ready/brightness"
PAUSE 100
SHELL "echo 0 > /sys/devices/platform/leds-gpio/leds/nslu2:green:ready/brightness"

GOTO StartAgain

Blassic basic for OpenWrt Attitude-adjustment and Backfire is here - put it into usr/sbin or similar