Add MQTT initial idea
parent
eca3e08291
commit
8a67202247
@ -0,0 +1,16 @@
|
||||
listeners:
|
||||
default:
|
||||
max-connections: 50000
|
||||
type: tcp
|
||||
tcp:
|
||||
bind: 0.0.0.0:1883
|
||||
ws:
|
||||
bind: 0.0.0.0:8080
|
||||
type: ws
|
||||
timeout-disconnect-delay: 2
|
||||
auth:
|
||||
plugins: ['auth.anonymous'] #List of plugins to activate for authentication among all registered plugins
|
||||
allow-anonymous: true
|
||||
#password-file: /some/passwd_file
|
||||
topic-check:
|
||||
enabled: false # Set to False if topic filtering is not needed
|
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import logging
|
||||
import asyncio
|
||||
|
||||
from amqtt.client import MQTTClient
|
||||
from amqtt.mqtt.constants import QOS_0, QOS_1, QOS_2
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def test_coro():
|
||||
C = MQTTClient()
|
||||
await C.connect('mqtt://test.mosquitto.org/')
|
||||
tasks = [
|
||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=QOS_1)),
|
||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=QOS_2)),
|
||||
]
|
||||
await asyncio.wait(tasks)
|
||||
logger.info("messages published")
|
||||
await C.disconnect()
|
||||
|
||||
|
||||
async def test_coro2():
|
||||
try:
|
||||
C = MQTTClient()
|
||||
ret = await C.connect('mqtt://127.0.0.1:1883/')
|
||||
message = await C.publish('a/b', b'TEST MESSAGE WITH QOS_0', qos=QOS_0)
|
||||
message = await C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=QOS_1)
|
||||
message = await C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=QOS_2)
|
||||
#print(message)
|
||||
logger.info("messages published")
|
||||
await C.disconnect()
|
||||
except ConnectException as ce:
|
||||
logger.error("Connection failed: %s" % ce)
|
||||
asyncio.get_event_loop().stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
formatter = "[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
||||
logging.basicConfig(level=logging.DEBUG, format=formatter)
|
||||
asyncio.get_event_loop().run_until_complete(test_coro())
|
||||
asyncio.get_event_loop().run_until_complete(test_coro2())
|
@ -1 +1,3 @@
|
||||
pywaggle[all]
|
||||
amqtt==0.11.0b1
|
||||
pyyaml
|
@ -0,0 +1,3 @@
|
||||
sensors:
|
||||
pico1:
|
||||
- "distance"
|
Loading…
Reference in New Issue