This is only a preview of the January 2010 issue of Silicon Chip. You can view 18 of the 104 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 "A Multi-Function GPS Car Computer, Pt.1":
Items relevant to "A Balanced Output Board for the Stereo DAC":
Items relevant to "Precision Temperature Logger & Controller, Pt.1":
Articles in this series:
Items relevant to "Voltage Interceptor For Cars With ECUs, Pt.2":
Items relevant to "Web Server In a Box, Pt.3":
Purchase a printed copy of this issue for $10.00. |
WI B
Pt.3: By MAURO GRASSI
Web S erver I n a B ox
In Pt.2 last month, we showed you how to connect the WIB to
a network and gave the step-by-step setting-up details. Most
constructors will settle for the website provided but for those
with special needs, this third article is for advanced users who
want to customise the WIB to their requirements.
O
NE OF THE advantages of the WIB
is that you can customise it by designing your own website if you wish.
For the purposes of this article though,
we’ll assume that you know the basics
of website design. Instead, we’ll just
give a few basic pointers on dynamic
content and running CGI (Common
Gateway Interface) commands.
Designing your own website
Basically, it’s up to you whether you
use the website we have provided with
the WIB or one of your own design. It’s
Note: the three tables referred to in the
text (Tables 1-3) are too large to include
in this article. Instead, you can download
them in PDF format from the SILICON CHIP
website.You’ll find them in the downloads
section for Jan 2010.
just a matter of copying the website
you wish to use to the memory card.
When it comes to designing your
own site, the best thing to do is to first
examine the website we have provided
and look at the source. We have used
dynamic variables, as well as forms
and Javascript.
There are plenty of HTML introductory tutorials on the web. Also you
can use a freeware HTML WYSIWYG
(What You See Is What You Get) editor such as Kompozer which you can
download from http://kompozer.net
We used Kompozer to design the
website provided with the WIB and
you can change all its important settings if necessary.
Dynamic content
The WIB implements a simple system for dynamic content.
For dynamic pages, a string of the
form ~XX, where XX represents a hexadecimal code between 00 and FF, is
replaced by the value of that variable.
Table 2 on the SILICON CHIP website
gives a list of the hexadecimal codes
and their corresponding variables.
Note that the files which are emailed
are also considered dynamic content.
For example, let’s say that we have
siliconchip.com.au
January 2010 85
An Example FTP Session . . .
The Temperature is currently 26.5
degrees.
As mentioned, any files sent by
email, such as var0max.txt (on a
maximum condition in variable #0),
can also contain dynamic content. In
order to show the ~ character you need
to escape it by using the sequence ~~.
For example ~~02 will translate to
~02 yet ~02 will translate to the Subnet
Mask (refer to Table 2).
The default var0max.txt file contains the following text:
The ~1E is currently at ~D0, which
is above the set maximum of ~1C!
This is an automatically generated
message, created on ~E2.
Fig.27: an example FTP session. Here a file called “report.pdf” has been
been uploaded to the WIB (via the Internet) using the “put” command.
List Of Accepted FTP Commands
CD: change directory.
PWD: show the current directory.
DELETE: delete a file.
DIR: show the files in the current directory
and the file sizes.
LS: show only the name of the files in the
current directory.
PUT: send a file to the ethernet web server.
GET: retrieve a file from the WIB.
Fig.27 shows an example FTP session. Here the put command is being
used to upload a file called report.pdf
to the memory card in the WIB via the
local network.
The first step is to connect to the
FTP server and that’s done by going to
a command prompt and typing:
ftp 192.160.0.34
The WIB’s local IP address has
been used here but you would have to
substitute the public IP address (or the
hostname if you have set up dynamic
DNS) if you want to access the WIB via
the Internet (as shown in Fig.27).
After that, it’s simply a matter of entering the username and password to
log on and then issuing the command:
put report.pdf
a dynamically typed file containing
the text:
The ~1E is currently ~D0 degrees.
From this, it follows that if the name
86 Silicon Chip
MGET: retrieve a collection of files from
the WIB.
MPUT: send a collection of files to the
ethernet web server.
USER: specify the username for login.
PASS: specify the password for login.
OPEN: open an FTP connection to a
remote server.
QUIT: exit the current FTP session.
The file should then upload to the
WIB. If you get an error that says
“Netout: connection reset by peers”,
it means that the buffer in the Windows
FTP client has overflowed and will have
to be increased in size. To do that, quit
the current FTP session (using the
quit command), then restart it with the
command:
ftp -w:8192 192.168.0.34
and try uploading the file again. This will
double the buffer size from the default. If
you get the same error message, double
it again by starting the FTP session using the command:
ftp -w:16384 192.168.0.34
Similarly, if you want to download a
file called report.pdf, use the command:
get report.pdf
of Variable 0 is set to “Temperature”
and the current value for the temperature (derived from a temperature sensor connected to the first ADC input)
is 26.5, then this would appear as:
As before, ~1E will be replaced by
the name of Variable 0, while ~D0
will be replaced by the current value
of that variable. ~1C is replaced by
the maximum set value, while ~E2
is the current time as determined by
the SNTP module. In other words, the
email would look like this example:
The Temperature is currently at 30.0,
which is above the set maximum of
28.0!
This is an automatically generated
message, created on Fri 28 August
2009 17:00:00.
Therefore, by modifying this file and
others like it, you can customise the
emails that are sent as notifications.
Running CGI commands
from an HTML form
It is possible to execute one of the
commands in Table 1 from an HTML
form. The commands are of the form:
<command>?<name>=<value>
Any system setting can then be
defined using an HTML form by using the set command (see Table 1 on
the SILICON CHIP website), the name
of the variable (Table 2) and the new
value, eg:
set?NTPTimezone=0
will modify the time zone for SNTP
to UTC time.
An in-depth discussion of HTML
forms is beyond the scope of this
article but if you are interested you
should look at the source code for the
supplied website. A number of HTML
forms are used to change the WIB’s
settings. By imitating these, you can
create complex websites.
siliconchip.com.au
Memory Card Special System Files
The are several special system files on
the memory card and these either have
a “txt” extension or a “dat” extension. For
security reasons, these two file extensions should always be set to private
in the HTTP Settings (file permissions)
– see text. This is the default but you can
change this and open up your system to
the public if that’s what you really want to
do (not recommended!).
You can also modify some of the special
system files to customise the behaviour of
the WIB. The relevant files are as follows:
FTP connection, a change in the public
IP address detected by the dynamic DNS
client, and any email sending activities.
log.txt: this file contains a human-readable log of system events since the last
reset. It is emailed to the user each time
there is a system reset. All important system events are logged, like an incoming
test.txt: this file contains the body of the
test email sent when the user presses the
‘Test Email’ button in the supplied website.
It is used to test that the SMTP settings
are correct.
The settings.txt file
The default settings can be overridden by a file named settings.txt. This
file is stored in the root folder of the
memory card.
In operation, the firmware loads and
parses this file at boot-up (or when
there is a Master Reset). Each line
should contain a statement of the form:
<setting name> = <value>
where <setting name> is one of the settings in Table 2 (provided it’s not read
only), and <value> is the value to set.
For example, to change the (default)
gateway to 192.168.0.33 you would
have a line in settings.txt that reads:
Gateway = 192.168.0.33
This would override the default
value but not the value that was last
set through the web interface. Those
values are instead stored in a file called
values.dat but in binary form.
Note that it is permissible to add any
number of spaces before the equals
sign for readability. For example, although the IP address settings name
is IPAddress, you can validly set the
IP Address by writing a line in your
settings.txt file that looks like this:
IP Address = 192.168.0.30
Restoring the defaults
To restore the default values, you
can simply delete the file values.dat
and reset the WIB by clicking the Master Reset button (or reboot the WIB).
siliconchip.com.au
settings.txt: this file contains a humanreadable list of single line entries that
override the system defaults. The user
may modify this file to define new default
values.
values.dat: this file is used to store system settings in binary form and should
not be modified.
var0max.txt: this is the file that is emailed
when variable #0 has exceeded its set
maximum.
var0min.txt: this is the file that is emailed
when variable #0 is below the set minimum.
var1max.txt, var1min.txt, var2max.txt,
var2min.txt, var3max.txt, var3min.txt:
similar to above but for variables #1, #2
and #3.
var0log.txt: this is the file that holds the
logged values of variable #0. This file is
emailed if periodic logging is enabled for
that variable.
var1log.txt, var2log.txt, var3log.txt:
similar to above but for variables #1, #2
and #3.
Correction To Fig.9(b) of WIB Pt.2
ETHERNET
PORT
MODEM
DYNAMIC
IP ADDRESS
INTERNET
FIXED LOCAL IP ADDRESS
(EG, 192.168.1.1)
192.168.0.34
WIB
(FIXED IP ADDRESS)
PC
(DYNAMIC IP ADDRESS)
MODEM PORT
(EG, 192.168.1.2)
ETHERNET
PORT (LAN)
ROUTER
ETHERNET
PORT (LAN)
FIXED LOCAL IP ADDRESS
(EG, 192.168.0.1)
There isB anSEPARATE
error in MODEM
the IP addressing
& ROUTER shown on Fig.9(b), page 84 of the
December 2009 issue. The addressing shown will not work because a router
will only forward packets between different networks, eg, from 192.168.0.x
to 192.168.1.x on a class C network (and vice versa).
This means that we must use IPs for two different networks on either
side of the router, eg, use 192.168.1.1 for the Ethernet port on the modem,
192.168.1.2 on the modem port on the router and leave the LAN side of the
router at 192.168.0.1 – see above. See also Notes & Errata, p101.
Alternatively, you can go to the Basic
Settings page of the supplied website
and click the Restore Defaults button.
Another option if you are creating
your own website is to run the defaults
command from an HTML file (see
Table 1).
You can also define the current
settings as the defaults by clicking
on the Create Defaults button and
then resetting the WIB by clicking the
Master Reset button (in the supplied
default website) or by rebooting the
SC
WIB (power off and on).
January 2010 87
|