Beginning bumper's new journey #4
2 changed files with 36 additions and 7 deletions
|
|
@ -45,7 +45,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|||
body = {
|
||||
"devices": [
|
||||
{
|
||||
"class": "tmpClass",
|
||||
"class": "ls1ok3",
|
||||
"company": "eco-ng",
|
||||
"did": "tmpDeviceID",
|
||||
"name": "tmpName",
|
||||
|
|
|
|||
|
|
@ -5,19 +5,43 @@ import asyncio
|
|||
import os
|
||||
from hbmqtt.broker import Broker
|
||||
import hbmqtt
|
||||
import pkg_resources
|
||||
|
||||
|
||||
class BumperMQTTPlugin:
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
logging.debug('Bumper Plugin Initialized')
|
||||
|
||||
@asyncio.coroutine
|
||||
def on_broker_client_connected(self, client_id):
|
||||
logging.debug('Bumper Connection: %s connected' % client_id)
|
||||
#yield from self.context.broadcast_message('location/%s' % client_id, b'home')
|
||||
|
||||
@asyncio.coroutine
|
||||
def on_broker_client_disconnected(self, client_id):
|
||||
logging.debug('Bumper Connection: %s disconnected' % client_id)
|
||||
#yield from self.context.broadcast_message('location/%s' % client_id, b'not_home')
|
||||
|
||||
|
||||
class MQTTServer():
|
||||
clients = []
|
||||
exit_flag = False
|
||||
default_config = {}
|
||||
default_config = {}
|
||||
|
||||
@asyncio.coroutine
|
||||
def broker_coro(self):
|
||||
broker = hbmqtt.broker.Broker(config=self.default_config, plugin_namespace=".")
|
||||
|
||||
yield from broker.start()
|
||||
def broker_coro(self):
|
||||
broker = hbmqtt.broker.Broker(config=self.default_config)
|
||||
yield from broker.start()
|
||||
|
||||
def __init__(self, address, run_async=False):
|
||||
#The below adds a plugin to the hbmqtt.broker.plugins without having to futz with setup.py
|
||||
distribution = pkg_resources.Distribution("hbmqtt.broker.plugins")
|
||||
bumper_plugin = pkg_resources.EntryPoint.parse('bumper = bumper.mqttserver:BumperMQTTPlugin', dist=distribution)
|
||||
distribution._ep_map = {"hbmqtt.broker.plugins": {"bumper": bumper_plugin}}
|
||||
pkg_resources.working_set.add(distribution)
|
||||
#for entry_point in pkg_resources.iter_entry_points("hbmqtt.broker.plugins"):
|
||||
# print(entry_point)
|
||||
try:
|
||||
# Initialize bot server
|
||||
self.default_config = {
|
||||
|
|
@ -37,7 +61,12 @@ class MQTTServer():
|
|||
'allow-anonymous': True,
|
||||
'password-file': os.path.join(os.path.dirname(os.path.realpath(__file__)), "passwd"),
|
||||
'plugins': [
|
||||
'VacBotAuth'
|
||||
'' #No plugins == no auth
|
||||
]
|
||||
},
|
||||
'broker': {
|
||||
'plugins': [
|
||||
'bumper'
|
||||
]
|
||||
},
|
||||
'topic-check': {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue