5
5
6
6
class BrokerFunctions ():
7
7
def __init__ (self ):
8
+ self .token = None
8
9
self .client = None
9
10
10
11
# connect() --> establish connection to message broker
@@ -20,25 +21,13 @@ def __init__(self):
20
21
# self.client.subscribe(f"bot/{self.token['token']['unencoded']['bot']}/#")
21
22
# print('connected')
22
23
23
- # def on_message(self, _client, _userdata, msg):
24
- # print('-' * 100)
25
- # # print channel
26
- # print(f'{msg.topic} ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})\n')
27
- # # print message
28
- # print(json.dumps(json.loads(msg.payload), indent=4))
24
+ # def status_connect(self, client, *_args):
25
+ # # Subscribe to specific channel
26
+ # device_info = self.api.get('device')
27
+ # device_id = device_info['id']
29
28
30
- # def on_connect(client, *_args):
31
- # # subscribe to all channels
32
- # client.subscribe(f"bot/{TOKEN['token']['unencoded']['bot']}/#")
33
- # print('connected')
34
-
35
- def status_connect (self , client , * _args ):
36
- # Subscribe to specific channel
37
- device_info = self .api .get ('device' )
38
- device_id = device_info ['id' ]
39
-
40
- client .subscribe ("bot/device_4652/status" )
41
- print ('connected via status_connect()' )
29
+ # client.subscribe("bot/device_4652/status")
30
+ # print('connected via status_connect()')
42
31
43
32
def on_message (self , _client , _userdata , msg ):
44
33
print ('-' * 100 )
@@ -50,10 +39,6 @@ def on_message(self, _client, _userdata, msg):
50
39
print (json .dumps (json .loads (msg .payload ), indent = 4 ))
51
40
52
41
def connect (self ):
53
- print (self .api .token )
54
-
55
- self .api .check_token ()
56
-
57
42
self .client = mqtt .Client ()
58
43
self .client .username_pw_set (
59
44
username = self .token ['token' ]['unencoded' ]['bot' ],
@@ -78,7 +63,7 @@ def disconnect(self):
78
63
79
64
def publish (self , message ):
80
65
if self .client is None :
81
- self .connect ()
66
+ self .connect (self . token )
82
67
83
68
self .client .publish (
84
69
f'bot/{ self .token ["token" ]["unencoded" ]["bot" ]} /from_clients' ,
0 commit comments