添加SLCP102打包逻辑;

This commit is contained in:
何 泽隆
2024-11-16 18:57:23 +08:00
parent 272b7c68b2
commit 628ce8bf27
4 changed files with 91 additions and 6 deletions

45
resource/Untitled-1.py Normal file
View File

@@ -0,0 +1,45 @@
# %%
from paho.mqtt import client as mqtt_client
broker = '123.249.75.235'
port = 1883
topic = "python/mqtt"
client_id = f'python-mqtt-{random.randint(0, 1000)}'
username = 'TTE0101TC2311000003'
password = 'qh10579lcb7au8o2'
# %%
import random
from paho.mqtt import client as mqtt_client
broker = '123.249.75.235'
port = 1883
topic = "python/mqtt"
client_id = f'python-mqtt-{random.randint(0, 1000)}'
username = 'TTE0101TC2311000003'
password = 'qh10579lcb7au8o2'
# %%
def connect_mqtt():
def on_connect(client, userdata, flags, rc):
# For paho-mqtt 2.0.0, you need to add the properties parameter.
# def on_connect(client, userdata, flags, rc, properties):
if rc == 0:
print("Connected to MQTT Broker!")
else:
print("Failed to connect, return code %d\n", rc)
# Set Connecting Client ID
client = mqtt_client.Client(client_id)
# For paho-mqtt 2.0.0, you need to set callback_api_version.
# client = mqtt_client.Client(client_id=client_id, callback_api_version=mqtt_client.CallbackAPIVersion.VERSION2)
# client.username_pw_set(username, password)
client.on_connect = on_connect
client.connect(broker, port)
return client