NetBurner 3.5.6
PDF Version
MessagePasserTask JSON

MessagePasserTask Application

Overview

MessagePasserTask is a NetBurner embedded application that demonstrates JSON-based client-server communication. The application periodically sends status information to a web server via HTTP POST requests and processes the server's responses to control local hardware.

Purpose

This application serves as an example of how to:

  • Implement web client functionality on embedded NetBurner devices
  • Send and receive JSON data over HTTP
  • Integrate hardware I/O (switches and LEDs) with network communication
  • Handle server responses and error conditions

Key Features

Network Communication

  • Makes HTTP POST requests to a configurable server endpoint
  • Sends JSON data containing device status information
  • Processes JSON responses from the server
  • Includes comprehensive error handling for network operations

Hardware Integration

  • Reads DIP switch positions to monitor user input
  • Controls LEDs based on server responses
  • Automatically triggers network requests when switch positions change

Data Exchange

The application sends the following information to the server:

  • Device MAC address (as DEVICEID)
  • System uptime in seconds
  • Current timestamp message
  • Student name identifier
  • Current switch position values

The server responds with:

  • Success flag indicating message processing status
  • Current switch value for LED control
  • Response message for display

Configuration

Server URL

The target server URL is configurable via the Url config object:

static config_string Url(appdata, "http://class.netburner.com/post/", "MessageUrl");
String Configuration Variable.
Definition config_obj.h:1127

Student Identity

Update the student name before deployment:

const char *StudentName = "Attendee Name";

Application Flow

  1. Initialization
    • Initialize NetBurner system and network stack
    • Wait for active network connection (DHCP)
    • Display IP address information
    • Start web client task
  2. Main Loop
    • Monitor DIP switch positions
    • Trigger network request when switches change
    • Send periodic status updates every 10 seconds
  3. Network Request Process
    • Build JSON object with current status
    • Send HTTP POST to configured server
    • Parse JSON response
    • Update LEDs based on server response
    • Display status messages

Error Handling

The application includes robust error handling:

  • Network connection timeouts (10 second limit)
  • JSON parsing errors
  • Server response validation
  • Hardware I/O error recovery

Error states are logged to the console with descriptive messages using the HandleErrorState() function.

Hardware Requirements

  • NetBurner development board with network capability
  • DIP switches for input
  • LEDs for status output
  • Network connection (Ethernet)

Build Dependencies

Required NetBurner libraries:

Usage Notes

  • The application automatically starts network communication after initialization
  • LED patterns indicate server response status
  • Switch changes immediately trigger new server requests
  • Console output provides detailed operation logging
  • System diagnostics are enabled for debugging (should be disabled in production)

Troubleshooting

Common issues and solutions:

  • Network timeouts: Check server availability and network connection
  • JSON parsing errors: Verify server response format matches expected structure
  • LED not responding: Check server CURSWITCH value in response
  • No SUCCESS flag: Server may be rejecting the request format

Enable HTTP diagnostics for detailed network troubleshooting:

void SetHttpDiag(bool b)
Enable/disable Web Client HTTP diagnostics to the console port.

Development Notes

This application demonstrates best practices for NetBurner embedded web clients and can serve as a foundation for more complex IoT communication scenarios.