Skip to content

Commit 04ec308

Browse files
authored
Update __init__.py
1 parent 694225f commit 04ec308

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

__init__.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ def on_connect(client, userdata, flags, rc):
1313
print("MQTT Connected" + str(rc))
1414

1515
class MQTTThread (threading.Thread):
16+
17+
def __init__(self,server,port,username,password):
18+
threading.Thread.__init__(self)
19+
self.server = server
20+
self.port = port
21+
self.username = username
22+
self.password = password
23+
1624
client = None
1725
def run(self):
1826
self.client = mqtt.Client()
@@ -63,7 +71,28 @@ def execute(self):
6371

6472
@cbpi.initalizer(order=0)
6573
def initMQTT(app):
66-
app.cache["mqtt"] = MQTTThread()
74+
75+
server = app.get_config_parameter("MQTT_SERVER",None)
76+
if server is None:
77+
server = "localhost"
78+
cbpi.add_config_parameter("MQTT_SERVER", "localhost", "text", "MQTT Server")
79+
80+
port = app.get_config_parameter("MQTT_PORT", None)
81+
if port is None:
82+
port = "1883"
83+
cbpi.add_config_parameter("MQTT_PORT", "1883", "text", "MQTT Sever Port")
84+
85+
username = app.get_config_parameter("MQTT_USERNAME", None)
86+
if username is None:
87+
username = "username"
88+
cbpi.add_config_parameter("MQTT_USERNAME", "username", "text", "MQTT username")
89+
90+
password = app.get_config_parameter("MQTT_PASSWORD", None)
91+
if password is None:
92+
password = "password"
93+
cbpi.add_config_parameter("MQTT_PASSWORD", "password", "text", "MQTT password")
94+
95+
app.cache["mqtt"] = MQTTThread(server,port,username, password)
6796
app.cache["mqtt"].start()
6897
def mqtt_reader(api):
6998
while True:

0 commit comments

Comments
 (0)