FTDI on WGT634u Running OpenWRT Backfire

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 24-04-2012-05-2008

0

In this post I will document the modules that installed to get a WGT634u running OpenWrt Backfire to recognize a DFRobot.com FTDI (http://www.dfrobot.com/index.php?route=product/product&filter_name=ftdi&product_id=147).  In order to trouble shoot this better I am connected to the router via a usb to serial TTL cable.  Instructions on how to build one can be found here.

First we need to install the USB modules. This router seems to support usb2 and ohci so these are the ones that I installed.

opkg update
opkg install kmod-usb2
opkg install kmod-usb-ohci

Note: You can use the following command to see what usb is supported (uhci or ohci):

cat /proc/bus/usb/devices

Next we will install the modules for the FTDI:

opkg update
opkg install kmod-usb-serial-ftdi

Note that when you plug the FTDI into the Arduino you should connect the tx to tx, rx to rx, and gnd to gnd. It seems that the usb on my router does not have the output to power the Arduino through the FTDI so I am powering it separately with a 9v DC adapter.

Netgear WGT634u as a Wireless Client Running OpenWRT Backfire

Posted by Max Power | Posted in Netgear WGT634u | Posted on 14-04-2012-05-2008

0

In this post I will show how to configure your Netgear WGT634u, running OpenWRT Bsckfire, as a wireless client.  This means that it will allow devices connected to its LAN to be connected to a wireless router LAN.

  1. First you will have to enable the wireless as shown in this post.
  2. On the LuCI>Network>wifi>wifi0 device info set the network to “WAN” and mode to “client“.

Here are my config files for reference (/etc/config/):

Wireless

config 'wifi-device' 'wifi0'
	option 'type' 'atheros'
	option 'channel' 'auto'
	option 'diversity' '0'
	option 'disabled' '0'
 
config 'wifi-iface'
	option 'device' 'wifi0'
	option 'ssid' 'ssid'
	option 'network' 'wan'
	option 'mode' 'sta'
	option 'encryption' 'wep'
	option 'key' '******************'

Network

config switch eth0
	option enable 1
 
config switch_vlan eth0_0
	option device "eth0"
	option vlan 0
	option ports "0 1 2 3 5"
 
config switch_vlan eth0_1
	option device "eth0"
	option vlan 1
	option ports "4 5"
 
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 type bridge
	option ifname "eth0.0"
	option proto static
	option ipaddr 192.168.1.1
	option netmask 255.255.255.0
 
config interface wan
	option ifname "eth0.1"
	option proto dhcp

Python Interface for Arduino Uno Using a Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 29-11-2011-05-2008

0

Edit:  I abandoned this method in favor of a simpler method.  I am using a FTDI to communicate and just executing serial commands with PHP.  You can see how I am doing this in this post.  I left this up thinking that it may be useful to someone else.  However, keep in mind it may not be complete.

In this post I will show you how I was able to communicate with my Arduino Uno connected to my Netgear WGT634u running OpenWrt Backfire.  This is a baby step toward being able to control the Arduino Uno from a website hosted by the Netgear WGT634u.

Setup

First we will install Python (python_2.6.4-3_brcm47xx.ipk) :

opkg update
opkg install python

Next we will install the PySerial module (pyserial_2.4-1_brcm47xx.ipk):

opkg update
opkg install pyserial

Now we need to edit the PySerial module to disable DTR, I discus this a bit (here):

cd /usr/local/lib/pythonX.Y/site-packages/serial
rm serialwin32.pyc
vi serialwin32.py

Change the following line:

self._dtrState = win32.DTR_CONTROL_ENABLE

to:

self._dtrState = win32.DTR_CONTROL_DISABLE

Now lets create a sample script and test it. First make a folder to put the python script in:

mkdir /python

Create the sample script:

vi /python/arduino_com.py
import sys
import arduino
 
ser = arduino.Serial('/dev/ttyACM0',9600)
 
if (len(sys.argv) >; 1):
print sys.argv[1]
ser.write(sys.argv[1])

Now lets test it.. To test the script I am using the LED example included with the Arduino software. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino. After you upload the sketch, plug it into the WGT634u and lets test it out. In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.

Turn the LED on:

/python/arduino_com.py H

Turn the LED off:

/python/arduino_com.py L

You can call you script from a webserver using cgi. Place the following file in your bin-cgi folder:

#!C:\Python27\python.exe -u
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import arduino # For serial com (modified pyserial)
 
print "Content-type: text/html"
print
 
print """
Sample CGI Script

Sample CGI Script

"""
 
form = cgi.FieldStorage()
arg = form.getvalue("arg")
 
print """
str value: %s
""" % cgi.escape(arg)
 
ser = arduino.Serial('\dev\ttyACM0',9600)
ser.write(arg)

Visit it with your web browser using http://localhost:8080/cgi-bin/arduino_com.py?arg=H to turn the light on and http://localhost:8080/cgi-bin/arduino_com.py?arg=L to turn it off.

You can also call it from a webserver using PHP:

#button {
	font-weight: bold;
	border: 2px solid #fff;
}

Arduino Uno Forward Serial to Telnet With ser2net on Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 29-11-2011-05-2008

1

This is how I used a WGT634u running OpenWrt Backfire to forward the serial port with the Arduino Uno to a telnet port.  This could be used as a cheap alternative to an ethernet shield or connecting the USB to your computer.  I was able to send commands to my Arduino via telnet over wireless network with the WGT634u in client mode.

Setup

Install ser2net:

opkg update
opkg install ser2net

Start ser2net:

ser2net -C "8082:raw:600:/dev/ttyACM0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS"

Now you should be able to communicate with your Arduino on port 8082.  Open up a telnet window and connect to your router.

Start on Boot

Next I will show you how to set it up so that ser2net will run on boot.

Edit the conf file:

vi /etc/ser2net.conf

Comment everything out and add this line at the bottom:

8082:raw:600:/dev/ttyACM0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS

Edit the startup file:

#!/bin/sh /etc/rc.common
START=10
STOP=15
start(){
ser2net
}
stop(){
killall ser2net
}

Enable the service:

/etc/init.d/ser2net enable

Arduino Uno Connected Via USB to Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 28-11-2011-05-2008

2

In this post I will show you how I connected an Arduino Uno to my Netgear WGT634u running OpenWrt Backfire via the USB port.  One thing to note is that it is much easier to trouble shoot if you are connected to the router with a serial cable.  I have another post (here) that outlines the process for building and connecting to the router with a serial cable.

Setup

First we need to make sure that we have the USB drivers that we need:

opkg update
opkg install kmod-usb-ohci

Next we will install the drivers package that will support the Arduino:

opkg update
opkg install kmod-usb-acm

Now when you plug the Arduino into the WGT634u, you should see that it is recognized (you will only see this if you are connected to the router with the serial cable):

usb 2-1: new full speed USB device using ohci_hcd and address 3
usb 2-1: configuration #1 chosen from 1 choice
cdc_acm 2-1:1.0: ttyACM0: USB ACM device

We should be able to find a new addition for the Arduino in the following location:

/dev/ttyACM0

Testing

Now that we have the Arduino installed, lets test it to see if we can send serial commands to it.  We can use the LED example included with the Arduino software to test it. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino.  After you upload the sketch, plug it into the WGT634u and lets test it out.  In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.

Turn off the led:

echo "L" > /dev/ttyACM0

Turn on the led:

echo "H" > /dev/ttyACM0

If this does not work for you, don’t fret…  It didn’t work for me either.  I appears that the older Arduino Uno boards reset the serial connection and so the light will flash but will not stay light.   I have a post (here) about how to fix this.

Summary

So now you have successfully connected your Arduino Uno to your Netgear WGT634u via the USB port and demonstrated that you can communicate with it via serial commands.

Webserver with PHP and Streaming Webcam on Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Netgear WGT634u | Posted on 17-11-2011-05-2008

0

In this post I will outline the process I used to setup a streaming usb webcam with a web server running php on a Netgear WGT634u running OpenWrt Backfire.

Webcam

First we will setup the webcam and make sure that we can view the stream on the lan.  Check out my other post (http://wp.yellowkazoo.com/?p=57) for details.  Note: When you setup the webcam make sure that you set it up on a different port than the one that you want the web server on.  I put the webcam on port 8081 and the web server on port 8080.  You can do this by editing the following file:

 /etc/config/mjpg-streamer
Config mjpg-streamer core
    option device "/dev/video0"
    option resolution "640x480"
    option fps "5"
    option port "8080"
    option enabled "true"

Web Server

Next we will install a web server,  I used lighttpd.

opkg update
opkg install lighttpd lighttpd-mod-cgi

Now lets edit the configuration file:

/etc/lighttpd/lighttpd.conf

Enable the mod_cgi module:

server.modules = (
    [..]
    "mod_cgi"
    [..]
}

Allow index.php as index:

index-file.names = ("index.html","default.html","index.htm","default.htm","index.php")

Set the server root directory:

server.document-root = "/www/pub_www/"

Set the server port:

server.port = 8080

Under CGI Module add:

cgi.assign = (".php => "/usr/bin/php")

Create a new folder for the document root:

mkdir /www/pub_www

Start lighttpd:

/etc/init.d/lighttpd start

Or have lighttpd start on startup:

/etc/init.d/lighttpd enable

PHP Server

Now lets setup the php server.  I installed PHP4 because it is a much smaller package.

opkg update
opkg install php4 php4-cgi

Edit the config file:

/etc/php.ini

Setup the root folder:

doc_root = /www/pub_www

To test the php setup we will create the file /www/pub_www/phpinfo.php with the following content:

<?php php phpinfo() ?>;

Now restart the server:

/etc/init.d/lighttpd restart

Browse to the phpinfo.php page (http://192.168.1.1:8080/phpinfo.php)

PHP Webcam Page

Now we will create a php page that includes the webcam stream.  Check out this post to see how I setup the webcam.

<?php
/* Usage: <img src="thisfile.php"> */
$server = "localhost"; // camera server
$port = 8081; // camera server port
$url = "/?action=stream"; // url on camera server
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if( !$fp ){
    echo "$errstr ($errno)<br />\n";
}else{
    $urlstring = "GET ".$url." HTTP/1.0\r\n\r\n";
    fwrite( $fp, $urlstring );
    while( $str = trim( fgets( $fp, 4096 ) ) )header( $str );
    fpassthru( $fp );
    fclose( $fp );
}
?>

Firewall Setup

Once the server is all setup we will configure the firewall so that it is accessible from the wan.

config redirect
    option src wan
    option src_dport 80
    option dest lan
    option dest_ip 192.168.1.1
    option dest_port 8000
    option proto tcp
config rule
    option src wan
    option dest_port 8000
    option target ACCEPT
    option proto tcp

Now restart the firewall:

/etc/init.d/firewall restart

Streaming Web Cam on Netgear WGT634u Running OpenWRT

Posted by Max Power | Posted in Netgear WGT634u | Posted on 14-11-2011-05-2008

0

This post will help you to setup a usb web cam on your WGT634u, running OpenWrt Backfire, and stream the video to a website.  The important part is to make sure that your web cam is supported by the Linux UVC drivers.

Web Cam

First you need to make sure that your webcam is compatible with the Linux UVC drivers.  The following links will help you find out if your web cam is supported by Linux UVC drivers:

I am using a Logitech Quickcam Pro 5000 that I got on eBay for about $15.

Router Setup

It is probably easiest to connect to the router with the serial cable and putty serial, although it will probably work with putty over ssh as well.  It may be more difficult to trouble shoot though since you don’t see all of the command information.

Setup USB Support

Since the newer web cams are the ones that support UVC, they probably also support USB 2.  To get usb support install the following packages:

opkg update
opkg install kmod-usb-core kmod-usb2 usbutils

Running the following command should show you a list of the usb ports:

lsusb

http://wiki.openwrt.org/doc/howto/usb.essentials

Setup Webcam Support

Now we want to install support for the web cam.  Install the following packages:

opkg update
opkg install kmod-video-uvc kmod-input-core kmod-video-core kmod-i2c-core

http://wiki.openwrt.org/doc/howto/usb.video

MJPG-Streamer

Now we will install mjpg-streamer to stream the video to a website.  Install the following packages:

opkg update
opkg install mjpg-streamer

Now you can plug in the camera.  Use the

lsusb

to see if the web cam is recognized. If you are using the serial interface connected to the router you should be able to see the camera recognized. Now lets start mjpg-streamer

/etc/init.d/mjpg-streamer start

and browse to the website to see if it is working

http://192.168.1.1:8080/?action=stream (to see video)

http://192.168.1.1:8080/?action=snapshot (to see a still snapshot)

If you want mjpg-streamer to start up automatically then run this command:

/etc/init.d/mjpg-streamer enable

Website Setup

Download all of the files located here or download the tarball here and unpack it into /www/webcam_www directory.

Edit /etc/init.d/mjpg-streamer – find the following line in function start():

[ $enabled -gt 0 -a -c $device ] && sleep 3 && $SSD -S -m -p $PIDF -q -x $PROG -- --input "input_uvc.so --device $device --fps $fps --resolution $resolution" --output "output_http.so --port $port" &

and add -w /www/webcam_www behind –output “output_http.so. Now it should look like this:

[ $enabled -gt 0 -a -c $device ] && sleep 3 && $SSD -S -m -p $PIDF -q -x $PROG -- --input "input_uvc.so --device $device --fps $fps --resolution $resolution" --output "output_http.so -w /www/webcam_www --port $port" &

Now restart mjpg-streamer

/etc/init.d/mjpg-streamer restart

Then test it by opening the URL http://192.168.1.1:8080/in your web browser.

Refrences

Check out the following links for mjpg-setup details

http://wiki.openwrt.org/doc/howto/webcam#embedding.video.stream.into.simple.webpages

http://wiki.openwrt.org/doc/howto/webcam

How to Build a Serial Cable for the Netgear WGT634u

Posted by Max Power | Posted in Netgear WGT634u | Posted on 01-11-2011-05-2008

0

If you end up messing up your router and you are unable to access your router via the web interface you will need to build a serial cable.  In this post I will show you how to build a serial cable.  For this ordered a CA-42 off of eBay for $5.

  1. First you should test your cable to make sure that you don’t have a dud.  Plug it into your computer and check to make sure that the drivers are installed and the cable is recognized.
    • I had to search for the drivers online and try a couple of different drivers before it was recognized.
    • To see if it working properly look at the device manager (Start >> Run >> type devmgmt.msc and look for Prolific USB-to-Serial Comm Port (COM #)) and make sure that there is not warning on that entry.  If you unplug the cable the entry should go away.  Note that this is also how you find what com port it is on.
  2. Now that you know the cable is good and have the drivers installed, cut the nokia plug off leaving a couple inches of cable to test with.  Strip the cables and using a multimeter check which color wire goes with which pin.
    • Mine was 8-Blue-Ground, 7-Green-Tx, 6-White-Rx but yours may be different.
    • Don’t worry about power since we will not need it.
  3. Now using the power connector for a floppy drive connect the ground, Tx, and Rx wires in the following order: yellow-Ground, black-Rx, black-Tx.
    • Note that the power connection is not needed.

The following pictures show the pin out for the CA-42 and the router serial plug:

wgt634u PCB

Refrences:

Enable Wifi on WGT634u Running OpenWrt Backfire

Posted by Max Power | Posted in Netgear WGT634u | Posted on 26-10-2011-05-2008

2

For some reason by default the wifi drivers are not included in the OpenWrt Backfire image for the WGT634u.  However it is very easy to get it up and working using the web interface.  The following steps outline the method that I used to enable wifi on my WGT634u running OpenWrt Backfire:

  1. Access the router using the web interface on 192.168.1.1 user: admin password is blank (unless you have changed it)
  2. Click the Administration link on the right hand side to get the administration menu options
  3. In the menu on the top left go to Overview >> LuCI Components
  4. Scroll down to the lower list of components that can be installed, find kmod-madwifiand click the link to the left to install it
    • If you don’t see kmod-wifi then use the link at the top to refresh the list of components that can be installed
  5. Once it is installed then go to System >> Reboot and reboot the router

If all went well then you should see the light come on for the wifi and you should see the wifi in the menu.  Now you can configure it to connect to your network.  By default the wifi is disabled, so you will have to enable it.

Connect to Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Netgear WGT634u | Posted on 25-10-2011-05-2008

0

There are a few ways that you can connect to your Netgear WGT634u running OpenWrt.  You can use the web interface, ssh, or WinSCP.  This post will describe each of these options and some of the features of each.

TCP/IP

Note:  PuTTY and WinSCP will require that you set a password for the administration account since they do not work with password: blank.

Web Interface

You can use the web interface at the IP address assigned to your router (192.168.1.1 by default username: root, password: blank).  The web interface gives you access to most things that you need for simple configuration of your router.

192.168.1.1

PuTTY

PuTTY will give you a command line interface to the router.  This can be used in both TCP/IP and serial.  When using TCP/IP just connect with the IP address.

http://en.wikipedia.org/wiki/PuTTY

WinSCP

WinSCP allows you to see the files on the router in a Windows Explorer type interface.

Note:  When setting up the connection use type SCP.

http://en.wikipedia.org/wiki/WinSCP

Serial

For this method you will need to build a USB-to-Serial cable (see my other post).

PuTTY

  1. Select Serial as the connection type and set the com number for the port the usb is plugged into and set the speed to 115200.
  2. Plug the adapter into the USB port, and plug it into the router.  Now power up the router.
  3. Now click open and the connection should initialize.  If you don’t see anything come up in the terminal press Ctrl + C and it should echo back something like “Press enter to activate this terminal”.
  4. Once you are connected you will see a linux like promp.  You can now use it like a normal linux terminal.