Specifications

SLAA137A
26 MSP430 Internet Connectivity
After initializing some hardware and the stack itself, the local TCP port is set to 80 (default for an
HTTP server). The server is now waiting for a client to be connected. During the first jump to
HTTPServer() after connecting, the flag HTTP_SEND_PAGE in register HTTPStatus is clear. It
is used to process some special code sections during this first execution of HTTPServer(). The
web server checks for any incoming TCP data and discards it. It is assumed that the received
data contains a GET request from an Internet browser. Since our server supports only one web
page, this request is not evaluated. The server starts just after client connection by sending the
web page stored in MCU memory. This page is stored in the C-constant WebSide[ ] in module
webside.c and is not encoded in any special way. After checking the status of the transmit
buffer, a pointer to the web side is set up and the total number of bytes to send is stored in
HTTPBytesToSend. During the first call of HTTPServer(), an HTTP response header is
transferred directly before the web page. It tells the client that its request was decoded
successfully and lets it know what kind of resource will be transmitted (HTML). It is stored in the
constant GetResponse[ ] in easyweb.h. After that, the web page is sent in pieces of
MAX_TCP_TX_DATA_SIZE size. Following the successful transmission of the whole page the
connection is closed by calling the API function TCPClose(). The connection is then reopened
by the main() function so that the next client can request and get the web page.
How can a dynamic web page be achieved? Before sending a segment of TCP data, the
function InsertDynamicValues() is executed. This function searches the transmit buffer for
special strings. If such a string is found, it is replaced by an A/D converter value. These strings
consists of four bytes: AD + channel number + %. The demonstration HTTP server replaces the
string AD7% by the value of the A/D converter’s channel seven and ADA% by the value of
channel ten. Before inserting these values, they are scaled to a range from 0 through 100
percent. With knowledge about HTML programming, this can be used to achieve effects on the
Web page.
The value for replacing the AD7% string is generated by the function GetAD7Val(). The ADC12
module of the MSP430 is configured to use an internal reference voltage of 2.5 V. Channel
seven is associated with MSP430F149 port pin P6.7. The voltage of the pin is sampled and the
voltage range of 0 to 2.5 V is projected into a percentage from 0 to 100. The other A/D converter
function used is GetTempVal(). Channel ten is connected internally to a temperature reference
diode. By setting the reference voltage to 1.5 V and doing a multiple conversion of eight sample
points, the temperature of the MCU is measured. Using a special formula, the temperature
range from 20 °C to 45 °C is converted to a percentage from 0 to 100. This formula should not
be used for exact measuring; it is for demonstration purposes only.
4.4.2 Dynamic Web Page Example
The server module provides a simple web page. It uses the process of replacing special strings
to be dynamic. Along with general text, two bar-graph displays showing the values of ADC12
channels 7 and 10 are displayed. For realizing such bar graph displays, HTML table commands
can be used easily. Two tables having a defined width and the background color red are
programmed. Within these tables, there are two more tables with the background color green.
The width of the two inner tables can be referred to the width of the outer tables using a
percentage. This is a good place to invoke the replacement process.