-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbroker.py
More file actions
39 lines (33 loc) · 829 Bytes
/
broker.py
File metadata and controls
39 lines (33 loc) · 829 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
32
33
34
35
36
37
38
39
# This is an example of a mqtt broker to test the server mqtt
# Normally the server should send the reveived information to the broker
from dotenv import load_dotenv
import os
import asyncio
from amqtt.broker import Broker
load_dotenv()
HOST = os.getenv("HOST", "0.0.0.0")
PORT = int(os.getenv("PORT", "1885"))
# This is a default basic config
config= {
"listeners" : {
"default": {
"type" : "tcp",
"bind" : f"{HOST}:{PORT}"
}
},
"sys_interval" : 10,
"topic-check" : {
"enabled" : False,
}
}
async def main():
broker = Broker(config)
await broker.start()
print(f"{HOST}:{PORT}")
try:
while 1:
await asyncio.sleep(3600)
finally:
await broker.shutdown()
if __name__ == "__main__":
asyncio.run(main())