FindMyIP Application
Overview
FindMyIP is a NetBurner embedded application that demonstrates network connectivity by retrieving and displaying the device's public IP address. The application connects to an external web service to determine the IP address that the device appears to have from the internet's perspective.
Description
This program creates a higher-priority task that performs an HTTP GET request to retrieve network information. Specifically, it connects to http://httpbin.org/ip and parses the JSON response to extract the device's public IP address.
Features
- Network Connectivity Testing: Verifies that the device can successfully connect to external web services
- Public IP Detection: Retrieves the public-facing IP address of the device
- JSON Response Parsing: Demonstrates parsing of JSON data returned from web services
- System Diagnostics: Includes diagnostic capabilities for debugging network issues
How It Works
- Initialization: The application initializes the system and enables diagnostics
- Network Wait: Waits up to 5 seconds for an active network connection (DHCP)
- HTTP Request: Performs a GET request to
httpbin.org/ip
- JSON Parsing: Extracts the "origin" field from the JSON response
- Display Results: Prints the discovered IP address to the console
- Continuous Loop: Enters an infinite loop with 1-second delays
Code Structure
Main Components
- Network Interface: Uses NetBurner's network stack for HTTP communication
- JSON Lexer: Parses JSON responses from the web service
- HTTP Functions: Handles web client operations
- System Initialization: Sets up the embedded system environment
Key Functions
Usage
When the application runs, you will see output similar to:
Application started
My IP address is 203.0.113.42
If the connection fails, you will see:
Application started
Failed to contact server
Dependencies
Configuration
The target URL is configured as a constant:
const char *url = "http://httpbin.org/ip";
This can be modified to use different IP detection services that return JSON responses.
Notes
- System diagnostics are enabled by default and should be disabled for production builds
- The application waits 5 seconds for network connectivity before attempting the request
- The main loop includes a 1-second delay to prevent excessive CPU usage
- Error handling is included for network connectivity issues