Example Path: examples/Web/FlashForm
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:
User Parameters vs. Configuration System
This example stores its data in the user-parameter flash area. NetBurner also provides a higher-level configuration system (demonstrated by the HTML Post Date/Time example). Both persist to flash, but they solve different problems:
| Aspect | User-Parameter Flash | Configuration System |
| Layout | Raw binary blob - your own C struct | Structured key/value tree (Config/...) |
| API | SaveUserParameters() / GetUserParameters() | Config objects (config_int, NV<>, ...) plus CONFIGTABLE / CONFIGVALUE HTML tags |
| Schema | None - you own the layout and versioning | Typed, named, and self-describing |
| Web editing | Not exposed (app-private bytes) | Browsable / editable on the configuration server (port 20034) |
| Serialization | Fixed bytes you read and write yourself | Automatic JSON serialization |
| Best for | A small, fixed set of private app data | Structured, discoverable, user-editable settings |
When to use which:**
- Reach for user-parameter flash when you need a small, fixed blob of private data, want full control of the byte layout, and do not need it exposed in the configuration UI - which is exactly what this example does.
- Reach for the configuration system when settings should be typed, named, discoverable, and editable through the config server on port 20034 (or via CONFIGTABLE / CONFIGVALUE tags in your own pages). As of the NetBurner 3.x release, it is the recommended choice for new applications.
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