iotpot 0.1.0__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.
iotpot-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: iotpot
3
+ Version: 0.1.0
4
+ Summary: basic MQTT and CoAP client-server helper
5
+ Author: XIN LIU
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+
10
+ # iotprotocols
11
+
12
+ A simple Python package that acts as a basic MQTT and CoAP
13
+ client-server helper.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install iotprotocols
iotpot-0.1.0/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # iotprotocols
2
+
3
+ A simple Python package that acts as a basic MQTT and CoAP
4
+ client-server helper.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ pip install iotprotocols
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: iotpot
3
+ Version: 0.1.0
4
+ Summary: basic MQTT and CoAP client-server helper
5
+ Author: XIN LIU
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+
10
+ # iotprotocols
11
+
12
+ A simple Python package that acts as a basic MQTT and CoAP
13
+ client-server helper.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install iotprotocols
@@ -0,0 +1,13 @@
1
+ README.md
2
+ pyproject.toml
3
+ iotpot.egg-info/PKG-INFO
4
+ iotpot.egg-info/SOURCES.txt
5
+ iotpot.egg-info/dependency_links.txt
6
+ iotpot.egg-info/top_level.txt
7
+ iotprotocols/__init__.py
8
+ iotprotocols/coap.py
9
+ iotprotocols/mqtt.py
10
+ iotprotocols/templates/coap_client.py
11
+ iotprotocols/templates/coap_server.py
12
+ iotprotocols/templates/mqtt_client.py
13
+ iotprotocols/templates/mqtt_server.py
@@ -0,0 +1 @@
1
+ iotprotocols
@@ -0,0 +1,2 @@
1
+ from .mqtt import mqtt
2
+ from .coap import coap
@@ -0,0 +1,23 @@
1
+ from pathlib import Path
2
+
3
+
4
+ def coap():
5
+ template_dir = Path(__file__).parent / "templates"
6
+
7
+ client_code = (template_dir / "coap_client.py").read_text(
8
+ encoding="utf-8"
9
+ )
10
+
11
+ server_code = (template_dir / "coap_server.py").read_text(
12
+ encoding="utf-8"
13
+ )
14
+
15
+ Path("coap_client.py").write_text(
16
+ client_code,
17
+ encoding="utf-8"
18
+ )
19
+
20
+ Path("coap_server.py").write_text(
21
+ server_code,
22
+ encoding="utf-8"
23
+ )
@@ -0,0 +1,23 @@
1
+ from pathlib import Path
2
+
3
+
4
+ def mqtt():
5
+ template_dir = Path(__file__).parent / "templates"
6
+
7
+ client_code = (template_dir / "mqtt_client.py").read_text(
8
+ encoding="utf-8"
9
+ )
10
+
11
+ server_code = (template_dir / "mqtt_server.py").read_text(
12
+ encoding="utf-8"
13
+ )
14
+
15
+ Path("mqtt_client.py").write_text(
16
+ client_code,
17
+ encoding="utf-8"
18
+ )
19
+
20
+ Path("mqtt_server.py").write_text(
21
+ server_code,
22
+ encoding="utf-8"
23
+ )
@@ -0,0 +1,23 @@
1
+ import asyncio
2
+
3
+ from aiocoap import Context
4
+ from aiocoap import Message
5
+ from aiocoap import GET
6
+
7
+
8
+ async def main():
9
+
10
+ protocol = await Context.create_client_context()
11
+
12
+ request = Message(
13
+ code=GET,
14
+ uri="coap://127.0.0.1/temperature"
15
+ )
16
+
17
+ response = await protocol.request(request).response
18
+
19
+ print("Response:", response.payload.decode())
20
+
21
+
22
+ if __name__ == "__main__":
23
+ asyncio.run(main())
@@ -0,0 +1,35 @@
1
+ import asyncio
2
+
3
+ from aiocoap import Context
4
+ from aiocoap import Message
5
+ from aiocoap.resource import Resource, Site
6
+
7
+
8
+ class TemperatureResource(Resource):
9
+
10
+ async def render_get(self, request):
11
+ payload = b"Temperature: 25 C"
12
+
13
+ return Message(
14
+ payload=payload
15
+ )
16
+
17
+
18
+ async def main():
19
+
20
+ root = Site()
21
+
22
+ root.add_resource(
23
+ ["temperature"],
24
+ TemperatureResource()
25
+ )
26
+
27
+ await Context.create_server_context(root)
28
+
29
+ print("CoAP server running...")
30
+
31
+ await asyncio.get_running_loop().create_future()
32
+
33
+
34
+ if __name__ == "__main__":
35
+ asyncio.run(main())
@@ -0,0 +1,25 @@
1
+ import paho.mqtt.client as mqtt
2
+
3
+ BROKER = "broker.hivemq.com"
4
+ PORT = 1883
5
+ TOPIC = "iotprotocols/test"
6
+
7
+
8
+ def on_connect(client, userdata, flags, rc):
9
+ print("Connected with result code:", rc)
10
+
11
+ client.subscribe(TOPIC)
12
+
13
+
14
+ def on_message(client, userdata, msg):
15
+ print("Received:", msg.payload.decode())
16
+
17
+
18
+ client = mqtt.Client()
19
+
20
+ client.on_connect = on_connect
21
+ client.on_message = on_message
22
+
23
+ client.connect(BROKER, PORT)
24
+
25
+ client.loop_forever()
@@ -0,0 +1,20 @@
1
+ import paho.mqtt.client as mqtt
2
+ import time
3
+
4
+ BROKER = "broker.hivemq.com"
5
+ PORT = 1883
6
+ TOPIC = "iotprotocols/test"
7
+
8
+
9
+ client = mqtt.Client()
10
+
11
+ client.connect(BROKER, PORT)
12
+
13
+ while True:
14
+ message = "Hello from MQTT"
15
+
16
+ client.publish(TOPIC, message)
17
+
18
+ print("Published:", message)
19
+
20
+ time.sleep(2)
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+
6
+ [project]
7
+ name = "iotpot"
8
+ version = "0.1.0"
9
+ description = " basic MQTT and CoAP client-server helper"
10
+ readme = "README.md"
11
+ requires-python = ">=3.9"
12
+ license = {text = "MIT"}
13
+ authors = [
14
+ {name = "XIN LIU"}
15
+ ]
16
+
17
+
18
+ [tool.setuptools]
19
+ include-package-data = true
20
+
21
+
22
+ [tool.setuptools.packages.find]
23
+ include = ["iotprotocols*"]
24
+
25
+
26
+ [tool.setuptools.package-data]
27
+ iotprotocols = [
28
+ "templates/*.py"
29
+ ]
iotpot-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+