1- # iotcore - MQTT and IoT capabilities to Django Rest Framework and FastAPI.
1+ # Iotcore - MQTT and IoT capabilities to Django Rest Framework and FastAPI.
22
3-
4- Project under development. Apis can change often until stable.
3+ The project aims to give full support for mqtt based server and related apis. The internals of the mqtt server is
4+ written in golang. The python will not directly interact with the golang instead communicate using grpc(planned). The
5+ motive is to avoid the GIL limitation of python and bring all the fun features offered by golang.
56
67## Planned Features
78
8- * MQTT based IoT protocol
9- * MQTT broker with websocket and tcp support (Written in golang)
10- * Easy sensor data storage
11- * APIs for IoT Device management and storage
12- * Most of the IoT logics will be handled by inbuilt golang application. It will then communicate with the django using channels
13- * and more coming soon
9+ * Full fledged MQTT server
10+ * with websocket and tcp support (Written in golang)
11+ * MQTT v5 support
12+ * and more coming soon
1413
1514## Installation
1615
1918pip install iotcore
2019```
2120
21+ # FastAPI setup
22+
23+ ``` python
24+ from fastapi import FastAPI
25+ from contextlib import asynccontextmanager
26+ from iotcore import IotCore
27+
28+ iot_core = IotCore()
29+
30+
31+ @asynccontextmanager
32+ async def lifespan (app : FastAPI):
33+ iot_core.run()
34+ yield
35+
36+
37+ app = FastAPI(lifespan = lifespan)
38+
39+
40+ @app.get (" /" )
41+ def read_root ():
42+ return {" Hello" : " World" }
43+
44+ ```
45+
46+ Output
47+
48+ ``` shell
49+ ❯ cd examples/fastapi
50+ ❯ uvicorn main:app
51+ INFO: Started server process [62593]
52+ INFO: Waiting for application startup.
53+ Starting Go process...
54+ INFO: Application startup complete.
55+ INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
56+ 11:21PM INF added hook hook=allow-all-auth
57+ 11:21PM INF attached listener address=:1883 id=t1 protocol=tcp
58+ 11:21PM INF attached listener address=:1882 id=ws1 protocol=ws
59+ 11:21PM INF attached listener address=:8080 id=stats protocol=http
60+ 11:21PM INF mochi mqtt starting version=2.3.0
61+ 11:21PM INF mochi mqtt server started
62+
63+ ```
64+
65+ # Django Setup
66+
2267Then add iotcore to the django apps as below in the settings.py file of your project
2368``` python
2469INSTALLED_APPS = [
@@ -27,17 +72,16 @@ INSTALLED_APPS = [
2772]
2873```
2974
30- Now Connect to mqtt broker on localhost
31- MQTT Port : 1883
32- Websocket Port : 1882
33- Stat Port: 8080
75+ Now Connect to mqtt broker on localhost
76+ MQTT Port : 1883
77+ Websocket Port : 1882
78+ Stat Port: 8080
3479
3580# Run Example project
3681
3782``` shell
38- cd example
3983pip install -r requirements.txt
40- python manage.py runserver
84+ python examples/ manage.py runserver
4185```
4286Output
4387
@@ -58,6 +102,8 @@ Starting golang
58102
59103```
60104
105+ For more details check the example folder
106+
61107## Development
62108
63109Use mage for development
0 commit comments