When i'm trying to publish some messages to a broker i got the following error:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.8/site-packages/opcua/client/client.py", line 66, in run
self.client.open_secure_channel(renew=True)
File "/usr/local/lib/python3.8/site-packages/opcua/client/client.py", line 325, in open_secure_channel
result = self.uaclient.open_secure_channel(params)
File "/usr/local/lib/python3.8/site-packages/opcua/client/ua_client.py", line 265, in open_secure_channel
return self._uasocket.open_secure_channel(params)
File "/usr/local/lib/python3.8/site-packages/opcua/client/ua_client.py", line 197, in open_secure_channel
future = self._send_request(request, message_type=ua.MessageType.SecureOpen)
File "/usr/local/lib/python3.8/site-packages/opcua/client/ua_client.py", line 72, in _send_request
self._socket.write(msg)
File "/usr/local/lib/python3.8/site-packages/opcua/common/utils.py", line 118, in write
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
i'm using network loop after client connection, and i tried to handle the error but, it deosn't work i have always the same issue, my fonction is called many times per second, each time when i recieve a data change notification from the server. Can someone help please? Here the following code that causes the error:
def clientPub(self,top,msg):
try:
cl=self.client
if(self.connectionFlag !=1):
cl.connect(self.broker,1883)
cl.loop_start()
cl.publish(top,msg,2)
except IOError as e:
if e.errno == errno.EPIPE:
print("Trying again to publish the message ...")
cl.publish(top,msg,2)
the above function is called by this one for every notification from the server:
def datachange_notification(self, node, val, data):
print("data recieved :",data.monitored_item.Value.SourceTimestamp,val,machine_number+".G3_"+node.nodeid.Identifier[3:])
valuesDict={"name":machine_number+".G3_"+node.nodeid.Identifier[3:],"datapoint":[[str(data.monitored_item.Value.SourceTimestamp),val,3]],"attributes":{"machine-type":"opcua"}}
finalvalue={"messageId":str(round(time.time()*1000)),"body":valuesDict}
sentval=json.dumps(finalvalue)
self.clientPub(self.topic,sentval)
waiting for you reply, Thank you.