api - restart_{service}
add restart_{service}
- restart_Helperbot
- restart_MQTTServer
- Removed a few outstanding references to threads
This commit is contained in:
parent
58b3567887
commit
7fc7cb80cb
4 changed files with 229 additions and 151 deletions
|
|
@ -31,7 +31,7 @@ logging.getLogger("hbmqtt.client").setLevel(logging.CRITICAL + 1) # Ignore this
|
|||
|
||||
class MQTTHelperBot:
|
||||
|
||||
Client = MQTTClient()
|
||||
Client = None
|
||||
wait_resp_timeout_seconds = 10
|
||||
expire_msg_seconds = 10
|
||||
|
||||
|
|
@ -39,14 +39,14 @@ class MQTTHelperBot:
|
|||
self.address = address
|
||||
self.client_id = "helper1@bumper/helper1"
|
||||
self.command_responses = []
|
||||
self.helperthread = None
|
||||
|
||||
async def start_helper_bot(self):
|
||||
|
||||
try:
|
||||
self.Client = MQTTClient(
|
||||
client_id=self.client_id, config={"check_hostname": False}
|
||||
)
|
||||
if self.Client is None:
|
||||
self.Client = MQTTClient(
|
||||
client_id=self.client_id, config={"check_hostname": False}
|
||||
)
|
||||
|
||||
await self.Client.connect(
|
||||
"mqtts://{}:{}/".format(self.address[0], self.address[1]),
|
||||
|
|
@ -183,29 +183,30 @@ class MQTTHelperBot:
|
|||
}
|
||||
|
||||
async def send_command(self, cmdjson, requestid):
|
||||
try:
|
||||
ttopic = "iot/p2p/{}/helper1/bumper/helper1/{}/{}/{}/q/{}/{}".format(
|
||||
cmdjson["cmdName"],
|
||||
cmdjson["toId"],
|
||||
cmdjson["toType"],
|
||||
cmdjson["toRes"],
|
||||
requestid,
|
||||
cmdjson["payloadType"],
|
||||
)
|
||||
if not self.Client._handler.writer is None:
|
||||
try:
|
||||
await self.Client.publish(
|
||||
ttopic, str(cmdjson["payload"]).encode(), QOS_0
|
||||
ttopic = "iot/p2p/{}/helper1/bumper/helper1/{}/{}/{}/q/{}/{}".format(
|
||||
cmdjson["cmdName"],
|
||||
cmdjson["toId"],
|
||||
cmdjson["toType"],
|
||||
cmdjson["toRes"],
|
||||
requestid,
|
||||
cmdjson["payloadType"],
|
||||
)
|
||||
try:
|
||||
await self.Client.publish(
|
||||
ttopic, str(cmdjson["payload"]).encode(), QOS_0
|
||||
)
|
||||
except Exception as e:
|
||||
helperbotlog.exception("{}".format(e))
|
||||
|
||||
resp = await self.wait_for_resp(requestid)
|
||||
|
||||
return resp
|
||||
|
||||
except Exception as e:
|
||||
helperbotlog.exception("{}".format(e))
|
||||
|
||||
resp = await self.wait_for_resp(requestid)
|
||||
|
||||
return resp
|
||||
|
||||
except Exception as e:
|
||||
helperbotlog.exception("{}".format(e))
|
||||
return {}
|
||||
return {}
|
||||
|
||||
|
||||
class MQTTServer:
|
||||
|
|
@ -233,7 +234,6 @@ class MQTTServer:
|
|||
|
||||
def __init__(self, address):
|
||||
try:
|
||||
self.mqttserverthread = None
|
||||
self.address = address
|
||||
|
||||
# The below adds a plugin to the hbmqtt.broker.plugins without having to futz with setup.py
|
||||
|
|
@ -355,6 +355,7 @@ class BumperMQTTServer_Plugin:
|
|||
|
||||
async def on_broker_client_connected(self, client_id):
|
||||
try:
|
||||
|
||||
didsplit = str(client_id).split("@")
|
||||
|
||||
bot = bumper.bot_get(didsplit[0])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue