Commit 4f9cd8b4 authored by yogesh.m's avatar yogesh.m

update

parent 26e0a8d7
......@@ -5,7 +5,7 @@ import socket
import threading
from time import sleep
localIP = "2.2.2.5"
localIP = "2.2.2.7"
localPort = 20002
bufferSize = 1024
UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
......@@ -47,7 +47,9 @@ class asyncua_server():
uri = uri
self.idx = await self.server.register_namespace(uri)
await self.server.start()
obj = self.server.nodes.objects.add_object(self.idx, "MyObject")
obj = await self.server.nodes.objects.add_folder(self.idx,"myobj" )
var = await obj.add_variable(self.idx,"myvar",0)
await var.set_writable()
try:
# keep the server running until interrupted
while True:
......@@ -77,4 +79,4 @@ def hash_receive():
def st():
t1=threading.Thread(target=hash_receive)
t1.start()
asyncio.run(asr.start_server("opc.tcp://2.2.2.5:53531/myopc/free","http://klopc.com"))
asyncio.run(asr.start_server("opc.tcp://2.2.2.7:53531/myopc/free","http://klopc.com"))
......@@ -5,7 +5,7 @@ from asyncua_server import st
import asyncio
import threading
localIP = "2.2.2.5"
localIP = "2.2.2.7"
localPort = 20001
......@@ -26,10 +26,10 @@ UDPServerSocket.bind((localIP, localPort))
print("UDP server up and listening")
t1=threading.Thread(target=st,args=())
t1.start()
sleep(10)
sleep(1)
print("here")
opua=opcua_pack()
sock = opua.connect("opc.tcp://2.2.2.5:53531/myopc/free")
sock = opua.connect("opc.tcp://2.2.2.7:53531/myopc/free")
while (True):
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
......
......@@ -141,7 +141,7 @@ class opcua_pack():
DiscoveryProfileUri = binascii.unhexlify("ffffffff")
ArraySize = 0
ServerUri= binascii.unhexlify("ffffffff")
EndpointUrl= "opc.tcp://2.2.2.5:53531/myopc/free"
EndpointUrl= "opc.tcp://2.2.2.7:53531/myopc/free"
EndpointUrllen= len(EndpointUrl.encode()).to_bytes(4,byteorder="little")
SessionName= "Pure Python Client Session1"
SessionNamelen=len(SessionName.encode()).to_bytes(4,byteorder="little")
......@@ -151,48 +151,53 @@ class opcua_pack():
RequestedSessionTimeout= binascii.unhexlify("0000000040774B41")
MaxResponseMessageSize= 0
Message_body = SecureChannelId.to_bytes(4, byteorder='little') + \
Security_Token_Id.to_bytes(4, byteorder='little') + \
Security_Sequence_Number.to_bytes(4, byteorder='little') + \
Security_RequestId.to_bytes(4, byteorder='little') + \
NodeId_EncodingMask.to_bytes(1, byteorder='little') + \
NodeId_Namespace_Index.to_bytes(1, byteorder='little') + \
NodeId_Identifier_Numeric.to_bytes(2, byteorder='little') + \
auth_EncodingMask.to_bytes(1, byteorder='little') + \
Identifier_Numeric.to_bytes(1, byteorder='little') + \
Timestamp + \
RequestHandle.to_bytes(4, byteorder='little') + \
Return_Diagnostics + \
AuditEntryId + \
TimeoutHint.to_bytes(4, byteorder='little') + \
additional_header_enc_mask + \
ah_Identifier_Numeric.to_bytes(1, byteorder="little") + \
ah_EncodingMask2 + \
ApplicationUrilen + \
ApplicationUri.encode() + \
ProductUrilen + \
ProductUri.encode() + \
Application_name + \
Textlen + \
Text.encode() + \
ApplicationType + \
GatewayServerUri + \
DiscoveryProfileUri + \
ArraySize.to_bytes(4, byteorder="little") + \
ServerUri + \
EndpointUrllen + \
EndpointUrl.encode() + \
SessionNamelen + \
SessionName.encode() + \
client_noncelen + \
client_nonce + \
ClientCertificate + \
RequestedSessionTimeout + \
MaxResponseMessageSize.to_bytes(4, byteorder="little")
Message_Size=int(8+len(Message_body)).to_bytes(4,byteorder="little")
session= MSG_MSG.encode()+\
chunk_type.encode() +\
Message_Size.to_bytes(4,byteorder='little')+ \
SecureChannelId.to_bytes(4,byteorder='little')+ \
Security_Token_Id.to_bytes(4, byteorder='little')+ \
Security_Sequence_Number.to_bytes(4, byteorder='little')+ \
Security_RequestId.to_bytes(4, byteorder='little')+\
NodeId_EncodingMask.to_bytes(1, byteorder='little')+\
NodeId_Namespace_Index.to_bytes(1, byteorder='little')+\
NodeId_Identifier_Numeric.to_bytes(2, byteorder='little')+\
auth_EncodingMask.to_bytes(1, byteorder='little') +\
Identifier_Numeric.to_bytes(1, byteorder='little')+ \
Timestamp+ \
RequestHandle.to_bytes(4, byteorder='little')+\
Return_Diagnostics+\
AuditEntryId+\
TimeoutHint.to_bytes(4, byteorder='little')+\
additional_header_enc_mask+ \
ah_Identifier_Numeric.to_bytes(1,byteorder="little")+\
ah_EncodingMask2+ \
ApplicationUrilen+\
ApplicationUri.encode()+\
ProductUrilen+\
ProductUri.encode()+\
Application_name+\
Textlen+\
Text.encode()+\
ApplicationType+\
GatewayServerUri+\
DiscoveryProfileUri+\
ArraySize.to_bytes(4,byteorder="little")+\
ServerUri+ \
EndpointUrllen+\
EndpointUrl.encode()+\
SessionNamelen+\
SessionName.encode()+\
client_noncelen+\
client_nonce+\
ClientCertificate+\
RequestedSessionTimeout+ \
MaxResponseMessageSize.to_bytes(4,byteorder="little")
Message_Size+ \
Message_body
return session
def start_session(self,secure_id,token_id,identifier_string):
MSG_MSG = "MSG"
chunk_type = "F"
......@@ -421,7 +426,7 @@ class opcua_pack():
return session
def connect(self,address):
server_address = ('2.2.2.5', 53531)
server_address = ('2.2.2.7', 53531)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(server_address)
message = self.helf(address)
......@@ -431,7 +436,8 @@ class opcua_pack():
data = sock.recv(10249)
self.SecureChannelId = int(data[-24:-23].hex(), 16)
self.TokenId = int(data[-20:-19].hex(), 16)
sock.sendall(self.create_session(self.SecureChannelId, self.TokenId))
message=self.create_session(self.SecureChannelId, self.TokenId)
sock.sendall(message)
count = 0
while True:
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment