Skip to content

Commit

Permalink
refactor: lint python
Browse files Browse the repository at this point in the history
  • Loading branch information
GoetzGoerisch committed Sep 26, 2024
1 parent 9609542 commit 5f3d28c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
36 changes: 19 additions & 17 deletions TestEnvironment/pub_client_1.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#simulator device 1 for mqtt message publishing
import paho.mqtt.client as paho
import time
# simulator device 1 for mqtt message publishing
import random
import time

import paho.mqtt.client as paho

# brokersettings
BROKER = "localhost" # mqtt broker url + port exposed to local
PORT = 1883

#brokersettings
broker="localhost" # mqtt broker url + port exposed to local
port=1883

def on_publish(client,userdata,result):
def on_publish(client, userdata, result):
print("Device 1 : Data published.")
pass

client= paho.Client(client_id="admin")

client = paho.Client(client_id="admin")
client.on_publish = on_publish
client.connect(host=broker,port=port)
client.connect(host=BROKER, port=PORT)
for i in range(20):
d=random.randint(1,5)
#telemetry to send
message="Device 1 : Data " + str(i)
d = random.randint(1, 5)

# telemetry to send
MESSAGE = "Device 1 : Data " + str(i)
time.sleep(d)


#publish message
ret= client.publish(topic="data",payload=message)
# publish message
ret = client.publish(topic="data", payload=MESSAGE)

print("Stopped...")
print("Stopped...")
29 changes: 16 additions & 13 deletions TestEnvironment/sub_client_1.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import paho.mqtt.client as mqtt

#broker settings
broker="localhost" # mqtt broker url + port exposed to local
port=1883
# broker settings
BROKER = "localhost" # mqtt broker url + port exposed to local
PORT = 1883

# time for Subscriber to live
TIMELIVE = 60

#time for Subscriber to live
timelive=60

def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic="data")
print("Connected with result code " + str(rc))
client.subscribe(topic="data")


def on_message(client, userdata, msg):
print(msg.payload.decode())

client = mqtt.Client()
client.connect(host=broker,port=port,keepalive=timelive)
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()


sub_client = mqtt.Client()
sub_client.connect(host=BROKER, port=PORT, keepalive=TIMELIVE)
sub_client.on_connect = on_connect
sub_client.on_message = on_message
sub_client.loop_forever()
29 changes: 16 additions & 13 deletions TestEnvironment/sub_client_2.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import paho.mqtt.client as mqtt

#broker settings
broker="localhost" # mqtt broker url + port exposed to local
port=1883
# broker settings
BROKER = "localhost" # mqtt broker url + port exposed to local
PORT = 1883

# time for Subscriber to live
TIMELIVE = 60

#time for Subscriber to live
timelive=60

def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic="data")
print("Connected with result code " + str(rc))
client.subscribe(topic="data")


def on_message(client, userdata, msg):
print(msg.payload.decode())

client = mqtt.Client()
client.connect(host=broker,port=port,keepalive=timelive)
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()


sub_client = mqtt.Client()
sub_client.connect(host=BROKER, port=PORT, keepalive=TIMELIVE)
sub_client.on_connect = on_connect
sub_client.on_message = on_message
sub_client.loop_forever()

0 comments on commit 5f3d28c

Please sign in to comment.