-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor_data_processor.py
More file actions
31 lines (27 loc) · 941 Bytes
/
sensor_data_processor.py
File metadata and controls
31 lines (27 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Sample Python Script for IoT Sensor Data Processing
import json
import requests
def fetch_sensor_data(sensor_endpoint):
# Example function to fetch data from a sensor
response = requests.get(sensor_endpoint)
if response.status_code == 200:
return json.loads(response.content)
else:
return None
def process_sensor_data(data):
# Example function to process sensor data
processed_data = {
'air_quality': data['AQI'],
'water_quality': data['WQI'],
# Add more processing logic as needed
}
return processed_data
# Example usage
if __name__ == "__main__":
sensor_data = fetch_sensor_data('http://example-sensor-api.com/data')
if sensor_data:
print("Fetched Sensor Data:", sensor_data)
processed_data = process_sensor_data(sensor_data)
print("Processed Sensor Data:", processed_data)
else:
print("Failed to fetch sensor data.")