Error while send data from Paho

Hi ,
I setup openremote on IDE. I have succesfully tested data communicating from MQTT Exoplorer to openremote. Here I use unsecure communication with 1883 poprt(Mqtt Explorer TLS =OFF, SSL =OFF).

Now I tried to send data from Pythone code Paho to openremote but it give some error.

Code:
import paho.mqtt.client as mqtt
import time
import certifi
import ssl
import json
import requests
from requests import *

def on_connect(client, userdata, flags, rc):
if rc == 0:
print(“Connected to broker”)
global Connected # Use global variable
Connected = True # Signal connection
else:
print(“Connection failed”)

def on_publish(client, userdata, result):
print(f’Data published. Data: {attribute_value}')
pass

def on_message(client, userdata, message):
msg = json.loads(message.payload.decode(“utf-8”))
id = msg[“attributeState”][“ref”][“id”]
att_name = msg[“attributeState”][“ref”][“name”]
att_value = msg[“attributeState”][“value”]
print(f’Message received. Asset ID: {id}. Attribute name: {att_name}. Attribute value: {att_value}')

Connected = False
username = “master:mqttuser”
secret = “Q3XdkI47UzePlgQGyIxGGuSsbHfni26s”
host = “192.168.11.217”
port = 1883
clientID = ‘client12345’
assetID = ‘585TvXai66JeXi07w1LZVK’
attributeWr = ‘writeAttribute’
attributeRd = ‘subscribeAttribute’

clientMQTT = mqtt.Client(clientID)
clientMQTT.username_pw_set(username, password=secret)

the key steps here

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

if you do not want to check the cert hostname, skip it

context.check_hostname = False
clientMQTT.tls_set_context(context)
response = requests.get(“http://192.168.11.217:1883”, verify=False)

clientMQTT.on_connect = on_connect
clientMQTT.on_publish = on_publish
clientMQTT.on_message = on_message
clientMQTT.connect(host, port=port)
clientMQTT.loop_start()

while Connected != True:
time.sleep(10)

attribute_value = 10
i = 0
for i in range(attribute_value):
clientMQTT.publish(f"master/{clientID}/writeattributevalue/{attributeWr}/{assetID}", i)
time.sleep(1)

time.sleep(5)
clientMQTT.disconnect()
clientMQTT.loop_stop()

we have tried to off/disable TLS, SSL but we have tried that method is correct or not we have doubt.
Connection established but data not send

Shresth

Best to use markup code blocks when pasting code…

Maybe you would see why data doesn’t get to the OpenRemote broker if you have no error handling on your publish call or look at the OpenRemote logs?

Obvious thing is to make sure the data you are publishing is compatible with the attribute type you are writing to.