NetBurner 3.5.6
PDF Version
Earthquake

Earthquake Monitor Application

Overview

This is a simple C++ embedded application that demonstrates real-time earthquake monitoring by retrieving and parsing JSON data from the USGS (United States Geological Survey) earthquake feed. The application fetches information about significant earthquakes (magnitude 4.5 and above) that have occurred in the last 24 hours and displays detailed information about each event.

Features

  • Real-time Data: Fetches live earthquake data from USGS API
  • Time Synchronization: Uses NTP (Network Time Protocol) to set accurate system time
  • JSON Parsing: Processes earthquake data in GeoJSON format
  • Detailed Reporting: Shows magnitude, location, and time elapsed since each earthquake
  • Network Stack Integration: Built for embedded systems with network capabilities

Data Source

The application retrieves data from:

https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson

This endpoint provides all earthquakes with magnitude 4.5 or greater from the past day in GeoJSON format.

Output Example

Application started
Time Set
In the last Day we have had 12 Earthquakes > 4.5
Magnitude : 5.2 at 34km WSW of Ferndale, CA 02:15:32 ago
Magnitude : 4.7 at 89km NNE of Adak, Alaska 05:42:18 ago
Magnitude : 4.9 at South of the Fiji Islands 08:30:45 ago
...

Technical Details

Dependencies

Key Components

  1. Network Initialization: Sets up the network stack and waits for DHCP
  2. Time Synchronization: Uses NTP to get accurate system time
  3. HTTP Client: Makes GET requests to the USGS API
  4. JSON Parser: Processes the GeoJSON response format
  5. Data Display: Formats and presents earthquake information

Application Flow

  1. Initialize network stack and enable diagnostics
  2. Wait for active network connection (up to 5 seconds)
  3. Synchronize system time using NTP
  4. Fetch earthquake data from USGS API
  5. Parse JSON response and extract earthquake count
  6. Iterate through each earthquake event and display:
    • Magnitude (formatted to 1 decimal place)
    • Location description
    • Time elapsed since the event (if time sync successful)
  7. Enter infinite loop with 1-second delays

JSON Data Structure

The application expects GeoJSON format with the following structure:

{
"metadata": {
"count": number_of_earthquakes
},
"features": [
{
"properties": {
"mag": earthquake_magnitude,
"place": "location_description",
"time": timestamp_in_milliseconds
}
}
]
}

Error Handling

  • Network Issues: Reports "Failed to contact server" if HTTP request fails
  • Parse Errors: Individual earthquake entries that fail to parse are reported with error messages
  • Time Sync: Application continues without time information if NTP sync fails

Usage

This application is designed for embedded systems and runs continuously, fetching earthquake data once at startup and then entering a maintenance loop. It's suitable for:

  • Environmental monitoring systems
  • Educational demonstrations of web API integration
  • Real-time earthquake awareness systems
  • JSON parsing examples in embedded contexts

Configuration

The earthquake magnitude threshold and time period can be modified by changing the API endpoint URL. Available USGS feed options include:

  • all_hour.geojson - All earthquakes in the past hour
  • 2.5_day.geojson - Magnitude 2.5+ in the past day
  • 4.5_week.geojson - Magnitude 4.5+ in the past week
  • significant_month.geojson - Significant earthquakes in the past month

Build Notes

Ensure all required header files and libraries are available in your build environment. The application uses proprietary networking and JSON parsing libraries that must be linked during compilation.