You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
850 B
37 lines
850 B
import paho.mqtt.client as mqtt
|
|
from decouple import config
|
|
|
|
|
|
#id divice
|
|
id_divice = "eui-60c5a8fffe79898c"
|
|
|
|
#mqtt credentials
|
|
user = config('USER_MQTT')
|
|
password = config('KEY')
|
|
|
|
#public address
|
|
public_tls_address = config('PUBLIC_ADDRESS')
|
|
public_tls_address_port = config('PUBLIC_TLS_ADDRESS_PORT')
|
|
|
|
topics = 'v3/{application id}@{tenant id}/devices/{device id}/up'
|
|
|
|
def on_connect(client,userdata,flag,rc):
|
|
print("Connected with resulte code: "+str(rc))
|
|
client.suscribe(topics)
|
|
|
|
def on_message(client,userdata, msg):
|
|
print(msg.topic+" "+str(msg.payload))
|
|
|
|
def stop(client):
|
|
client.disconnect()
|
|
print("\nExit")
|
|
|
|
client = mqtt.client()
|
|
client.on_connect = on_connect
|
|
client.on_message = on_message
|
|
|
|
|
|
|
|
if __name__ == '__main__' :
|
|
client.connect(public_tls_address,public_tls_address_port,60)
|
|
client.loop_forever()
|