iotml 0.2.1__tar.gz → 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iotml
3
- Version: 0.2.1
3
+ Version: 0.2.3
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,87 @@
1
+ import os
2
+
3
+ COAP_SERVER_CODE = '''import asyncio
4
+ import json
5
+ import requests
6
+ import urllib3
7
+ from aiocoap import Context, Message, resource
8
+
9
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
10
+
11
+ class Environment(resource.Resource):
12
+ async def render_get(self, request):
13
+ weather_url = "https://api.open-meteo.com/v1/forecast?latitude=10.0159&longitude=76.3419&current=temperature_2m,relative_humidity_2m"
14
+ air_url = "https://air-quality-api.open-meteo.com/v1/air-quality?latitude=10.0159&longitude=76.3419&current=european_aqi"
15
+
16
+ try:
17
+ weather = requests.get(weather_url, timeout=10).json()["current"]
18
+ except requests.exceptions.SSLError:
19
+ weather = requests.get(weather_url, timeout=10, verify=False).json()["current"]
20
+
21
+ try:
22
+ air = requests.get(air_url, timeout=10).json()["current"]
23
+ except requests.exceptions.SSLError:
24
+ air = requests.get(air_url, timeout=10, verify=False).json()["current"]
25
+
26
+ data = {
27
+ "temperature": weather["temperature_2m"],
28
+ "humidity": weather["relative_humidity_2m"],
29
+ "aqi": air["european_aqi"]
30
+ }
31
+
32
+ print(data)
33
+
34
+ return Message(
35
+ payload=json.dumps(data).encode()
36
+ )
37
+
38
+ async def main():
39
+ root = resource.Site()
40
+ root.add_resource(
41
+ ["environment"],
42
+ Environment()
43
+ )
44
+ await Context.create_server_context(
45
+ root,
46
+ bind=("127.0.0.1", 5687)
47
+ )
48
+ print("Server started")
49
+ await asyncio.get_running_loop().create_future()
50
+
51
+ if __name__ == "__main__":
52
+ asyncio.run(main())
53
+ '''
54
+
55
+ STREAMLIT_CLIENT_CODE = '''import streamlit as st
56
+ import asyncio
57
+ from aiocoap import Context, Message, GET
58
+
59
+ async def get_data():
60
+ protocol = await Context.create_client_context()
61
+ request = Message(
62
+ code=GET,
63
+ uri="coap://127.0.0.1:5687/environment"
64
+ )
65
+ response = await protocol.request(request).response
66
+ return response.payload.decode()
67
+
68
+ st.title("Environmental Monitoring System")
69
+
70
+ if st.button("Get Data"):
71
+ response = asyncio.run(get_data())
72
+ data = eval(response)
73
+ st.write("Temperature:", data["temperature"], "°C")
74
+ st.write("Humidity:", data["humidity"], "%")
75
+ st.write("AQI:", data["aqi"])
76
+ '''
77
+
78
+ def main():
79
+ with open("coap_server.py", "w", encoding="utf-8") as f:
80
+ f.write(COAP_SERVER_CODE)
81
+ with open("streamlit_client.py", "w", encoding="utf-8") as f:
82
+ f.write(STREAMLIT_CLIENT_CODE)
83
+ print("[+] Successfully generated 'coap_server.py'!")
84
+ print("[+] Successfully generated 'streamlit_client.py'!")
85
+
86
+ if __name__ == "__main__":
87
+ main()
@@ -0,0 +1,7 @@
1
+ import os
2
+ import sys
3
+
4
+ from .coap import COAP_SERVER_CODE, STREAMLIT_CLIENT_CODE, main
5
+
6
+ if __name__ == "__main__":
7
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iotml
3
- Version: 0.2.1
3
+ Version: 0.2.3
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
@@ -3,3 +3,5 @@ pandas
3
3
  matplotlib
4
4
  scikit-learn
5
5
  urllib3
6
+ aiocoap
7
+ streamlit
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "iotml"
7
- version = "0.2.1"
7
+ version = "0.2.3"
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,6 +19,8 @@ dependencies = [
19
19
  "matplotlib",
20
20
  "scikit-learn",
21
21
  "urllib3",
22
+ "aiocoap",
23
+ "streamlit",
22
24
  ]
23
25
 
24
26
  [project.scripts]
iotml-0.2.1/iotml/coap.py DELETED
@@ -1,139 +0,0 @@
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
- "&current=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
- "&current=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,191 +0,0 @@
1
- import os
2
- import sys
3
-
4
- COAP_SERVER_CODE = '''import asyncio
5
- import requests
6
- import urllib3
7
- from aiocoap import Context, Message, resource
8
-
9
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
10
-
11
- WEATHER_URL = (
12
- "https://api.open-meteo.com/v1/forecast"
13
- "?latitude=10.0159"
14
- "&longitude=76.3419"
15
- "&current=temperature_2m,relative_humidity_2m,weather_code"
16
- )
17
-
18
- AIR_QUALITY_URL = (
19
- "https://air-quality-api.open-meteo.com/v1/air-quality"
20
- "?latitude=10.0159"
21
- "&longitude=76.3419"
22
- "&current=pm10,pm2_5,carbon_monoxide,"
23
- "nitrogen_dioxide,ozone,european_aqi"
24
- )
25
-
26
- def safe_get(url):
27
- try:
28
- return requests.get(url, timeout=10)
29
- except requests.exceptions.SSLError:
30
- return requests.get(url, timeout=10, verify=False)
31
-
32
- class WeatherResource(resource.Resource):
33
- async def render_get(self, request):
34
- try:
35
- response = safe_get(WEATHER_URL)
36
- current = response.json()["current"]
37
- result = {
38
- "temperature": current["temperature_2m"],
39
- "humidity": current["relative_humidity_2m"],
40
- "weather_code": current["weather_code"]
41
- }
42
- return Message(payload=str(result).encode())
43
- except Exception as e:
44
- return Message(payload=f"Error: {e}".encode())
45
-
46
- class AirQualityResource(resource.Resource):
47
- async def render_get(self, request):
48
- try:
49
- response = safe_get(AIR_QUALITY_URL)
50
- current = response.json()["current"]
51
- result = {
52
- "pm10": current["pm10"],
53
- "pm2_5": current["pm2_5"],
54
- "carbon_monoxide": current["carbon_monoxide"],
55
- "nitrogen_dioxide": current["nitrogen_dioxide"],
56
- "ozone": current["ozone"],
57
- "european_aqi": current["european_aqi"]
58
- }
59
- return Message(payload=str(result).encode())
60
- except Exception as e:
61
- return Message(payload=f"Error: {e}".encode())
62
-
63
- async def main():
64
- root = resource.Site()
65
- root.add_resource(["weather"], WeatherResource())
66
- root.add_resource(["airquality"], AirQualityResource())
67
- await Context.create_server_context(root, bind=("127.0.0.1", 5683))
68
- print("CoAP Server started at coap://127.0.0.1:5683")
69
- await asyncio.get_running_loop().create_future()
70
-
71
- if __name__ == "__main__":
72
- asyncio.run(main())
73
- '''
74
-
75
- STREAMLIT_CLIENT_CODE = '''import streamlit as st
76
- import asyncio
77
- import ast
78
- from aiocoap import Context, Message, GET
79
-
80
- async def coap_get(uri):
81
- protocol = await Context.create_client_context()
82
- request = Message(code=GET, uri=uri)
83
- response = await protocol.request(request).response
84
- return response.payload.decode()
85
-
86
- st.set_page_config(page_title="Environmental Monitoring", page_icon="🌍")
87
- st.title("🌍 Environmental Monitoring System")
88
- st.write("Retrieve weather and air quality data using CoAP GET requests.")
89
-
90
- st.header("🌤️ Weather")
91
- if st.button("Get Weather Data"):
92
- with st.spinner("Requesting weather data..."):
93
- try:
94
- response = asyncio.run(coap_get("coap://127.0.0.1:5683/weather"))
95
- data = ast.literal_eval(response)
96
- st.success("Weather data received")
97
- col1, col2, col3 = st.columns(3)
98
- with col1:
99
- st.metric("Temperature", f"{data['temperature']} °C")
100
- with col2:
101
- st.metric("Humidity", f"{data['humidity']} %")
102
- with col3:
103
- st.metric("Weather Code", data["weather_code"])
104
- except Exception as e:
105
- st.error(f"CoAP Error: {e}")
106
-
107
- st.header("🌫️ Air Quality")
108
- if st.button("Get Air Quality Data"):
109
- with st.spinner("Requesting air quality data..."):
110
- try:
111
- response = asyncio.run(coap_get("coap://127.0.0.1:5683/airquality"))
112
- data = ast.literal_eval(response)
113
- st.success("Air quality data received")
114
- col1, col2, col3 = st.columns(3)
115
- with col1:
116
- st.metric("PM10", f"{data['pm10']} µg/m³")
117
- with col2:
118
- st.metric("PM2.5", f"{data['pm2_5']} µg/m³")
119
- with col3:
120
- st.metric("European AQI", data["european_aqi"])
121
- col4, col5 = st.columns(2)
122
- with col4:
123
- st.metric("Carbon Monoxide", f"{data['carbon_monoxide']} µg/m³")
124
- with col5:
125
- st.metric("Nitrogen Dioxide", f"{data['nitrogen_dioxide']} µg/m³")
126
- st.metric("Ozone", f"{data['ozone']} µg/m³")
127
- except Exception as e:
128
- st.error(f"CoAP Error: {e}")
129
- '''
130
-
131
- FILES = {
132
- "1": ("coap_server.py", COAP_SERVER_CODE),
133
- "2": ("streamlit_client.py", STREAMLIT_CLIENT_CODE),
134
- }
135
-
136
- ALIAS_MAP = {
137
- "1": "1", "coap_server": "1", "server": "1", "coap": "1",
138
- "2": "2", "streamlit_client": "2", "client": "2", "streamlit": "2", "ui": "2"
139
- }
140
-
141
- def generate_coap_files(target="all"):
142
- choice = str(target).strip().lower()
143
- if choice in ["all", "", "*"]:
144
- for key in ["1", "2"]:
145
- fname, code = FILES[key]
146
- with open(fname, "w", encoding="utf-8") as f:
147
- f.write(code)
148
- print(f"[+] Successfully generated '{fname}'!")
149
- return
150
-
151
- key = ALIAS_MAP.get(choice)
152
- if key and key in FILES:
153
- fname, code = FILES[key]
154
- with open(fname, "w", encoding="utf-8") as f:
155
- f.write(code)
156
- print(f"[+] Successfully generated '{fname}'!")
157
- else:
158
- print(f"[-] Unknown option '{target}'. Available: 1/server, 2/client, all")
159
-
160
- def main():
161
- if len(sys.argv) > 1:
162
- cmd = sys.argv[1].lower()
163
- if cmd in ["all", "1", "2", "server", "client", "streamlit"]:
164
- generate_coap_files(cmd)
165
- return
166
-
167
- while True:
168
- print("\n1. Generate Code File 2. Exit")
169
- try:
170
- choice = input("Enter your choice: ").strip()
171
- except (KeyboardInterrupt, EOFError):
172
- print("\nProgram ended.")
173
- break
174
-
175
- if choice in ["1", "", "generate", "code", "g"]:
176
- print("\n 1 / coap_server -> coap_server.py")
177
- print(" 2 / streamlit_client -> streamlit_client.py\n")
178
- try:
179
- sub_choice = input("Enter choice [all]: ").strip()
180
- except (KeyboardInterrupt, EOFError):
181
- print("\nProgram ended.")
182
- break
183
- generate_coap_files(sub_choice if sub_choice else "all")
184
- elif choice.lower() in ["2", "exit", "exite", "quit", "q"]:
185
- print("Program ended.")
186
- break
187
- else:
188
- print("Invalid choice")
189
-
190
- if __name__ == "__main__":
191
- main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes