Skip to content

Commit c5a9a7e

Browse files
authored
Merge pull request #7 from electrocoder/test
Test
2 parents 2bb8581 + 4e0c8ac commit c5a9a7e

File tree

9 files changed

+47
-44
lines changed

9 files changed

+47
-44
lines changed

.idea/MQTTClient.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MQTTClient.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Source Code: https://github.com/electrocoder/MQTTClient
66
7-
MQTT Examples: https://github.com/mesebilisim/mqtt-examples
7+
MQTT Examples: https://github.com/meseiot/iot-examples
88
99
Date: 12.11.2022
1010
@@ -251,17 +251,7 @@ def subscribe_list(self, name):
251251
self.entry_subscribe_topic_text.set(choice)
252252

253253
def button_disconnect(self):
254-
print("button_disconnect")
255-
if self.subscriber.connect_stop():
256-
self.connect_status_text.set("Disconnect")
257-
self.button_connect["state"] = tk.NORMAL
258-
self.button_connect["text"] = "Connect"
259-
self.button_disconnect["state"] = tk.DISABLED
260-
self.button_subscribe_topic[
261-
"state"] = tk.DISABLED
262-
self.button_publish_topic[
263-
"state"] = tk.DISABLED
264-
self.button_add_subscribe_topic["state"] = tk.DISABLED
254+
self.subscriber.mqtt_disconnect()
265255

266256
def button_subscribe(self):
267257
print("button_subscribe")

about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Source Code: https://github.com/electrocoder/MQTTClient
66
7-
MQTT Examples: https://github.com/mesebilisim/mqtt-examples
7+
MQTT Examples: https://github.com/meseiot/iot-examples
88
99
Date: 12.11.2022
1010

config_file.ini

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[iothook]
2+
broker = iothook.com
3+
port = 1883
4+
username = iothookpublic
5+
password = iothookpublic
6+
topics = #,timestamp,test,testtopic,aaa,$SYS,
7+
18
[hivemq]
29
broker = broker.hivemq.com
310
port = 1883
@@ -31,7 +38,7 @@ broker = test.mosquitto.org
3138
port = 1883
3239
username =
3340
password =
34-
topics = #,timestamp,
41+
topics = #,timestamp,test,
3542

3643
[flespi]
3744
broker = mqtt.flespi.io
@@ -54,13 +61,6 @@ username =
5461
password =
5562
topics = #,timestamp,
5663

57-
[iothook]
58-
broker = iothook.com
59-
port = 1883
60-
username = iothookpublic
61-
password = iothookpublic
62-
topics = #,timestamp,test,testtopic,aaa,$SYS,
63-
6464
[ele]
6565
broker = iothook.com
6666
port = 1883

config_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Source Code: https://github.com/electrocoder/MQTTClient
66
7-
MQTT Examples: https://github.com/mesebilisim/mqtt-examples
7+
MQTT Examples: https://github.com/meseiot/iot-examples
88
99
Date: 12.11.2022
1010

new_connect.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Source Code: https://github.com/electrocoder/MQTTClient
66
7-
MQTT Examples: https://github.com/mesebilisim/mqtt-examples
7+
MQTT Examples: https://github.com/meseiot/iot-examples
88
99
Date: 12.11.2022
1010
@@ -22,46 +22,43 @@ def __init__(self, main_window, font_size):
2222

2323
self.main_window = main_window
2424
self.title("MQTT Client New Connect")
25-
self.geometry("300x300")
25+
self.geometry("300x350")
2626

27-
ipadding = {'ipadx': 10, 'ipady': 10}
27+
ipadding = {'ipadx': 5, 'ipady': 5}
2828

2929
frame = Frame(self, padx=5, pady=5)
3030
frame.grid(row=0, column=1)
3131

32-
Label(frame, text='Name', padx=5, pady=5).pack()
33-
Label(frame, text='Broker', padx=5, pady=5).pack()
34-
Label(frame, text='Port', padx=5, pady=5).pack()
35-
Label(frame, text='Username', padx=5, pady=5).pack()
36-
Label(frame, text='Password', padx=5, pady=5).pack()
32+
Label(frame, text='Name').pack(**ipadding)
33+
Label(frame, text='Broker').pack(**ipadding)
34+
Label(frame, text='Port').pack(**ipadding)
35+
Label(frame, text='Username').pack(**ipadding)
36+
Label(frame, text='Password').pack(**ipadding)
3737

3838
frame2 = Frame(self, padx=5, pady=5)
3939
frame2.grid(row=0, column=2)
4040

4141
self.entry_name_text = StringVar(self)
4242
self.entry_name = Entry(frame2, font=font_size,
43-
textvariable=self.entry_name_text).pack(padx=5,
44-
pady=5)
43+
textvariable=self.entry_name_text).pack(**ipadding)
4544

4645
self.entry_broker_text = StringVar(self)
4746
self.entry_broker = Entry(frame2, font=font_size,
48-
textvariable=self.entry_broker_text).pack(
49-
padx=5, pady=5)
47+
textvariable=self.entry_broker_text).pack(**ipadding)
5048

5149
self.entry_port_text = StringVar(self)
5250
self.entry_port = Entry(frame2, font=font_size,
53-
textvariable=self.entry_port_text).pack(padx=5,
54-
pady=5)
51+
textvariable=self.entry_port_text).pack(**ipadding)
5552

5653
self.entry_username_text = StringVar(self)
5754
self.entry_username = Entry(frame2, font=font_size,
5855
textvariable=self.entry_username_text).pack(
59-
padx=5, pady=5)
56+
**ipadding)
6057

6158
self.entry_password_text = StringVar(self)
6259
self.entry_password = Entry(frame2, font=font_size,
6360
textvariable=self.entry_password_text).pack(
64-
padx=5, pady=5)
61+
**ipadding)
6562

6663
self.button_cancel = Button(self, text="Cancel",
6764
font=font_size,

new_topic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Source Code: https://github.com/electrocoder/MQTTClient
66
7-
MQTT Examples: https://github.com/mesebilisim/mqtt-examples
7+
MQTT Examples: https://github.com/meseiot/iot-examples
88
99
Date: 26.11.2022
1010

subscriber.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
55
Source Code: https://github.com/electrocoder/MQTTClient
66
7-
MQTT Examples: https://github.com/mesebilisim/mqtt-examples
7+
MQTT Examples: https://github.com/meseiot/iot-examples
88
99
Date: 12.11.2022
1010
1111
File: This script is MQTT Subscriber Client
1212
"""
13-
13+
import secrets
1414
import tkinter as tk
1515
from datetime import datetime
16+
from random import randint
17+
1618
import paho.mqtt.client as mqtt
1719

1820

@@ -33,6 +35,7 @@ def on_connect(self, client, userdata, flags, rc):
3335
self.on_message_count, self.publish_message_count))
3436

3537
def on_disconnect(self, client, userdata, rc):
38+
print("on_disconnect")
3639
self.main_window.connect_status_text.set(
3740
"Disconnect | Message: %s | Publish: %s" % (
3841
self.on_message_count, self.publish_message_count))
@@ -69,7 +72,7 @@ def on_message(self, client, userdata, msg):
6972
self.on_message_count, self.publish_message_count))
7073

7174
def connect_start(self, name, broker, port, username, password):
72-
self.client = mqtt.Client()
75+
self.client = mqtt.Client("iothook_%s" % secrets.token_hex(11))
7376
self.client.on_disconnect = self.on_disconnect
7477
self.client.on_message = self.on_message
7578
self.client.on_connect = self.on_connect
@@ -89,3 +92,16 @@ def subscribe_start(self, topic):
8992
def publish_start(self, topic, msg):
9093
self.client.publish(topic, msg)
9194
self.publish_message_count += 1
95+
96+
def mqtt_disconnect(self):
97+
if self.connect_stop():
98+
self.main_window.connect_status_text.set("Disconnect")
99+
self.main_window.button_connect["state"] = tk.NORMAL
100+
self.main_window.button_connect["text"] = "Connect"
101+
self.main_window.button_disconnect["state"] = tk.DISABLED
102+
self.main_window.button_subscribe_topic[
103+
"state"] = tk.DISABLED
104+
self.main_window.button_publish_topic[
105+
"state"] = tk.DISABLED
106+
self.main_window.button_add_subscribe_topic["state"] = tk.DISABLED
107+

0 commit comments

Comments
 (0)