Silicon ChipHacking A Mini Wireless Webserver, Pt.1 - November 2012 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Replacing sacrificial anodes in hot-water systems is good for the environment
  4. Feature: Sacrifice Your Sacrificial Anode by Leo Simpson
  5. Project: High-Power Class-D Audio Amplifier, Pt.1 by John Clarke
  6. Project: High-Energy Ignition System for Cars, Pt.1 by John Clarke
  7. Project: LED Musicolour: Light Up Your Music, Pt.2 by Nicholas Vinen
  8. Project: Hacking A Mini Wireless Webserver, Pt.1 by Andrew Snow
  9. Project: A Seriously Bright 20W LED Floodlight by Branko Justic, Ross Tester
  10. Review: Agilent U1233A DMM with Bluetooth Adaptor by Nicholas Vinen
  11. PartShop
  12. Order Form
  13. Vintage Radio: The HMV A13B 4-Valve Twin-Chassis Mantel Radio by Rodney Champness
  14. Book Store
  15. Advertising Index
  16. Outer Back Cover

This is only a preview of the November 2012 issue of Silicon Chip.

You can view 22 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "High-Power Class-D Audio Amplifier, Pt.1":
  • CLASSiC-D PCB [01108121] (AUD $20.00)
  • CLASSiC-D Speaker Protector PCB [01108122] (AUD $5.00)
  • CLASSiC-D PCB pattern (PDF download) [01108121] (Free)
  • CLASSiC-D Speaker Protector PCB pattern (PDF download) [01108122] (Free)
Articles in this series:
  • High-Power Class-D Audio Amplifier, Pt.1 (November 2012)
  • CLASSIC-D Speaker Protector (November 2012)
  • High-Power Class-D Audio Amplifier, Pt.1 (November 2012)
  • CLASSIC-D Speaker Protector (November 2012)
  • CLASSIC-D Amplifier Power Supply (December 2012)
  • High-Power Class-D Audio Amplifier, Pt.2 (December 2012)
  • CLASSIC-D Amplifier Power Supply (December 2012)
  • High-Power Class-D Audio Amplifier, Pt.2 (December 2012)
Items relevant to "High-Energy Ignition System for Cars, Pt.1":
  • High Energy Electronic Ignition PCB [05110121] (AUD $10.00)
  • PIC16F88-E/P programmed for the High Energy Electronic Ignition System / Jacob's Ladder [0511012A.HEX] (Programmed Microcontroller, AUD $15.00)
  • ISL9V5036P3-F085 360V, 46A IGBT for the High-Energy Electronic Ignition System (Component, AUD $10.00)
  • High Energy Electronic Ignition System Firmware (HEX/ASM - zipped) [0511012A.HEX] (Software, Free)
  • High Energy Electronic Ignition PCB pattern (PDF download) [05110121] (Free)
  • High-Energy Electronic Ignition System front panel label artwork (PDF download) (Panel Artwork, Free)
Articles in this series:
  • High-Energy Ignition System for Cars, Pt.1 (November 2012)
  • High-Energy Ignition System for Cars, Pt.1 (November 2012)
  • High-Energy Ignition System For Cars, Pt.2 (December 2012)
  • High-Energy Ignition System For Cars, Pt.2 (December 2012)
Items relevant to "LED Musicolour: Light Up Your Music, Pt.2":
  • LED Musicolour PCB [16110121] (AUD $25.00)
  • dsPIC33FJ128GP802-I/SP programmed for the LED Musicolour [1611012A.HEX] (Programmed Microcontroller, AUD $25.00)
  • LED Musicolour front & rear panels [16110122/16110123] (PCB, AUD $20.00)
  • LED Musicolour Firmware (HEX/C - zipped) [1611012A.HEX] (Software, Free)
  • LED Musicolour PCB pattern (PDF download) [16110121] (Free)
  • LED Musicolour front & rear panel artwork (PDF download) [16110122/16110123] (Free)
Articles in this series:
  • LED Musicolour: Light Up Your Music, Pt.1 (October 2012)
  • LED Musicolour: Light Up Your Music, Pt.1 (October 2012)
  • LED Musicolour: Light Up Your Music, Pt.2 (November 2012)
  • LED Musicolour: Light Up Your Music, Pt.2 (November 2012)
Items relevant to "Hacking A Mini Wireless Webserver, Pt.1":
  • Scripts for the Mini Wireless Webserver (WR703N) (Software, Free)
Articles in this series:
  • Hacking A Mini Wireless Webserver, Pt.1 (November 2012)
  • Hacking A Mini Wireless Webserver, Pt.1 (November 2012)
  • Hacking A Mini Wireless Web Server, Pt.2 (December 2012)
  • Hacking A Mini Wireless Web Server, Pt.2 (December 2012)

Purchase a printed copy of this issue for $10.00.

Hacking A Mini Wireless Webserver For about $30, you can have a tiny, low-power web/email server with WiFi, Ethernet and USB. And with a bit of extra circuitry, it can even monitor voltages and control some relays. Pt.1: By ANDREW ANDREW SNOW W OULD YOU LIKE a wireless web server that consumes almost no power and can be easily interfaced to other circuitry? The Webserver in a Box (WIB) project published in SILICON CHIP from November 2009 to January 2010 has been very popular but it lacks a WiFi interface. It’s also rather limited in regards to other capabilities; for example, the WIB has no support for DHCP (Dynamic Host Control Protocol) which allows for automatic IP address allocation. If you hack a TP-LINK TL-WR703N router, you can overcome all these problems. It’s sold as a tiny “G Travel Router” but you can easily re-flash it to run a version of Linux. It’s then a relatively simple matter to set up a web server, an email server and so on. This is dramatically smaller and cheaper than a typical PC and it does all this while drawing about 1W of power! Consider what this means; not only can you run a low-traffic website off this device, you can monitor temperatures, switch devices on and off and so on, without even needing a wired network connection. All you need is a source of low-voltage DC power and wireless internet access, plus the re-flashed WR703N. The TL-WR703N is actually a fully functional miniature computer, shipped with software to make it operate as a 60  Silicon Chip 3G/WiFi router. This device is available from Hong Kong on eBay for only $25 delivered to Australia, making it a good choice for the home experimenter. Just go to the eBay website and type “WR703N” into the search box. Making some mods What’s the catch? Because TP-LINK made this device for their domestic market, its default user interface is in Chinese. We’ll show how you can remove its built-in firmware by installing Linux over the top, without having to learn a new language. All you need are some basic computer skills and a general understanding of computer networking concepts. Inside the WR703N’s tiny 57mm square plastic case is an Atheros chipset containing a MIPS-based CPU, 802.11b/g/n 150Mb wireless (WiFi), 4MB of flash storage and 32MB of RAM. As well as its USB2.0 and 100-base-T Ethernet ports, the only other port is a Type B micro-USB socket by which the device is powered (a suitable USB cable is supplied with the device). Note, by the way, that the WR702N model is not suitable. It’s similar to the WR703N but only has 2MB of flash memory and 16MB RAM. Nominally running off 5V, the WR703N’s average power siliconchip.com.au Fig.1: this screen grab shows the menu item (circled at bottom left) that must be selected in the WR703N’s web interface to upload the OpenWRT firmware. It’s then just a matter of clicking the button to the right of the text input box to bring up the file “chooser” dialog. consumption (with no USB device attached) is only 0.5W but it can draw more than double that when the CPU & Wifi are being used. Enthusiasts on the internet say it will work with an input voltage as low as 3.7V, meaning it can be run straight off a single Lithium-Ion cell. In fact, TP-LINK did this with the similar but more expensive TL-MR11U model, which comes with a built-in 2000mAh cell. To install Linux, first you’ll need to download new firmware from the Internet, then connect your computer to the WR703N to upload this new firmware. There is more than one version of Linux that can run on the WR703N but we’ve chosen to use OpenWRT, a free Linux distribution for embedded devices. It has extensions which let you still use your device as a wireless/3G travel router if you wish but extends its capabilities far beyond this. It can even be loaded with various scripting languages which allow you to program it to do just about anything. Once OpenWRT is installed, then depending how you configure it, it can operate as a web server, as a file server, play audio via a USB sound card and, for those with the technical knowledge, even do such things as run a tele­ phone PBX for Voice-over-IP (VoIP) phones. This month, we’ll show you how to install the new firmware, configure the networking parameters and do the web server set-up. A follow-up article will then describe how to interface some hardware to control relays and to measure temperatures and voltages. We’ll also describe how to set up an email server in the follow-up article. Other requirements In addition to the WR703N, you’ll need a PC with an Ethernet port and a standard Cat5 (or Cat6) Ethernet cable. You also need to initially connect the device to the internet via Ethernet, which means you need an internet modem/ router with a spare Ethernet port. This is to allow it to download some of the new software itself. OpenWRT installation steps STEP 1: make sure your computer can run “Telnet” from a command prompt. If you have Windows 7, it has to be siliconchip.com.au Fig.2: the next step is to select the OpenWRT firmware file that you downloaded in Step 3 and click the OK button. You then click the OK button again in the next dialog box to confirm the file selection and start the new firmware installation process. Fig.3: a progress bar monitors the firmware installation. Do not turn your computer or the WR703N off during this process, otherwise you could “brick” the device (ie, render it completely useless). enabled first via Control Panel (Programs & Features –> Turn Windows Features On Or Off and select the “Telnet Client” check box). Alternatively, use Google to get more detailed instructions. For Windows XP, Linux and other operating systems, Telnet or a similar terminal program is usually installed by default. STEP 2: make a note of your PC’s current IP address on your LAN (local area network), as well as its default gateway address. In Windows, you can do this by typing ipconfig /all and pressing Enter in a command prompt window. The IP address will consist of four 3-digit numbers separated by dots, normally in the form of “192.168.x.x” (eg, 192.168.0.3) or “10.0.x.x”. Note that the one you’re looking for is the IPv4 address. In addition, if the PC is connected to the internet, you will also see the IP addresses for the DHCP and DNS servers. STEP 3: download the new firmware for the WR703N November 2012  61 Fig.4: this is what you see when you first connect to the WR703N using telnet after the new firmware has been installed (see Step 9). router from this website: http://downloads.openwrt. org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-tlwr703n-v1-squashfs-factory.bin STEP 4: connect the WR703N to your computer’s USB port to power it up. Wait a minute for it to boot, then connect it to your computer via an Ethernet cable. STEP 5: disable your computer’s other network connections (eg, WiFi). The WR703N should now assign a 192.168.1.x IP address to your computer. STEP 6: open a web browser and enter http://192.168.1.1 into the address bar. When prompted, log in with the default username and password, both of which are “admin” (without the inverted commas). STEP 7: you should now see the WR703N’s menu system in Chinese language characters. If it’s all Greek (or Chinese) to you, don’t panic! Just click your mouse on the bottom menu item with a “+” sign next to it (ie, on the lefthand side of the window). This will open up a sub-menu, where you should click on the third item – see Fig.1. If you picked the correct one, then your browser’s address bar may end with the filename SoftwareUpgradeRpm.htm. If not, you should see this filename pop up if you hover your mouse over the third item in the sub-menu. STEP 8: click the button to the right of the white text input box, which will pop up a file “chooser” dialog. Select the firmware file you downloaded in Step 3, then click “OK”. Ditch The Plugpack Supply The TL-WR703N comes with a plugpack supply with two parallel mains pins plus an adaptor with angled pins. However, this unit doesn’t meet Australian standards since there’s no finger-guard insulation material on any of the mains pins. In addition, the mains pins are too close to the edges of the plastic housing and the recessed metal contacts inside the back of the pin adaptor are quite exposed. Our advice is to bin the supplied adaptor and purchase an approved replacement unit from a local supplier. You need to purchase a 5V 1A DC adaptor with a USB output such as the Altronics Cat. M-8889 or the Jaycar Cat.MP-3452. Of course, if you intend powering the WR703N from a USB port on your computer, then an adaptor is unnecessary. 62  Silicon Chip The next dialog box is just asking you for confirmation, so click the button (it means “OK”). This begins the firmware installation process. You’ll see a progress bar moving slowly to the right as the new firmware is installed. Warning: to avoid problems, do not interrupt this process by turning off the power during this step. Be careful also not to bump any of the cables. If you do, the WR703N could be rendered useless, as you will be unable to get back into it to re-install the software. STEP 9: assuming the last step worked correctly, your computer will again be assigned an IP address in the same range as before (192.168.1.x). If so, it’s now time to set up OpenWRT’s web interface and WiFi networking and this has to be done by first running the command telnet 192.168.1.1 in a command prompt window – see Fig.4. As a reward for making it this far, you’ll be greeted with OpenWRT’s welcome screen, which includes a recipe for a strong drink called “Attitude Adjustment” – the makers of OpenWRT show their sense of humour by naming each version after a different cocktail. It’s now time to connect the device to the Internet so it can download additional software (eg, the web server). STEP 10: you must now allocate a fixed IP address for the WR703N so that it is connected to your home or office network (and thence to the internet). The commands below assume that your computer normally has an address starting with “192.168.0.” Check the addresses you noted in Step 2 and if they differ, you will need to change these commands to suit (ie, the colour-highlighted parts). The IP address in the “ipaddr” command line below shouldn’t conflict with any existing computer on your LAN. Type these six commands carefully in turn (they must be entered exactly as shown): (1) uci set network.lan.proto=static (2) uci set network.lan.ipaddr=192.168.0.123 (3) uci set network.lan.netmask=255.255.255.0 (4) uci set network.lan.gateway=192.168.0.1 (5) uci set network.lan.dns=8.8.8.8 (6) uci commit network In addition, it’s likely that you will already have a DHCP server on the network (eg, in your main router). If so, you will need to instruct the WR703N to ignore DHCP requests as follows: (1) uci set dhcp.lan.ignore=1 (2) uci commit dhcp Alternatively, you can disable the DHCP server later on via the web interface, as shown in Fig.7. STEP 11: reset the WR703N by typing “reboot” and pressing Enter, then unplug its network cable from the PC and plug it into your Internet router instead. That done, reconnect your PC to the network, either by plugging its LAN cable back into the router or by reenabling its WiFi connection. Now wait a minute or so for the WR703N to reboot and then re-connect to it with Telnet, this time using its new address as allocated in Step 10 (ie, 192.168.0.123 if you used our example). STEP 12: the WR703N should now have Internet access and you can confirm this with a ping test. Enter the command ping -c 3 google.com and check that you get responses to the pings. Each time you want to install extra software, OpenWRT siliconchip.com.au needs to have its package database updated with the command “opkg update”, so run that now. STEP 13: use the following three commands to set up the web interface and start uhttpd: (1) opkg install luci (2) /etc/init.d/uhttpd enable (3) /etc/init.d/uhttpd start STEP 14: point your web browser at WR703N’s IP address (eg, http://192.168.0.123). This will bring up a web interface where you can see a status report. Now let’s configure its wireless networking. STEP 15: assuming you have a WiFi network (ie, your main router has WiFi), go to Network -> WiFi and click “Scan” which will list the available WiFi networks. Click “Join Network”and fill in the password details (if needed). Web server set-up To use the device as a webserver, you need to put files into the “www” directory (or folder). To copy the files across, first you must enable Secure Shell (SSH) support on the WR703N. This involves setting a password for the superuser (root) account. When SSH is enabled, the Telnet interface is automatically disabled. You will need to download and install an SSH client on your PC. There are several free ones available but we recommend PuTTY (www.chiark.greenend.org. uk/~sgtatham/putty/). Once you have installed PuTTY, type the following command in the Telnet window: passwd Now follow the prompts to enter the new root password. This has to be done twice (once to confirm). With the root password successfully set, close the Telnet window and then connect to the device’s IP (same as before) via SSH using PuTTY. Login as root and then enter the password you’ve just set. From this point on, the SSH interface behaves much like the Telnet one. In order to copy files across to the WR703N for its web server, you also need to install SCP (secure copy) client software. We used a freeware program called WinSCP. Refer to the accompanying panel for the instructions on installing this program and copying files across. Fig.5: once the web interface has been set up and uhttpd started (Step 13), you can log into the WR703N using a web browser. This screen-grab shows the log-in dialog. Fig.6: once logged in, there are all sorts of menus you can explore in OpenWRT. This wifi set-up screen allows you to create a new wifi network or join an existing one. Port forwarding If you want to make the website available from the Internet, you will need to set up “port forwarding” on your main internet router. This is done via its web interface. You need to forward port 80 (http) to the WR703N, using the IP address you assigned to it earlier. You will need to refer to your router’s user manual, as this procedure varies between different brands and models. Fig.10 shows the setup for a Linksys WAG5462. Note that it will also be necessary to also manually open port 80 in the firewall in some routers. Other software To have a look at what other software packages are available with OpenWRT, run the command “opkg list”. You can install them using the command “opkg install <packagename>”. But don’t go installing everything you see, because you’ll run out of space very quickly – you can check how much is left using the Linux “df” command. Remember, the WR703N has only 4MB of internal storsiliconchip.com.au Fig.7: if you wish, you can turn off the DHCP server in the WR703N in the web interface. Just click on the Network tab, then on DHCP and DNS and uncheck the “This is the only DHCP in the local network” box (circled). November 2012  63 Installing WinSCP & Copying Files To The WR703N Fig.8: logging into the WR703N router using WinSCP. Choose SCP as the file protocol, then enter the IP address (host name), user name and the set password before clicking the Login button. An option before logging in is to save the profile to make future logins easier. Fig.9: once you’ve logged in, navigate to the “www” directory and create a new subdirectory called “test”. You can then copy an index.htm test file to that folder and view it using a web browser. T HE EASIEST way to copy web files to the WR703N is to use WinSCP. This can be download it from http://winscp. net/eng/download.php and installed it on your PC in the usual manner. Choose the Explorer-style interface and simply click through the warning and/or error dialogs that pop up during the installation process. Once it’s installed, start the program and log in to the WR703N router using the SCP protocol – see Fig.8. This will age and that has to fit OpenWRT, your software packages AND your website. More storage Obviously, the WR703N’s internal storage won’t be then bring the dialog shown in Fig.9 and you can then easily create and rename folders and copy files into these folders by dragging them across from Windows Explorer. To test the system, create a directory called test and copy a file there called index.htm. You should then be able to browse to this file by entering http://192.168.0.123/test/ in your web browser (note: substitute the WR703N’s IP address if it’s something other than 192.168.0.123). enough for anything but a very small website. But don’t worry – you can easily expand on this by plugging a USB flash drive into the unit’s single USB port. A multi-gigabyte flash drive costs virtually nothing these days (a few dollars). Once the FAT-formatted flash drive is plugged in, you will need to “mount” it so that the files on the flash drive are accessible. To do this, you will first need to install and enable the necessary packages with these three commands: (1) opkg install kmod-usb-storage block-mount blockhotplug kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 (2) /etc/init.d/fstab enable (3) /etc/init.d/fstab start Now after you’ve plugged in your USB stick, use the administration web interface to go into System and then Mount Points. You should see an entry for “/dev/sda1” – Edit it so that the filesystem type is “vfat” and the mount point is “/www/usb”, then use WinSCP to create that folder in the filesystem. After clicking “Save & Apply”, go back and make sure the box is ticked under Enable, then click Save and reboot the WR703N. If you now point your web browser to http:// 192.168.0.123/usb you should see the files on the USB stick. Coming soon Fig.10: you need to forward port 80 (TCP) on your main internet router if you want to make to WR703N’s web server available via the internet. 64  Silicon Chip That’s all for this month. As mentioned earlier, a future article will describe how to connect the unit to external SC hardware such as temperature sensors and relays. siliconchip.com.au