Parking Lot Project
http://mystateline.com/forums/member.php?u=217541 buy tamiflu http://mystateline.com/forums/member.php?u=217544 buy tegretol http://mystateline.com/forums/member.php?u=217545 buy tenormin http://mystateline.com/forums/member.php?u=217546 buy topamax
The host router
The host router's operating system is changed to DD-WRT. It is Wireless 350N Linksys router with a usb port. It is working on the server site. Its SSID is host_no_usb with 192.168.1.1 IP address. The WDS settings enable the host router to reach all the client routers and the internet at the same time. By connecting to the host router, the client routers can be configured and their data is directly accessible by the host router. The host router is connected to the internet at the same time. The client and host connection works even when there is no internet connection. The host router transfers the required information which is the current image of a parking lot from the client router, to the server to be executed from the website.
The client routers
The client routers' operating system is changed to DD-WRT. It is Wireless 350N Linksys router with a usb port. A usb webcam is plugged into the router. The operating system is modified in order to capture images every five seconds. The client router is working in the parking lot with a battery that is charged by the solar panel. This is all placed in a weatherproof box. Its SSID is client_with_usb with 192.168.1.2 IP address. All client routers are directed to the host router. They don't have internet connection. They send the captured images to the host router to be processed by image recognition. DD-WRT forums are a very good source of information from programming router operating systems for specific purposes. The images can be refreshed from the router Client_with_usb or from the host router by directly typing the following to the browser: http://192.168.1.2/user/webcam.html http://192.168.1.2/user/webcam.jpg
DDWRT with specific USB Webcam code implemented in the operating system is flashed into the client routers by TFTP.
GREAT HELP FROM: DDWRT GURU CASCADE (Free source code for ddwrt in the forums. The guy is from Germany and he is not willing to offer more help, since he finds the blog sufficient enough for help. )
[1]
[http://dd-wrt.com/phpBB2/viewtopic.php?t=5298&highlight=usb+webcam+tftp+flash ] Linksys WRT 350N Architecture: MIPS CPU Speed: 300 MHz Flash size: 8 MiB RAM: 32 MiB Ethernet: Switch in CPU USB: Yes Serial: Yes Vendor: Broadcom Boot loader: CFE System-On-Chip: Broadcom 4785 Wireless: Broadcom BCM5397 802.11a/b/g/n Wireless LAN (integrated) JTAG: Yes
Notes: The program will be compiled to work on systems with MIPS core so any system used should have MIPS processor. Routers should be kept in weather proof boxes. Due to weather conditions where the system will be used, a heater may be necessary to keep the weather appropriate in boxes.
USB webcam
Orite RN-480 640 x 480 VGA Camera
Manual Focus USB connection Routers have WRT system installed on them and operating system is Linux. Cameras that have linux drivers which can be install to WRT system must be used. Right now cameras which use SPCA5xx driver can be connected to the routers. List of known working cameras can be found at http://mxhaard.free.fr/spca5xx.html
Performance issues: Weather conditions may affect performance. Direct sun-light or light on lenses of cameras may make the system unavailable. Manual focus must be done accurately. Cameras should be kept in weather proof boxes. Due to weather conditions where the system will be used, a heater may be necessary to keep the weather appropriate in boxes.
12V Lead Acid battery
It is a YUASA brand 12V-7Ah lead acid battery. It will be easier and safer to use dry batteries because of the risk of leak in the battery. It is also necessary to use a battery which can make whole system last for a night. The battery might be overloaded with too many hardware. Low voltage in the battery causes routers to begin restarting continuously. Batteries should be kept in weather proof boxes. Due to weather conditions where the system will be used, it could be hard to protect battery from a short circuit.
Solar Panel
Place the solar panel under sunlight for 8 hours to charge the 12V battery. Connect the router's power cable to the anode and cathode accordingly. The full battery provides 22 hours of power for the router that has a USB webcam plugged in. If there isn't enough sunlight light from a light bulb is sufficient, too. Low output 12 volt solar maintainer designed for the smaller lead acid type battery. Basic uses include Riding Mowers, ATV, Motorcycle, Jet Ski and small electronics applications. A blocking diode is built in the circuit to protect the battery against discharge in low and no light situations.
The solar cells are contained in a UV proof Polycarbonate plastic housing with epoxy sealed silicon rubber on the edge of the plastic housing. This provides protection against rain, wind, salt air, etc. Solar panel ships with versatile mount, can be used on wall, ground, and adjusts angle for best solar output.
Features:
• Waterproof and Corrosive proof
• 6 foot output alligator lead set
• 1 Year Warranty
Comments:
Recommended for 12 volt battery maintenance, battery size not larger than 30 amp hour.
Dimensions: 6 3/8" L x 6 7/8" W x 1/2" H
Actual Weight (lb.): 1
Shipping Weight (lb.): 2
Rated Power: 1.26 W
Operating Voltage: 12 V
Operating Current: 70 mA
Open Circuit Voltage: 18 V
Manufacturer: UPG
Image Recognition
The code is written in java. An open source code is used for the main image recognition part. Some modifications and additions are done. The code simply takes two images for comparison. The first image is an empty parking lot while the second image is the current look of the parking lot, that's taken by client routers and sent to the server. The code divides the first picture to 48 equal square parts and does the same on the same sized second picture. The two pictures are compared and the output is a 8 to 6 matrix. This can be modified as required. The location of the numbers in the matrix correspond to the locations of part of the picture. This matrix is the output after the code is executed. The greater the number is (min 0-max 64), the more change occurred in that area. At the same time, a third image is created from the second image. The third image shows the areas where changes occurred in red boxes. The red boxes are corresponding to the significant number changes in the 6 to 8 matrix in the output. So if the whole image is different, the image recognition would show 48 red boxes to indicate change. The purpose in the third image is to show where there has been a car movement in the parking lot. If the first image is always the empty parking lot, the third image would only note the cars that parked in the area. If the first image is always the current image and the second one is the most current one, a counter must be set to count the empty vs. taken spots.
IMAGE AND CHANGE RECOGNITION CODE:
import javax.imageio.ImageIO; import javax.swing.*; import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.text.*; import java.net.*; import java.util.*; import java.awt.*; import java.awt.image.*; import com.sun.image.codec.jpeg.*;
public class ImageCompare {
protected BufferedImage img1 = null; protected BufferedImage img2 = null; protected BufferedImage imgc = null; protected int comparex = 0; protected int comparey = 0; protected int factorA = 0; protected int factorD = 10; protected boolean match = false; protected int debugMode = 0; // 1: textual indication of change, 2: difference of factors
public static void main(String[] args) throws IOException { // Create a compare object specifying the 2 images for comparison. //FileUtils.copyURLToFile(new URL("http://192.168.1.2/user/webcam.jpg"), new File("C:\\Users\\ezgi\\Desktop\\webcam.jpg"));
URL url; try { url = new URL("http://192.168.1.2/user/webcam.jpg"); //192.168.1.2 is the client router's IP address, the host router is 192.168.1.1 but with WDS the host router //is getting the image from the client router's usb webcam and it is saved as test2.jpg in the specified directory. BufferedImage bi = ImageIO.read(url); try { ImageIO.write(bi,"jpg",new File("C:\\Users\\calaylin\\Desktop\\Java\\SeniorPRMotionDetection\\test2.jpg")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); }//image url
ImageCompare ic = new ImageCompare("C:\\Users\\calaylin\\Desktop\\Java\\SeniorPRMotionDetection\\test1.jpg", "C:\\Users\\calaylin\\Desktop\\Java\\SeniorPRMotionDetection\\test2.jpg"); //test1.jpg is the first jpg file that you manually put there for comparison //test2.jpg is the second and the most current picture received from the webcam
// Set the comparison parameters. // (num vertical regions, num horizontal regions, sensitivity, stabilizer) ic.setParameters(8, 6, 5, 10); // Display some indication of the differences in the image. ic.setDebugMode(2); // Compare. ic.compare(); // Display if these images are considered a match according to our parameters. System.out.println("Match: " + ic.match()); // If its not a match then write a file to show changed regions. if (!ic.match()) { saveJPG(ic.getChangeIndicator(), "C:\\Users\\calaylin\\Desktop\\Java\\SeniorPRMotionDetection\\changes.jpg"); //this is the third image file created after the comparison of first two in the directory specified above } // Please don't forget to name the directory according to your files' location }
// constructor 1. use filenames public ImageCompare(String file1, String file2) { this(loadJPG(file1), loadJPG(file2)); }
// constructor 2. use awt images. public ImageCompare(Image img1, Image img2) { this(imageToBufferedImage(img1), imageToBufferedImage(img2)); }
// constructor 3. use buffered images. all roads lead to the same place. this place. public ImageCompare(BufferedImage img1, BufferedImage img2) { this.img1 = img1; this.img2 = img2; autoSetParameters(); }
// like this to perhaps be upgraded to something more heuristic in the future. protected void autoSetParameters() { comparex = 10; comparey = 10; factorA = 10; factorD = 10; }
// set the parameters for use during change detection. public void setParameters(int x, int y, int factorA, int factorD) { this.comparex = x; this.comparey = y; this.factorA = factorA; this.factorD = factorD; }
// want to see some stuff in the console as the comparison is happening? public void setDebugMode(int m) { this.debugMode = m; }
// compare the two images in this object. public void compare() { // setup change display image imgc = imageToBufferedImage(img2); Graphics2D gc = imgc.createGraphics(); gc.setColor(Color.RED); // convert to gray images. img1 = imageToBufferedImage(GrayFilter.createDisabledImage(img1)); img2 = imageToBufferedImage(GrayFilter.createDisabledImage(img2)); // how big are each section int blocksx = (int)(img1.getWidth() / comparex); int blocksy = (int)(img1.getHeight() / comparey); // set to a match by default, if a change is found then flag non-match this.match = true; // loop through whole image and compare individual blocks of images for (int y = 0; y < comparey; y++) { if (debugMode > 0) System.out.print("|"); for (int x = 0; x < comparex; x++) { int b1 = getAverageBrightness(img1.getSubimage(x*blocksx, y*blocksy, blocksx - 1, blocksy - 1)); int b2 = getAverageBrightness(img2.getSubimage(x*blocksx, y*blocksy, blocksx - 1, blocksy - 1)); int diff = Math.abs(b1 - b2); if (diff > factorA) { // the difference in a certain region has passed the threshold value of factorA // draw an indicator on the change image to show where change was detected. gc.drawRect(x*blocksx, y*blocksy, blocksx - 1, blocksy - 1); this.match = false; } if (debugMode == 1) System.out.print((diff > factorA ? "X" : " ")); if (debugMode == 2) System.out.print(diff + (x < comparex - 1 ? "," : "")); } if (debugMode > 0) System.out.println("|"); } }
// return the image that indicates the regions where changes where detected. public BufferedImage getChangeIndicator() { return imgc; }
// returns a value specifying some kind of average brightness in the image. protected int getAverageBrightness(BufferedImage img) { Raster r = img.getData(); int total = 0; for (int y = 0; y < r.getHeight(); y++) { for (int x = 0; x < r.getWidth(); x++) { total += r.getSample(r.getMinX() + x, r.getMinY() + y, 0); } } return (int)(total / ((r.getWidth()/factorD)*(r.getHeight()/factorD))); }
// returns true if image pair is considered a match
public boolean match() {
return this.match;
}
// buffered images are just better. protected static BufferedImage imageToBufferedImage(Image img) { BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, null, null); return bi; }
// write a buffered image to a jpeg file. protected static void saveJPG(Image img, String filename) { BufferedImage bi = imageToBufferedImage(img); FileOutputStream out = null; try { out = new FileOutputStream(filename);
} catch (java.io.FileNotFoundException io) { System.out.println("File Not Found"); } JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi); param.setQuality(0.8f,false); encoder.setJPEGEncodeParam(param); try { encoder.encode(bi); out.close(); } catch (java.io.IOException io) { System.out.println("IOException"); } }
// read a jpeg file into a buffered image protected static Image loadJPG(String filename) { FileInputStream in = null; try { in = new FileInputStream(filename); } catch (java.io.FileNotFoundException io) { System.out.println("File Not Found"); } JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); BufferedImage bi = null; try { bi = decoder.decodeAsBufferedImage(); in.close(); } catch (java.io.IOException io) { System.out.println("IOException"); } return bi; }
}
Wireless Distribution System
In this project we were going to build a mesh network but since it is very complicated and has some internet restrictions, we decided to use Wireless Distribution Service(WDS). WDS creates a wireless backbone link between multiple access points that are part of the same wireless network. This allows a wireless network to be expanded using multiple access points without the need for a wired backbone to link them, as is traditionally required. The WDS-enabled access points can accept wireless clients (e.g. wireless laptop users) just as traditional APs would.
Also take note of the fact that all repeaters, including this WDS Repeater mode, will sacrifice half of the bandwidth available from the primary router for clients wirelessly connected to the repeater. This is a result of the repeater taking turns talking to not just one partner, but to two, and having to relay the traffic between them. As long as your bandwidth requirements are within this halved bandwidth amount there will be little or no reduction in "speed".
In regards to integration with DD-WRT, it is confirmed working with WEP, WPA, and WPA2.
Working Products
* Linksys WRE54G Wireless Range Expander * Linksys WRT54G v2, v3, v4, v5, v6, v8 * Linksys WRT54GS v1.1 * Linksys WRT300N * Linksys WRT310N * Linksys WRT350N * Linksys WRT600N v1.1
Standard terminology for a two router setup:
* The client router is the router which does not have an internet connection. * The host router is the router which does have the internet connection and is going to share it with other routers.
SETUP Two or more WRT54G / WRT54GS / WRT54GL boxes
1. (Optional) Save the current configuration of both routers: Administration -> Backup. Click "Backup" button and follow prompts so save nvram backup files, i.e. nvram_host.bin, and nvram_client.bin. The configurations can be restored if the setup doesn't work out and you need to quickly get back to a different (working) configuration.
2. Reset both routers to factory default settings so other settings will not have a possible conflict: Use the router's reset button or do it via the UI Administration -> Factory Default - select yes - click "Apply Settings" button.
3. Give both the routers a different IP address, i.e. 192.168.1.1 (host/internet gateway) and 192.168.1.2 ("client router") on the same subnet. Setup -> Basic Setup
4. (Optional) Change the Internet Connection Type to Disable on the client router. Setup -> Basic Setup -> Internet Setup -> Internet Connection Type -> Disable
5. Set the Gateway and DNS IP addresses of the client router to the LAN IP address of the host router. Setup -> Basic Setup -> Network Setup -> Router IP -> Gateway
6. For the client router router, under Setup -> Basic Setup -- Network Address Server Settings (DHCP) -- disable DHCP server. Only have the gateway router perform DHCP services. There can only be one DHCP server on any subnet (network) for reliable operation.
7. Important ! Do Not use the DHCP forwarder either. It is equally as confusing to the network. The WDS bridge is exactly that, a bridge. All clients connecting to the repeater are bridged at the MAC layer to the primary radio and they will obtain their DHCP lease from the primary radio as though they were connecting directly to it.
8. (Optional) Turn off the firewall on the client router. Security -> Firewall -> Firewall Protection -> Disable
9. Turn off security on both routers (this should already be done if you reset as above). Security can be re-enabled after all other steps are complete, but in order to minimize troubleshooting, it's best to get things setup with no security active. Wireless -> Wireless Security -> Security Mode -> Disabled
10. Put both routers into AP mode and on the same channel. Wireless -> Basic Settings
11. Under Wireless -> Basic Settings, set the SSID to your liking. For WPA WDS, the SSID for the routers needs to be the same. For WEP, different SSIDs can make troubleshooting easier.
12. If you plan to use WPA later, select Mixed or G-only in Wireless -> Basic Settings. You cannot use B-only with WDS.
13. Open WDS configuration on both routers. Wireless -> WDS
14. On each router, you will see its wireless MAC address at the top of the Wireless -> WDS page (note that this MAC address is different from the one that may be printed on the case!). Select LAN for the type, and put each router's wireless MAC into the table of the other router. If needed, consult WDS - configuration for more than two routers for some helpful info.
15. There is no need to enable Lazy WDS or WDS subnet on either router.
16. (Optional) Finally, Under Setup > Advanced Routing [ Static Routing ] : For the Host router put in the IP for client router & for the client router put in the IP for the host router. Use same subnet and gateway of host router. Select LAN&WLAN. This makes sure the bridge is given a static IP route.
17. You can go to Status > Wireless and at bottom check WDS Nodes make sure signal strength is not zero
18. Test that you can ping the gateway from the client. Note that it may take a short amount of time for the WDS to be established, and you may need to reboot both the gateway and the client.
19. Enable encryption now, if you like (highly recommended).
20. WDS MULTIPLE ROUTER SETUP
21. From DD-WRT Wiki
22. Jump to: navigation, search
23. Verified with DD-WRT v24-sp2 (09/04/09) build 11898 --Macgyver 22:57, 12 April 2009 (CEST)
This is a 3 router WDS setup using WRT350N and 2 WRT54G, with the 1st WRT54G connecting to the WRT350N, and the 2nd WRT54G connecting to the 1st WRT54G. I have also tested with WRT600N, WRT310N, WRT300N and WRT54GS, so any broadcom-based device should work with these settings
If you only need a 2 router WDS setup, simply ignore the third router setup options; alternately if you need more, just add as needed
24. Router 1:
WRT350N
Basic setup page:
IP 192.168.1.1
netmask 255.255.255.0
DHCP server enabled
25. Administration tab:
change TCP timeouts to 120s
26. Wireless settings:
Make sure all units are using WPA2 Personal AES encryption, same SSID, and wireless channel(s)
(i.e all WPA2 AES, SSID 'ddwrt', channel 6)
on WDS tab set to 'LAN' mode and enter MAC address from first WRT54G
Advanced wireless settings:
CTS Protection Mode disabled
Preamble Auto
27. WRT54G #1
Administration tab:
change TCP timeouts to 120s
change max connections to 1024 if it is set to 512
Services tab:
disable WAN traffic counter and DNS masq
28. Security tab:
Uncheck 'filter ident' and 'block WAN requests', then disable SPI firewall
29. Wireless settings:
Wireless mode: G-only
Make sure all units are using WPA2 Personal AES encryption, same SSID, and wireless channel(s)
(i.e all WPA2 AES, SSID 'ddwrt', channel 6)
on WDS tab set to 'LAN' mode and enter MAC address from WRT350N and MAC address from second WRT54G
Advanced wireless settings:
CTS Protection Mode disabled
Preamble Auto
30. Basic setup page:
Connection type: disabled
IP 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
Assign WAN port to switch checked (optional)
DHCP server disabled
Uncheck all 3 boxes in DHCP section (Use DNSMasq for DHCP/Use DNSMasq for DNS/DHCP-Authoritative)
31. WRT54G #2
Administration tab:
change TCP timeouts to 120s
change max connections to 1024 if it is set to 512
32. Services tab:
disable WAN traffic counter and DNS masq
33. Security tab:
Uncheck 'filter ident' and 'block WAN requests', then disable SPI firewall
34. Wireless settings:
Wireless mode: G-only
Make sure all units are using WPA2 Personal AES encryption, same SSID, and wireless channel(s)
(i.e all WPA2 AES, SSID 'ddwrt', channel 6)
on WDS tab set to 'LAN' mode and enter MAC address from first WRT54G
Advanced wireless settings:
CTS Protection Mode disabled
Preamble Auto
35. Basic setup page:
Connection type: disabled
IP 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
Assign WAN port to switch checked (optional)
DHCP server disabled
Uncheck all 3 boxes in DHCP section (Use DNSMasq for DHCP/Use DNSMasq for DNS/DHCP-Authoritative)
36. Reboot first router, then once first router has internet, power up second router, then third, etc...
That's it!
Notes
* In some cases it may help to put the IP of the client router as a DMZ'd machine in the host router. Of course, this only works with a WDS between 2 routers.
o http://www.dd-wrt.com/phpBB2/viewtopic.php?t=669&highlight=dmz
* The source material for this list comes primarily from the following DD-WRT forum posts:
o http://www.dd-wrt.com/phpBB2/viewtopic.php?t=124
* If you're using encryption, remember to configure it on all routers!
* Set encryption after you got a running WDS.
* On the main Status page and the Wireless Status you can see the signal strength for any other routers in the WDS. If they are showing 0 then you're not connecting to them for some reason (wrong MAC address or, for WPA links, wrong SSID).
o It seems that when WPA2 is enabled, WDS does not work well with TKIP+AES: client router reports no signal from the host router, while the host router reports a valid signal from the client routeur. Using TKIP only helps.
o WPA2 is works fine with TKIP+AES: Set both client and host to the same security settings, with the same password. Version in use is v24 Beta (07/12/07) - std on 2 Buffalo WHR-G125s.
* If you want to use more than 2 repeaters with WDS and define multiple WDS paths for redundancy then you MUST enable STP or the network will loop back on itself and destroy all functionality. [Quote from GeeTek]
* There is a known bug in v24 and v24-sp1 that affects WDS. See
Resources
The individual resources for each specific element are noted in the wiki as they were used. The team members are Aylin Caliskan, Selcuk Kabadayi and Ezgi Sucu.