16 KiB
NWS API Documentation - Integrated Main Endpoint
This document describes all available endpoints in the integrated main.php file, which consolidates functionality from multiple separate PHP scripts.
Base URL
/main.php
General Information
- Content-Type:
application/json(unless otherwise specified) - CORS: Enabled with
Access-Control-Allow-Origin: * - Methods: GET, POST, OPTIONS
- Database: PostgreSQL (connection:
host=localhost dbname=nws user=nws password=nws)
Utility Functions (No Direct Access)
The following utility functions are included at the top of the file for compatibility:
connect_db()- Database connectionsend_error($code, $message)- JSON error responsesend_json($data)- JSON success responsesend_geojson($features)- GeoJSON response
GET Endpoints
1. Single Camera Information
Endpoint: ?camid={id}
Description: Get detailed information for a single camera.
Parameters:
camid(string, required): Camera ID
Response: Camera object with hydro/airport boolean fields
Example: /main.php?camid=123
2. Active Cameras
Endpoint: ?cams or no parameters
Description: Get all active cameras with recent successful connections.
Response: Array of camera objects
Example: /main.php?cams
3. Camera List
Endpoint: ?camlist
Description: Get comprehensive list of all active cameras.
Response:
{
"status": "success",
"data": [...],
"count": 150
}
Example: /main.php?camlist
4. Camera API with Filters
Endpoint: ?cams with bounding box parameters
Parameters:
lat1,lon1,lat2,lon2(float, required): Bounding box coordinateselevbottom,elevtop(float, required): Elevation range
Response: Filtered camera array
Example: /main.php?cams&lat1=38.0&lon1=-82.0&lat2=39.0&lon2=-81.0&elevbottom=100&elevtop=1000
5. Camera Static Search
Endpoint: ?camstatic
Parameters:
lat1,lon1,radius(float, required): Center point and radius for radius searchcamstatic=bboxwithlat1,lon1,lat2,lon2,elevbottom,elevtop: Bounding box search
Response: Cameras within specified area
Example: /main.php?camstatic=radius&lat1=38.5&lon1=-81.5&radius=50
6. Camera Database Count
Endpoint: ?camdb
Response: Total count of camera records
Example: /main.php?camdb
7. Camera Circles
Endpoint: ?camcircle
Description: Get camera locations as buffer circles (8000m radius).
Response: GeoJSON FeatureCollection with circular buffers
Example: /main.php?camcircle
8. Weather Station Data
Endpoint: ?outside or ?outsideold
Description: Get current weather station observations.
Response: Array of weather station data
Example: /main.php?outside
9. Fire Data
Endpoint: ?fire
Description: Get active wildfire information.
Response: GeoJSON FeatureCollection of fire data
Example: /main.php?fire
10. Individual Camera Images
Endpoint: ?camid={id}&dtg={datetime}&camimages={count}
Parameters:
camid(string, required): Camera IDdtg(string, optional): End time for historical images (YYYY-MM-DD HH:MM UTC)camimages(int, optional): Number of images (default: 20)
Response: Array of camera image records
Example: /main.php?camid=123&camimages=10
11. OHGO Data
Endpoint: ?ohgo
Description: Get Ohio Department of Transportation road information.
Response: Array of OHGO road status data
Example: /main.php?ohgo
12. Power Outage Data
Endpoint: ?power
Description: Get current power outage information for RLX CWA.
Response: Array of power outage points
Example: /main.php?power
13. Power API (Advanced)
Endpoint: Various parameters for power data
Parameters:
states: Get state boundaries GeoJSONcounty: Get county outage summarymaxwithstart,end: Get maximum outage by county for date rangecountyarchivewithstart,end: County archive dataarchivepointwithstart,end: Point outage archivesvr=current: Current severe weather warningssvrpolys: Warning polygon metadatapowerids={ids}: Specific outage detailspoweridsgeojson={ids}: Specific outage GeoJSONpolygongeojson={geojson}: Outages within polygon
Response: Varies by endpoint (JSON or GeoJSON)
Example: /main.php?states
14. Local Storm Reports (LSR)
Endpoint: Various LSR-related parameters
Parameters:
ohgo: OHGO data as GeoJSONohgotable: OHGO tabular datavtec={code}: Warning polygon by VTEC codereports={code}: Reports within warning polygonoutages={code}: Power outages within warning polygonverify: Verification table datastats: Report statistics by countymetarswithstart,end: METAR datanews,news2,news3: News data with various filteringnewsarchivewith search parameters: Archived newswv511: West Virginia 511 dataky511: Kentucky 511 datagetCombinedTable: Combined road incident tableupdaterwithtable,id,lsr/hide: Update incident flags
Response: Varies by endpoint
Example: /main.php?ohgo
15. NWS Staff Data
Endpoint: ?officestats, ?regionstats, ?drilldown
Parameters:
datetime: Date for statistics (m-d-Y format)
Response: NWS office staffing statistics
Example: /main.php?officestats
16. Verification Data
Endpoint: Various verification parameters
Parameters:
lsrslist: Simple verification listreset: Clear verification tablelsrswithzone,lsr,dir: Update verification countsinc/hidewithid,true/false: Update report visibility
Response: Verification operation results
Example: /main.php?lsrslist
17. Warning Tracking
Endpoint: ?warntrack
Description: Get active warning tracking information for KRLX.
Response: GeoJSON FeatureCollection of warning tracks
Example: /main.php?warntrack
POST Endpoints
1. MP4/GIF Creation
Endpoint: POST with form data
Parameters:
data(array, required): Array of image file pathsimages(int, required): Number of imagesdelay(int, required): Frame delay in millisecondslastdelay(int, required): Last frame delaymaxh,maxv(int, optional): Maximum dimensions
Response: Base64-encoded GIF data
Content-Type: Not JSON (binary/gif)
2. Update Camera Field
Endpoint: POST with form data
Parameters:
camid(string, required): Camera IDfield(string, required): Field name ('hydro' or 'airport')value(string, required): New value ('true' or 'false')
Response:
{
"success": true
}
3. Admin Functions
Endpoint: POST with form data
Parameters:
action(string, required): Action typecheckurl: Check if URL existsnewcam: Add new camera
For checkurl:
url(string, required): URL to check
For newcam:
url,lat,lon,description,method,permission,owner,email(all required)
Response: Operation result
4. Storm Data API
Endpoint: POST with JSON data
Content-Type: application/json
Request Body:
{
"request_type": "ohgo|ohgonopoly|power|powernopoly|wupoly|campoly",
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-01-02 00:00:00",
"area_geojson": {...},
"buffer": 2,
"outage_threshold": 10,
"polygons": ["POLYGON(...)"],
"camimages": 20
}
Request Types:
ohgo: OHGO data within GeoJSON polygonohgonopoly: OHGO data without polygon filterpower: Power outages within GeoJSON polygonpowernopoly: Power outages without polygon filterwupoly: Weather Underground data within polygonscampoly: Camera images within GeoJSON polygon
Response: GeoJSON FeatureCollection
Error Handling
All endpoints return consistent error responses:
{
"error": "Error message"
}
Common HTTP status codes:
200: Success400: Bad Request (missing/invalid parameters)404: Not Found500: Internal Server Error (database/query issues)
Migration Guide for Existing Callers
Simple URL Changes
Most existing callers only need to update the filename in their requests:
Before:
https://your-server/single.php?camid=123
After:
https://your-server/main.php?camid=123
Specific Migration Instructions
1. single.php → main.php
No parameter changes needed
- Existing calls:
single.php?camid={id} - New calls:
main.php?camid={id}
2. cam.php → main.php
No parameter changes needed
- Existing calls:
cam.phporcam.php?cams - New calls:
main.phpormain.php?cams
3. camlist.php → main.php
Parameter change required
- Existing calls:
camlist.php - New calls:
main.php?camlist
4. camapi.php → main.php
No parameter changes needed
- Existing calls:
camapi.php?cams=1&lat1=... - New calls:
main.php?cams=1&lat1=...
5. camcircle.php → main.php
Parameter change required
- Existing calls:
camcircle.php - New calls:
main.php?camcircle
6. camobs.php → main.php
No parameter changes needed
- Existing calls:
camobs.php?camstatic=radius&lat1=... - New calls:
main.php?camstatic=radius&lat1=...
7. db.php → main.php
No parameter changes needed
- Existing calls:
db.php?outside - New calls:
main.php?outside - Existing calls:
db.php?outsideold - New calls:
main.php?outsideold
8. fire.php → main.php
Parameter change required
- Existing calls:
fire.php - New calls:
main.php?fire
9. individualcam.php → main.php
No parameter changes needed
- Existing calls:
individualcam.php?camid=123&dtg=... - New calls:
main.php?camid=123&dtg=...
10. lsr.php → main.php
No parameter changes needed
- Existing calls:
lsr.php?ohgo - New calls:
main.php?ohgo - Existing calls:
lsr.php?vtec=... - New calls:
main.php?vtec=...
11. mp4.php → main.php
No parameter changes needed (POST data remains the same)
- Existing calls: POST to
mp4.php - New calls: POST to
main.php
12. nws.php → main.php
No parameter changes needed
- Existing calls:
nws.php?officestats - New calls:
main.php?officestats
13. ohgo.php → main.php
Parameter change required
- Existing calls:
ohgo.php - New calls:
main.php?ohgo
14. power.php → main.php
Parameter change required
- Existing calls:
power.php - New calls:
main.php?power
15. powerapi.php → main.php
No parameter changes needed
- Existing calls:
powerapi.php?states - New calls:
main.php?states - Existing calls:
powerapi.php?county - New calls:
main.php?county
16. searchapi.php → main.php
No parameter changes needed
- Existing calls:
searchapi.php?county - New calls:
main.php?county
17. stormdata.php → main.php
No parameter changes needed (POST JSON remains the same)
- Existing calls: POST to
stormdata.php - New calls: POST to
main.php
18. update_field.php → main.php
No parameter changes needed (POST data remains the same)
- Existing calls: POST to
update_field.php - New calls: POST to
main.php
19. ver.php → main.php
No parameter changes needed
- Existing calls:
ver.php?lsrslist - New calls:
main.php?lsrslist
20. warntrack.php → main.php
Parameter change required
- Existing calls:
warntrack.php - New calls:
main.php?warntrack
Files NOT Requiring Changes
one.php
This file contains HTML/JavaScript interface and should remain as-is. It makes calls to other endpoints that have been integrated.
Bulk Update Script
For systems with many hardcoded references, use this sed command pattern:
# Update all .php files to use main.php
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/single\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/cam\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/camapi\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/camlist\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/camobs\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/db\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/fire\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/individualcam\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/lsr\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/mp4\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/nws\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/ohgo\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/power\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/powerapi\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/searchapi\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/stormdata\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/update_field\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/ver\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/warntrack\.php/main.php/g' {} \;
Testing Migration
After updating references, test key endpoints:
# Test basic camera functionality
curl "http://your-server/main.php?camid=123"
# Test admin functions
curl -X POST "http://your-server/main.php" -d "action=checkurl&url=http://example.com"
# Test storm data API
curl -X POST "http://your-server/main.php" \
-H "Content-Type: application/json" \
-d '{"request_type":"power","start_time":"2025-01-01","area_geojson":"{\"type\":\"Polygon\",\"coordinates\":[[[-82,38],[-81,38],[-81,39],[-82,39],[-82,38]]}"}'
Original Files Consolidated
This integrated file consolidates the following original scripts:
admin.php- Admin functionscam.php- Active camerascamapi.php- Camera API with filterscamcircle.php- Camera buffer circlescamlist.php- Camera listcamobs.php- Camera observationsdb.php- Weather station datafire.php- Fire dataindividualcam.php- Individual camera imageslsr.php- Local storm reportsmp4.php- GIF creationnws.php- NWS staff dataohgo.php- OHGO road dataone.php- HTML interface (not integrated)power.php- Power outagespowerapi.php- Advanced power APIpowerapitest.php- Power API testsearchapi.php- Search APIsingle.php- Single camera infostormdata.php- Storm data APIupdate_field.php- Camera field updatesver.php- Verification datawarntrack.php- Warning tracking
Usage Examples
Get all active cameras:
curl "http://your-server/main.php?cams"
Get camera within bounding box:
curl "http://your-server/main.php?cams&lat1=38.0&lon1=-82.0&lat2=39.0&lon2=-81.0&elevbottom=100&elevtop=1000"
Update camera hydro status:
curl -X POST "http://your-server/main.php" \
-d "camid=123&field=hydro&value=true"
Query storm data with polygon:
curl -X POST "http://your-server/main.php" \
-H "Content-Type: application/json" \
-d '{
"request_type": "power",
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-01-02 00:00:00",
"area_geojson": {
"type": "Polygon",
"coordinates": [[[-82, 38], [-81, 38], [-81, 39], [-82, 39], [-82, 38]]]
},
"buffer": 2
}'
Notes
- The
one.phpfile contains HTML/JavaScript interface and is not integrated into this API endpoint. - All database connections use the same credentials and should be pooled in production.
- Geographic data uses SRID 4326 (WGS84) unless otherwise specified.
- Time-based queries typically use UTC unless converted to local time zones.
- The integrated file maintains backward compatibility with existing callers by preserving all original functionality.