TCP/IP Networking: Web-Based Status Monitoring



Similar documents
TCP/IP Networking, Part 2: Web-Based Control

Touch Through Metal. mtouch Metal Over Capacitive Technology Part 1

AN1142. USB Mass Storage Class on an Embedded Host INTRODUCTION. USB Mass Storage Class. Overview

TB3016. Using the PIC MCU CTMU for Temperature Measurement IMPLEMENTATION BASIC PRINCIPLE MEASUREMENT CIRCUIT

AN956. Migrating Applications to USB from RS-232 UART with Minimal Impact on PC Software OVERVIEW INTRODUCTION. Microchip Technology Inc.

ZENA Wireless Network Analyzer User s Guide

AN Wire Communication with PIC Microcontroller INTRODUCTION. OVERVIEW OF THE 1-Wire BUS. 1-Wire Protocol. Prerequisites

PICkit 2 Microcontroller Programmer USER S GUIDE

AN687. Precision Temperature-Sensing With RTD Circuits RTD OVERVIEW INTRODUCTION EQUATION 1:

LIN Serial Analyzer User s Guide Rev2.0

Timers: Timer0 Tutorial (Part 1)

How To Use Microchip.Com

ZENA Wireless Network Analyzer User s Guide

PICkit 3 Programmer/Debugger User s Guide

dspic30f3012/3013 dspic30f3012/3013 Rev. B0 Silicon Errata dspic30f3012/3013 (Rev. B0) Silicon Errata Silicon Errata Summary

AN1265. KEELOQ with AES Microcontroller-Based Code Hopping Encoder INTRODUCTION DUAL ENCODER OPERATION BACKGROUND FUNCTIONAL INPUTS AND

Microsoft Expression Web

AN1303. Software Real-Time Clock and Calendar Using PIC16F1827 DATA INTERFACE INTRODUCTION IMPLEMENTATION INTERNAL REGISTER MAP

Uninstalling Incorrect USB Device Drivers

WORKSHOP-IN-A-BOX 2: LOW POWER SOLUTIONS DEMONSTRATION BOARD

PICkit TM 2 Microcontroller Programmer USER S GUIDE

Real-Time Data Monitor User s Guide

AN1156. Battery Fuel Measurement Using Delta-Sigma ADC Devices INTRODUCTION REVIEW OF BATTERY CHARGING AND DISCHARGING CHARACTERISTICS

AN1212. Using USB Keyboard with an Embedded Host INTRODUCTION. USB Keyboard Overview. USB Keyboard with an Embedded Host USB KEYBOARD OUTPUT REPORT

MCP1701A. 2 µa Low-Dropout Positive Voltage Regulator. Features. General Description. Applications. Package Types

AN1286. Water-Resistant Capacitive Sensing INTRODUCTION THEORY OF OPERATION. Sensing Steps. Sensing Steps Description DESIGN

Analog-to-Digital Converters

Introduction to the dspic DSC SMPS (Part 1)

An Introduction to MPLAB Integrated Development Environment

MPLAB IDE QUICK START GUIDE

TABLE 1: BUCK REGULATOR

MPLAB ICD 3 In-Circuit Debugger User s Guide For MPLAB X IDE

AN1275. KEELOQ with Advanced Encryption Standard (AES) Receiver/Decoder KEY FEATURES OVERVIEW. Microchip Technology Inc.

PIC10F200/202/204/206

AN1325. mtouch Metal Over Cap Technology THEORY OF OPERATION INTRODUCTION CROSS SECTION OF METAL OVER CAPACITIVE (UNPRESSED)

MPLAB IDE USER S GUIDE

Bootloader for dspic30f/33f and PIC24F/24H Devices

Designing A Li-Ion Battery Charger and Load Sharing System With Microchip s Stand-Alone Li-Ion Battery Charge Management Controller

MCP73811/2. Simple, Miniature Single-Cell, Fully Integrated Li-Ion / Li-Polymer Charge Management Controllers. Description. Features.

NJCU WEBSITE TRAINING MANUAL

Recommended Usage of Microchip 23X256/23X640 SPI Serial SRAM Devices RECOMMENDED CONNECTIONS FOR 23X256,23X640 SERIES DEVICES VCC 23X256/ HOLD.

MCP2515 CAN Bus Monitor Demo Board User s Guide

How To Improve Electromagnetic Compatibility

TC4423A/TC4424A/TC4425A

Making a Web Page with Microsoft Publisher 2003

AN1470. Manchester Decoder Using the CLC and NCO ABSTRACT INTRODUCTION MANCHESTER ENCODED DATA (AS PER G.E. THOMAS)

AN1256. Microchip s Power MOSFET Driver Simulation Models INTRODUCTION MODEL DESCRIPTION. Using The Power MOSFET Simulation Models

Getting Started with WebSite Tonight

Section 15. Input Capture

PICmicro DC Motor Control Tips n Tricks

Universal Programming Module 2

AN1095. Emulating Data EEPROM for PIC18 and PIC24 Microcontrollers and dspic Digital Signal Controllers INTRODUCTION THEORY OF OPERATION

AN990. Analog Sensor Conditioning Circuits An Overview INTRODUCTION SENSOR APPLICATIONS. Target Audience. Goals. Description.

AN1140. USB Embedded Host Stack INTRODUCTION USB OVERVIEW. Host vs. Embedded Host. USB Hosts and Peripheral Devices

How To Develop A Microchip Device With Dspic Language Tools

AN1543. Using MRF24W with PIC32 Internal Program Flash Memory For EZ_CONFIG_STORE ALTERNATIVE LOW-COST SOLUTIONS OVERVIEW SCOPE

Perceptive Intelligent Capture Solution Configration Manager

RN-131-PICTAIL & RN-171-PICTAIL Web-Server Demo Application

Getting Started with dspic30f Digital Signal Controllers User s Guide

AN1066. Microchip MiWi Wireless Networking Protocol Stack INTRODUCTION CONSIDERATIONS TERMINOLOGY FEATURES

Beginning Web Development with Node.js

TC4421/TC4422. Functional Block Diagram. TC4421 Inverting. TC4422 Non-Inverting V DD. 300 mv Output. Input 4.7V. GND Effective. Input.

MPLAB IDE Quick Start Guide

TC1047/TC1047A. Precision Temperature-to-Voltage Converter. General Description. Applications. Block Diagram. Features.

Using The HomeVision Web Server

In-Circuit Serial Programming (ICSP ) Guide

Understanding PIC WEB boards and how to use Microchip's TCP-IP Stack. Rev.A, April Copyright(c) 2008, OLIMEX Ltd, All rights reserved

PICkit 3 Debug Express PIC18F45K20 MPLAB C Lessons

Microchip Development Systems Ordering Guide

Hypercosm. Studio.

MPLAB C18 C COMPILER GETTING STARTED

PORTAL ADMINISTRATION

SPHOL326: Designing a SharePoint 2013 Site. Hands-On Lab. Lab Manual

dspic Language Tools Libraries

AN1332. Current Sensing Circuit Concepts and Fundamentals CURRENT SENSING RESISTOR INTRODUCTION. Description. Microchip Technology Inc.

MCRF khz Passive RFID Device with Sensor Input. Not recommended for new designs. Package Type. Features. Description. Applications PDIP/SOIC

T320 E-business technologies: foundations and practice

AN1106. Power Factor Correction in Power Conversion Applications Using the dspic DSC INTRODUCTION

MSOP, PDIP, SOIC, TSSOP

MCP73X23 Lithium Iron Phosphate (LiFePO 4 ) Battery Charger Evaluation Board User s Guide

Catalog Creator by On-site Custom Software

Active Filter Demo Board Kit User s Guide

TB056. Demonstrating the Set_Report Request With a PS/2 to USB Keyboard Translator Example INTRODUCTION. The Set_Report Request.

Microsoft Expression Web Quickstart Guide

PIC MCU Comparator Tips n Tricks

Joomla! Actions Suite

educ Office Remove & create new Outlook profile

Introduction to Programming with Xojo

RingCentral from AT&T Desktop App for Windows & Mac. User Guide

CREATE A WEB PAGE WITH LINKS TO DOCUMENTS USING MICROSOFT WORD 2007

STRUCTURE AND FLOWS. By Hagan Rivers, Two Rivers Consulting FREE CHAPTER

AN1492. Microchip Capacitive Proximity Design Guide INTRODUCTION CAPACITIVE SENSING BASICS SENSING

Features, Value and Benefits of Digital Control for Power Supplies

RIT Message Center Compose and Send Messages

AN1353. Op Amp Rectifiers, Peak Detectors and Clamps INTRODUCTION BASIC RECTIFIERS. Choosing the Components. Positive Half-Wave Rectifier.

Version 1.0 January Xerox Phaser 3635MFP Extensible Interface Platform

MCP3004/ V 4-Channel/8-Channel 10-Bit A/D Converters with SPI Serial Interface. Features. Description. Applications. Functional Block Diagram

FREE VERSION. Created by: Jason Nesbitt Mobile App Development Guide

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Transcription:

TCP/IP Networking: Web-Based Status Monitoring Microchip TCP/IP Stack HTTP2 Module 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 1 Welcome to the first in a series of Microchip s web seminars on building embedded web applications. We ll be discussing the HTTP2 web server module included with Microchip s free TCP/IP Stack, and more specifically, how you can use Dynamic Variables to present data from your system to a web browser. My name is Elliott Wood, and I m an Applications Engineer at Microchip s headquarters in Chandler, AZ. I am one of the main developers of Microchip s TCP/IP Stack, and I ll be explaining how to build a simple web-based status monitoring application for an embedded product. 1

Project Overview Web Enabled Vending Machine Online Features: Stock check www.microchip.com/tcpip Scope: Basic familiarity with TCP/IP Stack Vending machine and web pages are written Just need to add the HTTP2 callbacks 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 2 Suppose you are tasked with maintaining several vending machines. Your job is to make sure that the machines stayed stocked with product. Visiting each machine every day to check on its stock could be time consuming. Wouldn t it be easier if you could check each machine s status from the PC at your desk? This seminar will take a simple vending machine application and add web-based monitoring capabilities to the device. Over the next 25 minutes or so, we will build an online interface to our vending machine, allowing us to check its stock from the Internet. If you re just viewing out of curiosity or to see what s possible, all you need is a general understanding of embedded design. If you want to follow along with the examples, you will need to have downloaded and installed the full TCP/IP Stack distribution from the web page shown on the slide. We will be using the TCPIP WebVend App project. You should have also at least completed the Getting Started section in the TCPIP User s Guide, and know how to use the MPFS2 utility. For this seminar, we will assume that the actual vending machine application has already been written. We will also assume that a web developer has designed a simple web page for us to use. Our job will be to add the required hooks between the web pages and Microchip s HTTP2 web server module. In essence, we will provide the glue between the embedded application and the HTML web pages. The source code for this basic vending machine is all included in the TCPIP WebVend App project installed with the TCPIP Stack. 2

Agenda Simple Dynamic Variables Dynamic Variable Parameters Outputting HTML Wrap-up: Working Demo 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 3 In this seminar, we will describe three main uses of dynamic variables. First, we ll cover the basics and explain how to dynamically insert text strings into a web page. Next, we will expand upon this use and show how to pass parameters, allowing you to write less code. Finally, we will demonstrate the use of dynamic variables to output HTML, which provides the power to control design, layout, and graphical elements on a page. A working demo will be shown when we ve completed all three topics. 3

Basic Dynamic Variables 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 4 Let s get started. The first task is to learn the basics of dynamic variables. 4

Dynamic Variables: Overview Combine system data into web pages Present completed page to user s browser 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 5 Dynamic variables allow the web server module to take data from your system, such as the value from a sensor or data in memory, and combine it into a template web page. The completed web page is then transmitted through a network or the Internet, and the system data is displayed on the user s screen. In the simplified example on the slide, the microcontroller inserts the value from the thermometer into a web page and transmits that page to the user s browser. 5

Dynamic Variables: Overview Display system data on web pages Indicated in HTML by names in ~~ pairs Invoke a callback function To create a variable called foo: Insert ~foo~ in your web pages Implement HTTPPrint_foo() in CustomHTTPApp.c 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 6 Now that you know what a dynamic variable does, let s look at how to make one. Dynamic variables are created by enclosing any name inside a pair of tilde (~) characters and placing that variable in your web pages HTML code. When the HTTP2 web server module encounters this variable, it will execute a callback function. This callback is implemented in your application s C code, and controls what is transmitted to the browser and ultimately displayed on screen. For example: to create a variable called foo, two pieces are necessary. You must first insert the variable ~foo~, enclosed in tilde characters, somewhere in our web pages. Second, you must implement the callback function HTTPPrint_foo() in your project s CustomHTTPApp.c source code. The HTTPPrint_ portion indicates a dynamic variable callback, but the name foo will change depending on the name of your variable. 6

Basic Example 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 7 Here s a simple example. If we take a brief look at our web page, we will see that there is a space at the top reserved for the device s name and a description line. Right now they are hard-coded in, but we d like those elements to display our host name and description string. 7

Basic Example GOALS: Display host name on main web page Display location and description on screen SOLUTION: Replace host name text with ~hostname~ Replace description with ~machinedesc~ Implement appropriate callbacks 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 8 To accomplish this, we will add two dynamic variables. The first will output the host name, and the second will write the machine description or location string. We must then implement the appropriate callback functions to display these values. 8

Basic Example: index.htm Before: <div id="location"> Machine HOSTNAME :: Machine Location / Description </div> After: <div id="location"> Machine ~hostname~ :: ~machinedesc~ </div> 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 9 Let s start with the HTML file, located in the WebPages2 folder within the project. If we open up index.htm, we ll see some code towards the top where the host name is hard-coded. We will replace this name with a dynamic variable. Let s call it hostname, all one word, and place it within a pair of tilde (~) characters. We will do the same for the machine description string, as shown. When we save this HTML file, our variables will have been added to the web page. 9

Dynamic Variables: Callbacks Write directly to the socket Guaranteed 16 bytes free Must manage output for longer strings Use curhttp.callbackpos Add callbacks in CustomHTTPApp.c HTTPPrint_hostname() HTTPPrint_machineDesc() 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 10 The second part of a dynamic variable is the callback function. When a dynamic variable is encountered, a callback function is executed. This function will generally write some data to the socket. For technical reasons outside the scope of this presentation, the HTTP server operates in a buffer of a fixed size. When a callback is invoked, the server guarantees at least 16 bytes are free in the buffer. If a dynamic variable is only to write small amounts of data, it can write immediately and return. If more than 16 bytes need to be written, the callback must first check how much space is available, and use the variable curhttp.callbackpos(ition) to indicate whether or not it is finished. We will demonstrate this in the next few slides. To hook in the two dynamic variables we just created, we will need to add two callback functions to the file CustomHTTPApp.c. They must be named according to the variable names chosen when the dynamic variables were inserted into the HTML. 10

Example: CustomHTTPApp.c void HTTPPrint_hostname(void) { TCPPutString(sktHTTP, AppConfig.NetBIOSName); } 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 11 The first callback function to be added is HTTPPrint_hostname(). This function outputs the host name of the device. This host name is the NetBIOS name currently being used, and is stored in the AppConfig structure. Since it is defined to be 15 characters, we can write it directly without worrying about buffer space. Simply call an appropriate TCPPut() function and write the data to the HTTP socket. In this case, I ve chosen to use TCPPutString. Refer to the TCP API to learn what functions are available. 11

Example: CustomHTTPApp.c void HTTPPrint_machineDesc(void) { if(strlen((char*)machinedesc) > TCPIsPutReady(sktHTTP)) {// Not enough space curhttp.callbackpos = 0x01; return; } } TCPPutString(sktHTTP, machinedesc); curhttp.callbackpos = 0x00; 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 12 The machinedesc(ription) callback is slightly more complex. A string, machinedesc is defined as a global variable for our application. It is 32 bytes in length, so it is longer than our 16 byte limit and therefore we must make sure enough space is available before printing. The first if-statement performs this check. If the length of this description string is longer than the amount of space free in the buffer, we must wait and try again later. To accomplish this, we set the callback position to a non-zero value. If enough space is available, we will write the string to the buffer and return. Before this happens, we must set the callback position to zero. This clears any flag that may have previously been set if we had to wait for space. The value of zero indicates to the HTTP server that our callback function is finished with all its output. For this example we know that at some point there will be at least 32 free bytes, so we can just return and wait until enough space is available. To write arbitrarily large amounts of data, you should use determine how much pace is available, write that amount, and track your output state in the callback position variable. As a practical maximum, you should support partial writes like this for any output that may be longer than about 40 bytes. 12

Demonstration 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 13 Let s take a look at what we ve just changed. 13

2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 14 Our original webpage showed just some static text at the top of the page. If I reload the page with the changes we just made, we ll see that information become populated by the board. 14

2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 15 The default host name for this application is WEBVEND, and the description string defaults to the location of my office here at the Chandler facility. 15

Basic Example Review Allow arbitrary output Two components: ~varname~ in web page HTML code HTTPPrint_myVar() in CustomHTTPApp.c Must manage output if > 16 bytes Use curhttp.callbackpos 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 16 So far, we ve seen how dynamic variables provide the capability to output data. Each dynamic variable has two components. The first is the variable declaration in the web page. The second is an associated callback function in CustomHTTPApp.c. And remember that outputs longer than 16 bytes must be managed by your application. 16

Dynamic Variable Parameters 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 17 Let s move on to some more advanced uses. 17

Parameters: Overview Can pass parameters to callbacks Extremely useful for arrays Add parameters in () after varname ~myvector(3)~, ~myarray(7,25)~ Callback functions get WORD parameters HTTPPrint_myVector(WORD) HTTPPrint_myArray(WORD, WORD) 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 18 Parameters can also be passed through dynamic variables. These parameters are entered in the web page and are ultimately passed to the callback function. This method can be extremely useful for multiple outputs of similar data, such as arrays. To add a parameter to a dynamic variable, enclose that value in parenthesis after the name. Multiple parameters are supported in this fashion, but every call to a variable of that name must have the same number of parameters. Each parameter will be passed to the associated callback function as a 16-bit word value. 18

Parameters: Example GOALS: Display product names Update numeric stock display SOLUTION: Replace product names with ~name(#)~ Replace stock display with ~stock(#)~ Implement HTTPPrint_name(WORD) Implement HTTPPrint_stock(WORD) 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 19 Let s try this out with an example. Look again at our vending machine demonstration. There are bar graphs for seven different products. 19

GOALS: Product Name Display product names Update numeric stock display Current Stock Parameters: Example SOLUTION: Replace product names with ~name(#)~ Replace stock display with ~stock(#)~ Implement HTTPPrint_name(WORD) Implement HTTPPrint_stock(WORD) 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 20 We want to display the product name above each bar, and display the current stock remaining inside of the bar. 20

Parameters: Example GOALS: Display product names Update numeric stock display SOLUTION: Replace product names with ~name(#)~ Replace stock display with ~stock(#)~ Implement HTTPPrint_name(WORD) Implement HTTPPrint_stock(WORD) 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 21 Rather than writing seven different callback functions for each product name, plus another seven for the stock levels, we can write just two callback functions. One will handle all the product names, and the other will handle the stock. The product we re currently interested in will be passed to the callback function as a parameter. 21

Parameters: index.htm Before: <div class="productname">product:</div> <div class="bar-out" style="width: 17em"> <div class="bar-in-ok">stk</div> </div> After: <div class="productname">~name(0)~:</div> <div class="bar-out" style="width: 17em"> <div class="bar-in-ok">~stock(0)~</div> </div> 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 22 Looking again at index.htm, we see seven blocks of code. Each has a label for the product, and a place where the stock should be displayed. We will replace each of the Product: labels with a dynamic variable indicating the product name to be displayed. Add a number inside of parenthesis to the end of each variable. This parameter will indicate which product name to print at that location. Repeat this procedure for each of the stock displays. Our web pages are now ready to display product names and stock levels. 22

Parameters: Callbacks Work exactly as before Have an additional parameter list Add callbacks in CustomHTTPApp.c HTTPPrint_name(WORD) HTTPPrint_stock(WORD) 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 23 As in the prior example, we need to implement two callbacks in CustomHTTPApp.c. These callback functions work exactly as before, except that they now receive a single 16-bit word parameter. The callbacks take on the name of the dynamic variables we just added into the HTML code, name and stock. 23

Parameters: CustomHTTPApp.c void HTTPPrint_name(WORD item) { TCPPutString(sktHTTP, items[item].name); } void HTTPPrint_stock(WORD item) { BYTE digits[4]; uitoa(items[item].stock, digits); TCPPutString(sktHTTP, digits); } 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 24 The first callback handles printing of the names. The parameter item indicates which name to print. Since the name strings are 10 bytes or less, we just write them to the socket and return. The second callback is only slightly more complicated. Since we would like to display a number, we must convert that number using the unsigned integer to alpha function, then print that string. The item parameter is again passed to this function, and we will use that parameter to determine which product stock should be printed. These two callback functions will take care of all cases for printing names and stock levels. 24

Demonstration 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 25 Let s check on those changes we just made. 25

2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 26 Our original web page had statically listed products and stock levels. 26

2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 27 After making this change, we see that the names above each of the bars have been populated with data from our machine, and the stock number in each bar has also changed. We d still like to modify a few more elements, but things are looking good. Let s continue. 27

Parameter Example Review Callbacks can receive parameters Enables less code in CustomHTTPApp.c All parameters are WORD values Multiple parameters are supported Two components: ~varname(0)~ HTTPPrint_myVar(WORD) 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 28 In the past several slides, we saw how parameters can be passed to dynamic variables. The callback functions receive these parameters, which enables us to write less code in CustomHTTPApp.c. The same two components are required for these variables. The only difference is the parameters, indicated in parenthesis after the variable name, and passed to the callback function as 16-bit WORD values. 28

Outputting HTML 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 29 Our last topic covers outputting HTML. 29

Outputting HTML: Overview Dynamic variables can send HTML Can be used to control display elements Works for CSS, JavaScript, etc. No special changes required 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 30 So far, we ve used dynamic variables to display text on our web pages. Yet dynamic variables are much more powerful than that. They can be used to output text anywhere in the HTML code. This allows them to control display elements, images, CSS, JavaScript, and anything else that can be modified within HTML. No special changes are required for this functionality the variables are just inserted in a place where they will modify the HTML code rather than the text display. 30

Outputting HTML: Example 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 31 Our vending machine monitor has two logical places for outputting HTML rather than displayable text. The first, and most obvious, is the length of the bar. We want that to grow and shrink with the stock, and we can control that with HTML. The second is more subtle, but a nice feature nonetheless. The shorter bars in the example our web developer provided are red rather than green. We d like the colors to change automatically when stock gets low as well. 31

GOAL: Vary length of bar with stock Change bar color when stock is low Outputting HTML: Example SOLUTION: Output stock as bar length Have a dynamic variable control color vending.css defines bar-in-ok / low 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 32 The solution, again, uses dynamic variables. It will make more sense when we look at the code, so we ll describe it in detail on the next slide. 32

Outputting HTML: index.htm Before: <div class="productname">~name(0)~</div> <div class="bar-out" style="width: 17em"> <div class="bar-in-ok">~stock(0)~</div> </div> After: <div class="productname">~name(0)~</div> <div class="bar-out" style="width: ~stock(0)~em"> <div class="bar-in-~status(0)~">~stock(0)~</div> </div> 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 33 We see in the second line of each block there is a definition for the width of the bar element. It s measured in EMs, which is a standard print measurement. If we just output the stock in place of that fixed number, our application will be able to control the width property of each bar. We ve already got a dynamic variable written for the stock of each product, so we ll just use that again. The bar color requires closer inspection. By comparing two different bars, it looks like the class of the inner bar is being modified to be either bar-in-ok or bar-inlow, depending on the stock level. That class is defined in the site s CSS style sheet, but its exact implementation doesn t really affect our application. For now, we can just replace this ok or low suffix with a dynamic variable called status. We will again pass the product number as a parameter, and will determine whether to write ok or low based on the current stock of that product. That s all for the modifications in the HTML. Now we must tie in the callbacks. 33

HTML: CustomHTTPApp.c void HTTPPrint_status(WORD item) { if(items[item].stock < 10) TCPPutROMString(sktHTTP, (ROM BYTE*)"low"); else TCPPutROMString(sktHTTP, (ROM BYTE*)"ok"); } 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 34 The callback for stock was written in a prior example, so we are just using it as-is. No problem there. We do need to implement the status callback however. The status we removed was either ok or low. We can output the correct class suffix again by checking the stock level for the specified item. If the stock is less than 10, we will output low. Otherwise, ok will be written. That s all we need to do. The CSS takes care of all the necessary color and style changes, and our web developer already wrote that portion for us. 34

Outputting HTML Review Dynamic variables can output HTML Allows control of layout, display, etc Works for CSS, JavaScript, etc No special changes required 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 35 We ve just shown how to use dynamic variables to control HTML output. This provides the capability to control graphical elements, and even place values within CSS or JavaScript as necessary. No special changes were required to do any of this; we simply placed the dynamic variable within the HTML or CSS we wanted to modify. 35

Working Demonstration 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 36 Now that we ve added all the dynamic variables, let s take a look at this page. If we program our board and load the web page, we will see default products and stocks shown on our screen. If I insert several quarters (by pressing BUTTON3, the right most one), then vend a few drinks by pressing BUTTON2, the machine will track this change in its memory. I ll buy a few Colas and a couple of Diets right now. When I click refresh in the browser, we see the stock numbers change and the bars shrink. If I buy a few more Colas right now, there will be fewer than ten remaining. When I refresh the page again, the bar will turn red, indicating that it s about time to refill. It looks like our vending machine project is a success! 36

Dynamic Variables: Summary Allow output of arbitrary data Can output text, data, or HTML User-defined output functions Can pass parameters Two components: ~varname~ in web page HTML code HTTPPrint_myVar() in CustomHTTPApp.c 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 37 Today s seminar explained how add web-based monitoring to a simple embedded application. We used dynamic variables to output system data to a web browser. These variables can write either text or HTML code, and will invoke custom callback functions. We can also pass parameters to these callback functions, which simplifies output for arrays. 37

Conclusion Use dynamic variables to provide web-based output from your application Web status monitoring application First of several TCP/IP seminars Will cover Form Processing, Authentication, E-mail, and more Please provide feedback! 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 38 The tools presented should provide everything needed to build a simple web status monitoring application. As mentioned at the beginning, this is the first of several TCP/IP seminars. If you d like to learn how to update the system through the web, or have it automatically e- mail you when stock runs low, check for future seminars. We will soon cover other topics involving the HTTP2 module such as processing web forms, and basic password authentication. We will also explain how to automatically send yourself an e-mail when stock runs low, and much more. Before you go, please remember to provide feedback using the link on this seminar s web page. Comments both good and bad will be appreciated so we can better tailor future seminars to your needs. 38

For More Information www.microchip.com/tcpip TCPIP Stack User s Guide Installed with the TCP/IP Stack Accessible via Start menu TCPIP Demo App WebPages2 CustomHTTPApp.c 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 39 For more information on the topics presented here, please refer to the TCPIP Stack User s Guide. This file is installed with the TCP/IP Stack, and can be accessed via the Start menu. More examples and labs are available within the TCPIP Demo App that is installed with the stack. The demo application has its own WebPages2 folder and CustomHTTPApp.c source file that explain how everything works in more detail. Thanks for watching! 39

Trademarks The Microchip name and logo, the Microchip logo, Accuron, dspic, KeeLoq, KeeLoq logo, microid, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, rfpic and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. AmpLab, FilterLab, Linear Active Thermistor, Migratable Memory, MXDEV, MXLAB, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. Analog-for-the-Digital Age, Application Maestro, CodeGuard, dspicdem, dspicdem.net, dspicworks, dsspeak, ECAN, ECONOMONITOR, FanSense, FlexROM, fuzzylab, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rflab, Select Mode, Smart Serial, SmartTel, Total Endurance, UNI/O, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. 2007 Microchip Technology Incorporated. All Rights Reserved. Web-Based Status Monitoring Slide 40 40