A decentralized smart contract built on the Stacks blockchain for managing a distributed network of climate monitoring stations. This contract enables users to register monitoring devices, submit weather measurements, and maintain a transparent, immutable record of climate data.
This smart contract provides a trustless infrastructure for climate data collection by allowing anyone to register monitoring stations and submit validated weather measurements. All data is stored on-chain with proper validation and access controls.
- Decentralized Station Registry: Register climate monitoring stations with geographic coordinates
- Validated Measurements: Submit weather data with comprehensive bounds checking
- Data Integrity: Immutable timestamp-based records of all climate measurements
- Access Control: Station owners control their devices; admin manages system parameters
- Multi-Monitor Support: Users can register and manage multiple monitoring stations
- Active/Inactive Status: Deactivate stations without deleting historical data
All submitted measurements are validated against the following bounds:
- Temperature: -50°C to 60°C (configurable by admin)
- Humidity: 0% to 100%
- Pressure: Must be greater than 0
- Wind Speed: 0 to 500 units
- Precipitation: 0 to 1000 units
- Coordinates: Latitude (-90 to 90), Longitude (-180 to 180)
Register a new climate monitoring station.
Parameters:
name: Station identifier (1-64 ASCII characters)latitude: Geographic latitude (-90 to 90)longitude: Geographic longitude (-180 to 180)
Returns: Unique monitor ID
Example:
(register-monitor "Downtown Weather Station" 40 -74)Submit a climate measurement from a registered monitor.
Parameters:
monitor-id: The station's unique identifiertemperature: Temperature reading (°C)humidity: Humidity percentage (0-100)pressure: Atmospheric pressurewind-speed: Wind speed (0-500)precipitation: Precipitation amount (0-1000)
Authorization: Only the station owner or contract admin can submit readings.
Example:
(submit-measurement u0 25 65 1013 15 0)Deactivate a monitoring station (preserves historical data).
Parameters:
monitor-id: The station to deactivate
Authorization: Only the station owner can deactivate.
Update acceptable temperature range for validation.
Parameters:
min-temp: Minimum acceptable temperaturemax-temp: Maximum acceptable temperature
Authorization: Admin only
Retrieve station details by ID.
Returns: Station information including owner, name, coordinates, and status.
Get the most recent measurement for a station.
Returns: Complete weather reading with all parameters.
Count how many stations a principal owns.
Returns: Number of monitors registered by the owner.
Check if a monitoring station is currently active.
Returns: Boolean active status.
Get the total number of registered monitoring stations.
Returns: Total monitor count.
u100: Not authorized to perform this actionu101: Invalid or non-existent monitor IDu102: Invalid measurement data (out of bounds)u103: Duplicate monitor (already exists)u104: Resource not found
- Maximum Monitors: 10,000 stations network-wide
- Name Length: 64 ASCII characters maximum
- Data Storage: All measurements stored with block-height timestamps
- Bounds Validation: All inputs validated before storage
- Ownership Verification: Only owners can manage their stations
- Admin Controls: Separate admin privileges for system parameters
- Duplicate Prevention: Prevents duplicate station registration
- Existence Checks: Validates monitor IDs before operations
- Community Weather Networks: Grassroots climate monitoring initiatives
- Research Projects: Academic climate data collection
- Agricultural Monitoring: Farm-level weather tracking
- Urban Climate Studies: City-wide temperature and precipitation mapping
- Environmental Compliance: Transparent environmental data reporting
The contract is deployed on the Stacks blockchain. The deploying address becomes the admin with special privileges for managing system-wide parameters.