Jobsite Environmental Sensor Ingestion Script
Collect, filter, and stream edge telemetry data from jobsite IoT nodes to cloud monitoring endpoints.
Use this template when building resilient data ingestion workers for jobsite safety and compliance monitoring. It outputs a lightweight edge script designed to process sensor bursts and alert on regulatory breaches.
Role: Lead Site Telemetry & Embedded Systems Engineer specializing in commercial real estate IoT networks.
Context
- Telemetry Transport Protocol: {{telemetry_source_protocol}}
- Sensor Poll Interval: {{sampling_interval_seconds}}
- Structural Vibration Ceiling: {{vibration_limit_g}}
- Permissible Decibel Ceiling: {{noise_threshold_db}}
- Compliance Webhook URL: {{alert_webhook_url}}
- Local Edge Buffer Path: {{local_cache_path}}
Task
Create a resilient edge Python monitoring script that ingests environmental telemetry across jobsite hardware nodes, computes moving window averages for noise and vibration, persists buffers locally during network outages, and dispatches immediate breach alerts.
Method
- Establish connection to the jobsite telemetry stream using {{telemetry_source_protocol}} with automatic retry logic.
- Configure periodic sampling loops governed strictly by {{sampling_interval_seconds}}.
- Validate incoming sensor payload schemas for dust, temperature, sound, and tri-axial acceleration.
- Maintain a 60-second sliding window buffer to compute rolling averages for environmental readings.
- Compare rolling vibration metrics against {{vibration_limit_g}} and acoustic levels against {{noise_threshold_db}}.
- Assemble an incident JSON payload upon limit violation and dispatch an HTTP POST to {{alert_webhook_url}}.
- Intercept network failure exceptions, writing telemetry packages into {{local_cache_path}} for subsequent replay.
- Implement a graceful SIGINT/SIGTERM shutdown hook to flush remaining buffers to persistent storage.
Constraints
- Memory footprint MUST NOT exceed 128MB to ensure execution on resource-constrained edge gateways.
- The script MUST continue logging to {{local_cache_path}} without crashing if the upstream network disconnects.
- Third-party dependencies MUST be limited to standard networking and parsing modules (e.g., requests, paho-mqtt).
- Plaintext API tokens or sensitive site credentials MUST NOT be hardcoded in the script body.
Output format
Format the response with the following clearly labeled sections:
- Runtime Architecture (brief overview of thread handling and queue mechanism).
- Complete Edge Python Script (fully runnable script with inline error handling).
- Daemon Service Configuration (systemd service unit file definition for automatic restart).
Self-review
- Check that moving window calculations handle zero-division and empty arrays cleanly.
- Verify all 6 context variables ({{telemetry_source_protocol}}, {{sampling_interval_seconds}}, {{vibration_limit_g}}, {{noise_threshold_db}}, {{alert_webhook_url}}, {{local_cache_path}}) are explicitly parameterized.
- Ensure the edge buffer replay mechanism flushes stored records once network connectivity is restored.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.