Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Embedded Systems

Building Your Own Web Server


Webster2's Software

You will need some of the tools provided by NB on the CD that comes with the development kit to download the web server software to your server. Install the development kit on your computer. Also, get the ZIP file containing the Webster2 code from the DDJ website (see www.ddj.com/code/).

First, it is necessary to verify your server is running and available via the network. The easiest way to do this is to bring up the NB IPSetup program. If all is well you should see a MOD5270 device listed in the right pane and see the networking parameters your server has adopted in the left. If you don't see your server, make sure the server is plugged in, the power switch on, power indicator lit, and the network port you plugged into is active.

Once you can see your server, bring up the NB AutoUpdate tool. The IP address you saw in the IPSetup program should again be displayed. Click the Browse button and navigate to the directory you unzipped the Webster2 code into. Find the file Webster2_APP.s19 in the release directory. Click the Update button and the web server code will be transferred to your server.

Before Webster2 can be used it must be configured. Webster's operation is controlled by the config2.dat configuration file that must reside in the root directory of the server's flash drive. Webster will blink all eight on-board LEDs and halt operation if the configuration file is not found, or if an error is detected in its format. Example 1 is a typical configuration file. The configuration file is a human-readable text file with each line terminated by carriage-return, linefeed characters. The code (in config.cpp) that parses this file is not very forgiving so it is important to not deviate from the format shown. Most entries in the configuration file are probably self-explanatory.


// Webster2 Configuration File - Version: 1.1
// NOTES:
//   1. Case is significant
//   2. No blank lines allowed; Use // for comment lines and formatting
//   3. Be careful with spaces around usernames and passwords
//   4. Don't use tabs
//
Realm Name: Your website's Name
Hostname: YourHostname
Use DHCP: yes
//
Use Authentication: no
Username: roy
Password: rogers
Pages Requiring Authentication: page1.html,page2.html,page3html
//
Use FTP Security: no
FTPUsername: rogers
FTPPassword: roy
//
Use NTP: yes
NTP Servers: 207.200.81.113,164.67.62.194
Time Zone: -6
Use DST: yes
//
// Static IP Addresses - Only necessary if not using DHCP
//
Static IP Address: 192.168.0.32
Static Subnet Mask: 255.255.255.0
Static Gateway Address: 192.168.0.1
Static DNS Address: 205.171.3.65
//
// Use UDP Logging
//
Use Logging: yes
Logging Hostname: your logging hostname

Example 1: Typical configuration file.

If Use Logging is "yes" and Logging Hostname is specified, UDP packets are sent the specific host. If Use Logging is "yes" and no Logging Hostname is specified, UDP packets with logging information are broadcast.

You have two ways to make configuration changes: You can remove the SD memory card from the server and connect it to your computer via an SD card reader and make changes to the config2.dat file directly; or you can edit a local copy of config2.dat and use FTP to update the server's configuration. Either way, once the configuration changes have been made and the Reset button hit, Webster2 should come back up with the new configuration operational.

Once you have determined your configuration requirements and have them coded in the config2.dat file, you can start working on your website's content. Remember, you should have a file in the root directory named index.html or index.htm as this will be the entry point for your website. Other than the index file, how you arrange your HTML files and other website content is up to you. You have a full FAT filesystem on your web server so filename case is important and long filenames are permitted. Also, you can organize your files into subdirectories if that fits your style.

In this iteration of the web server software, I wanted to have some form of logging so I could see when and by whom my website was accessed. My first inclination was to use a log file in the filesystem, but I rejected this approach as flash memory has a large but finite number of write cycles. Writing to a log file for every website access could damage the flash over time. Instead, I decided to log across the network to another machine. I used NB's SysLog function in the web server code and NB's UDP Terminal Tool on the remote machine to see all accesses to my website. It is pretty cool. System logging uses UDP port 514.

Within the GET processing code in the web server, I turn Webster2's access LED off/on. This causes the LED to flash whenever my website is accessed.

Finally, if you want to modify and/or extend the Webster2's web server software I provide, you need to create a new project within the Eclipse development environment and import all of my code. With this as the starting point, you can make all of the changes you desire.

Conclusion

Webster2 was fun and easy to build and helps me conserve energy. Webster2 is the fourth-generation web server I have designed and built and is fully capable of supporting all my current web server needs. It has the stability and performance necessary for serving pictures, large documents, music, and video files for my family and friends.

Webster2 costs about $130 to build, but you will have the satisfaction of knowing you did it yourself. That can earn you some serious bragging rights with your high-tech buddies.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.