iotml 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {iotml-0.2.0 → iotml-0.2.2}/PKG-INFO +3 -1
- iotml-0.2.2/iotml/coap.py +139 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml.egg-info/PKG-INFO +3 -1
- {iotml-0.2.0 → iotml-0.2.2}/iotml.egg-info/SOURCES.txt +1 -0
- iotml-0.2.2/iotml.egg-info/entry_points.txt +4 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml.egg-info/requires.txt +2 -0
- {iotml-0.2.0 → iotml-0.2.2}/pyproject.toml +5 -2
- iotml-0.2.0/iotml.egg-info/entry_points.txt +0 -3
- {iotml-0.2.0 → iotml-0.2.2}/LICENSE +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/README.md +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml/__init__.py +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml/__main__.py +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml/coapsupa.py +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml/main.py +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml.egg-info/dependency_links.txt +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/iotml.egg-info/top_level.txt +0 -0
- {iotml-0.2.0 → iotml-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: iotml
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: IoT & Data Analytics Lab toolkit for live API fetching, visualization, and ML models
|
|
5
5
|
Author: Meena
|
|
6
6
|
License-Expression: MIT
|
|
@@ -13,6 +13,8 @@ Requires-Dist: pandas
|
|
|
13
13
|
Requires-Dist: matplotlib
|
|
14
14
|
Requires-Dist: scikit-learn
|
|
15
15
|
Requires-Dist: urllib3
|
|
16
|
+
Requires-Dist: aiocoap
|
|
17
|
+
Requires-Dist: streamlit
|
|
16
18
|
Dynamic: license-file
|
|
17
19
|
|
|
18
20
|
# iotml
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
COAP_SERVER_CODE = '''import asyncio
|
|
4
|
+
import requests
|
|
5
|
+
import urllib3
|
|
6
|
+
from aiocoap import Context, Message, resource
|
|
7
|
+
|
|
8
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
9
|
+
|
|
10
|
+
WEATHER_URL = (
|
|
11
|
+
"https://api.open-meteo.com/v1/forecast"
|
|
12
|
+
"?latitude=10.0159"
|
|
13
|
+
"&longitude=76.3419"
|
|
14
|
+
"¤t=temperature_2m,relative_humidity_2m,weather_code"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
AIR_QUALITY_URL = (
|
|
18
|
+
"https://air-quality-api.open-meteo.com/v1/air-quality"
|
|
19
|
+
"?latitude=10.0159"
|
|
20
|
+
"&longitude=76.3419"
|
|
21
|
+
"¤t=pm10,pm2_5,carbon_monoxide,"
|
|
22
|
+
"nitrogen_dioxide,ozone,european_aqi"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def safe_get(url):
|
|
26
|
+
try:
|
|
27
|
+
return requests.get(url, timeout=10)
|
|
28
|
+
except requests.exceptions.SSLError:
|
|
29
|
+
return requests.get(url, timeout=10, verify=False)
|
|
30
|
+
|
|
31
|
+
class WeatherResource(resource.Resource):
|
|
32
|
+
async def render_get(self, request):
|
|
33
|
+
try:
|
|
34
|
+
response = safe_get(WEATHER_URL)
|
|
35
|
+
current = response.json()["current"]
|
|
36
|
+
result = {
|
|
37
|
+
"temperature": current["temperature_2m"],
|
|
38
|
+
"humidity": current["relative_humidity_2m"],
|
|
39
|
+
"weather_code": current["weather_code"]
|
|
40
|
+
}
|
|
41
|
+
return Message(payload=str(result).encode())
|
|
42
|
+
except Exception as e:
|
|
43
|
+
return Message(payload=f"Error: {e}".encode())
|
|
44
|
+
|
|
45
|
+
class AirQualityResource(resource.Resource):
|
|
46
|
+
async def render_get(self, request):
|
|
47
|
+
try:
|
|
48
|
+
response = safe_get(AIR_QUALITY_URL)
|
|
49
|
+
current = response.json()["current"]
|
|
50
|
+
result = {
|
|
51
|
+
"pm10": current["pm10"],
|
|
52
|
+
"pm2_5": current["pm2_5"],
|
|
53
|
+
"carbon_monoxide": current["carbon_monoxide"],
|
|
54
|
+
"nitrogen_dioxide": current["nitrogen_dioxide"],
|
|
55
|
+
"ozone": current["ozone"],
|
|
56
|
+
"european_aqi": current["european_aqi"]
|
|
57
|
+
}
|
|
58
|
+
return Message(payload=str(result).encode())
|
|
59
|
+
except Exception as e:
|
|
60
|
+
return Message(payload=f"Error: {e}".encode())
|
|
61
|
+
|
|
62
|
+
async def main():
|
|
63
|
+
root = resource.Site()
|
|
64
|
+
root.add_resource(["weather"], WeatherResource())
|
|
65
|
+
root.add_resource(["airquality"], AirQualityResource())
|
|
66
|
+
await Context.create_server_context(root, bind=("127.0.0.1", 5683))
|
|
67
|
+
print("CoAP Server started at coap://127.0.0.1:5683")
|
|
68
|
+
await asyncio.get_running_loop().create_future()
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
asyncio.run(main())
|
|
72
|
+
'''
|
|
73
|
+
|
|
74
|
+
STREAMLIT_CLIENT_CODE = '''import streamlit as st
|
|
75
|
+
import asyncio
|
|
76
|
+
import ast
|
|
77
|
+
from aiocoap import Context, Message, GET
|
|
78
|
+
|
|
79
|
+
async def coap_get(uri):
|
|
80
|
+
protocol = await Context.create_client_context()
|
|
81
|
+
request = Message(code=GET, uri=uri)
|
|
82
|
+
response = await protocol.request(request).response
|
|
83
|
+
return response.payload.decode()
|
|
84
|
+
|
|
85
|
+
st.set_page_config(page_title="Environmental Monitoring", page_icon="🌍")
|
|
86
|
+
st.title("🌍 Environmental Monitoring System")
|
|
87
|
+
st.write("Retrieve weather and air quality data using CoAP GET requests.")
|
|
88
|
+
|
|
89
|
+
st.header("🌤️ Weather")
|
|
90
|
+
if st.button("Get Weather Data"):
|
|
91
|
+
with st.spinner("Requesting weather data..."):
|
|
92
|
+
try:
|
|
93
|
+
response = asyncio.run(coap_get("coap://127.0.0.1:5683/weather"))
|
|
94
|
+
data = ast.literal_eval(response)
|
|
95
|
+
st.success("Weather data received")
|
|
96
|
+
col1, col2, col3 = st.columns(3)
|
|
97
|
+
with col1:
|
|
98
|
+
st.metric("Temperature", f"{data['temperature']} °C")
|
|
99
|
+
with col2:
|
|
100
|
+
st.metric("Humidity", f"{data['humidity']} %")
|
|
101
|
+
with col3:
|
|
102
|
+
st.metric("Weather Code", data["weather_code"])
|
|
103
|
+
except Exception as e:
|
|
104
|
+
st.error(f"CoAP Error: {e}")
|
|
105
|
+
|
|
106
|
+
st.header("🌫️ Air Quality")
|
|
107
|
+
if st.button("Get Air Quality Data"):
|
|
108
|
+
with st.spinner("Requesting air quality data..."):
|
|
109
|
+
try:
|
|
110
|
+
response = asyncio.run(coap_get("coap://127.0.0.1:5683/airquality"))
|
|
111
|
+
data = ast.literal_eval(response)
|
|
112
|
+
st.success("Air quality data received")
|
|
113
|
+
col1, col2, col3 = st.columns(3)
|
|
114
|
+
with col1:
|
|
115
|
+
st.metric("PM10", f"{data['pm10']} µg/m³")
|
|
116
|
+
with col2:
|
|
117
|
+
st.metric("PM2.5", f"{data['pm2_5']} µg/m³")
|
|
118
|
+
with col3:
|
|
119
|
+
st.metric("European AQI", data["european_aqi"])
|
|
120
|
+
col4, col5 = st.columns(2)
|
|
121
|
+
with col4:
|
|
122
|
+
st.metric("Carbon Monoxide", f"{data['carbon_monoxide']} µg/m³")
|
|
123
|
+
with col5:
|
|
124
|
+
st.metric("Nitrogen Dioxide", f"{data['nitrogen_dioxide']} µg/m³")
|
|
125
|
+
st.metric("Ozone", f"{data['ozone']} µg/m³")
|
|
126
|
+
except Exception as e:
|
|
127
|
+
st.error(f"CoAP Error: {e}")
|
|
128
|
+
'''
|
|
129
|
+
|
|
130
|
+
def main():
|
|
131
|
+
with open("coap_server.py", "w", encoding="utf-8") as f:
|
|
132
|
+
f.write(COAP_SERVER_CODE)
|
|
133
|
+
with open("streamlit_client.py", "w", encoding="utf-8") as f:
|
|
134
|
+
f.write(STREAMLIT_CLIENT_CODE)
|
|
135
|
+
print("[+] Successfully generated 'coap_server.py'!")
|
|
136
|
+
print("[+] Successfully generated 'streamlit_client.py'!")
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: iotml
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: IoT & Data Analytics Lab toolkit for live API fetching, visualization, and ML models
|
|
5
5
|
Author: Meena
|
|
6
6
|
License-Expression: MIT
|
|
@@ -13,6 +13,8 @@ Requires-Dist: pandas
|
|
|
13
13
|
Requires-Dist: matplotlib
|
|
14
14
|
Requires-Dist: scikit-learn
|
|
15
15
|
Requires-Dist: urllib3
|
|
16
|
+
Requires-Dist: aiocoap
|
|
17
|
+
Requires-Dist: streamlit
|
|
16
18
|
Dynamic: license-file
|
|
17
19
|
|
|
18
20
|
# iotml
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "iotml"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "IoT & Data Analytics Lab toolkit for live API fetching, visualization, and ML models"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -19,11 +19,14 @@ dependencies = [
|
|
|
19
19
|
"matplotlib",
|
|
20
20
|
"scikit-learn",
|
|
21
21
|
"urllib3",
|
|
22
|
+
"aiocoap",
|
|
23
|
+
"streamlit",
|
|
22
24
|
]
|
|
23
25
|
|
|
24
26
|
[project.scripts]
|
|
25
27
|
iotml = "iotml.main:main"
|
|
26
|
-
|
|
28
|
+
coap = "iotml.coap:main"
|
|
29
|
+
coapsupa = "iotml.coap:main"
|
|
27
30
|
|
|
28
31
|
[tool.setuptools.packages.find]
|
|
29
32
|
where = ["."]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|