TL-WR703N Webcam Streaming

Get a router, load it with the standard image.

Set-up wireless or any other networking changes.  See an example here.

Plug in the camera

Now there are two ways to get mjpg-streamer to auto-start, there is an easy way and an elegant way.
Easy way : Just add the command to the auto start script using LuCi…
Elegant way : Edit the configuration files /etc/init.d/mjpg-streamer and /etc/config/mjpg-streamer

  1. Telnet/SSH into the router

  2. Run the following command :
    opkg update
    opkg install kmod-video-uvc 
    opkg install mjpg-streamer
    mjpg_streamer -i “./input_uvc.so -n -r VGA -f 6 -d /dev/video0″ -o “./output_http.so -p 8080 -n” 
    This command uses VGA (640×480) resolution “-r VGA” at 6 frames per second “-f 6″.

  3. If that doesn’t work and an error appears, it most likely means your camera doesn’t support JPEG images.  If so, try the following command instead :
     mjpg_streamer -i “./input_uvc.so -n -q 60 -r QVGA -f 6 -d /dev/video0″ -o “./output_http.so -p 8080 -n” 
    This command forces mjpg-streamer to convert into raw into JPEG at (-q) quality 60, at resolution (-r) QVGA, this can be “160×120″ for example.  The frame rate is specified by the -f (6).  This method is MUUUUUUUUCH more CPU intensive and you might have to tweak the resolution and frame rate down.

  4. Using a device connected to the router, use a web browser (e.g. Chrome) to connect to the following to get a live view:
     http://192.168.1.1:8080/?action=stream 
  5. You can also get a single snapshot at:
     http://192.168.1.1:8080/?action=snapshot 
  6. If you need to play around with the commands, use CTRL-C to kill mjpg-streamer and try again.  Avoid high resolutions (e.g. 1920×1080) as that will just crash the router.  I used 640×480 at 25 frames per second relatively happily on a JPEG enabled camera (e.g. Logitech/Microsoft ones, not the cheap no brand ones).

  7. Once you have a workable set-up, copy the command you have and put it into the local start-up.  Append the command line with an ampersand “&” so it runs in the background.  e.g.
    mjpg_streamer -i “./input_uvc.so -n -r VGA -f 6 -d /dev/video0″ -o “./output_http.so -p 8080 -n” & 
            OR
    [ -c "/dev/video0" ] &&  /usr/bin/mjpg_streamer -b -i "input_uvc.so -r 352x288 -f 15 -q 80 -y" -o "output_http.so -p 8080 -w /tmp" 
  8. In Luci, select the Systems tab, then select Startup, scroll down to the Local Startup section and add your command to the box and press save and apply.

Control Arduino to Openwrt

The Arduino is plug into the USB port of TP-LINK TL-WR1043ND allow the router to control the Arduino.

Install FTDI USB Serial

  opkg update
  opkg install kmod-usb-serial-ftdi

Install USB Device drivers

If you are using Teensy or Arduino Uno

opkg install kmod-usb-acm

If you are using PL2303 based USB/serial adapters

opkg install kmod-usb-serial-pl2303

If you are using CP201x based USB/serial adapters

opkg install kmod-usb-serial-cp210x 

Verify USB Serial driver

Plug in Arduino to the USB port of router and execute the following command.

 dmesg | grep -i usb 
 opkg install usbutils
 lsusb

FTDI USB Serial Device converter is attached to ttyUSB0

[   10.780000] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
[   10.810000] USB Serial support registered for pl2303
[   10.810000] pl2303 1-1:1.0: pl2303 converter detected
[   10.830000] usb 1-1: pl2303 converter now attached to ttyUSB0
[   10.830000] usbcore: registered new interface driver pl2303
[   10.840000] pl2303: Prolific PL2303 USB to serial adaptor driver

root@OpenWrt:~# ls /dev bus mtd0 mtd3 mtdblock0 null shm ttyS11 ttyS3 ttyS9 console mtd0ro mtd3ro mtdblock1 port tty ttyS12 ttyS4 ttyUSB0 full mtd1 mtd4 mtdblock2 ppp ttyATH0 ttyS13 ttyS5 urandom

root@OpenWrt:~# lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

Install Serial to Net ( ser2net or socat )

To install ser2net :

 
opkg install ser2net

vi /etc/ser2net.conf

To make ser2net listen on TCP port 1234, append 1 line to the end of /etc/ser2net.conf

1234:raw:0:/dev/ttyUSB0:9600

Start ser2net manually

ser2net

ser2net will start based on ser2net configuration file

To install socat :

  opkg install socat

Start socat manually (Arduino Duemilanove) socat tcp-l:1234,reuseaddr,fork file:/dev/ttyUSB0,nonblock,raw,echo=0,waitlock=/var/run/tty,b9600 This will open a tcp 1234 port & set to baud rate 9600. The usb serial port will be /dev/ttyUSB0

Start socat manually (Arduino Uno R3 USB chip) socat tcp-l:1234,reuseaddr,fork file:/dev/ttyACM0,nonblock,raw,echo=0,waitlock=/var/run/tty,b9600 This will open a tcp 1234 port & set to baud rate 9600. The usb serial port will be /dev/ttyACM0

Open the port

This is particular important , it use to prevent autoreset on initiation of serial.

cat /dev/ttyUSB0 

You can open the port on every router reboot

    Login to router Click System -> Startup Scroll down the screen until you see Local Startup

Communicate with Arduino

Try realTerm from here.

1. Run realTerm
2. Click on Port tab
3. Enter 9600 for Baud since the default baud rate for the Arduino is set to 9600
4. Enter 192.168.1.1:1234, where 192.168.1.1 is the router IP & 1234 is the port. Make sure it match with the ser2net or socat settings.
5. Click on Open button
6. Click on Send tab
7. Enable +CR from EOL since the Arduino require Carriage Return as the termination.

Labels: my.