FlashForm Example Application
Overview
The FlashForm example is a NetBurner embedded web application that demonstrates three key capabilities:
- Dynamic HTML - Server-side function calls embedded in HTML
- HTML Form Processing - Handling POST requests from web forms
- User Flash Parameter Storage - Persistent data storage in flash memory
Application Structure
Core Files
main.cpp - Main application entry point and network initialization
formcode.cpp - Web server functionality and form processing logic
index.html - Web interface with dynamic content and form
ReadMe.txt - Original project documentation
Main Application (main.cpp)
The main application initializes the NetBurner network stack and starts the web server:
- Initializes the network stack
- Enables system diagnostics
- Starts HTTP server on default port 80
- Waits for DHCP network configuration
- Displays application information and NNDK revision
- Enters main loop with 1-second delays
Features
Dynamic HTML Content
The application uses special HTML comments to embed server-side function calls:
<!--FUNCTIONCALL DoMessageName -->
<!--FUNCTIONCALL DoMessageBody -->
These tags are replaced with dynamic content when the page is served:
DoMessageName() - Displays the stored user name
DoMessageBody() - Displays the stored message
Form Processing
The web interface includes a form that allows users to:
- Enter their name (up to 40 characters)
- Enter a message (up to 128 characters)
- Submit the form to store the data in flash memory
Form data is processed by the PostCallBack() function which handles:
eStartingPost - Initialize temporary storage
eVariable - Process each form field (name and comment)
eEndOfPost - Save data to flash and redirect to index page
Flash Storage
User data is stored persistently in flash memory using a structured approach:
struct MyOwnDataStore
{
uint32_t verify_key;
char name[40];
char msg[128];
};
The application uses NetBurner's user parameter storage functions:
Security Features
- Data Validation - Uses a verification key to ensure data integrity
- HTML Escaping - Uses
writesafestring() to prevent HTML injection
- Buffer Protection - Uses
strncpy() with size limits to prevent buffer overflows
Usage
- Setup: Deploy the application to a NetBurner device
- Access: Open a web browser and navigate to the device's IP address
- View: See any previously stored name and message
- Update: Use the form to enter a new name and message
- Save: Click "Save New Message" to store the data in flash
Technical Details
Network Configuration
- Uses DHCP for automatic IP configuration
- HTTP server runs on port 80
- Waits up to 5 seconds for network activation
Memory Management
- Static storage for form processing to maintain state across callbacks
- Flash storage persists data across power cycles
- Verification key ensures data integrity
Error Handling
- Displays "?" for invalid/missing name data
- Displays "No Message Stored" for invalid/missing message data
- Reports success/failure of flash programming operations
Development Notes
- Functions exposed to HTML must be declared as
extern "C" to prevent C++ name mangling
- The
PostCallBack function uses static variables to maintain state across multiple calls
- As of NetBurner 3.x release, the configuration server/storage system is recommended for new applications
Dependencies