89 host = x.group('host') |
89 host = x.group('host') |
90 port = x.group('port') |
90 port = x.group('port') |
91 if port: |
91 if port: |
92 port = int(port) |
92 port = int(port) |
93 else: |
93 else: |
94 port = 3000 |
94 # default port depends on security |
|
95 port = 4000 if IDhash else 3000 |
|
96 |
|
97 if not IDhash and _scheme=="ERPCS": |
|
98 confnodesroot.logger.write_error( |
|
99 f'Invalid URI "{uri}": ERPCS requires PLC ID after "#"\n') |
|
100 return None |
|
101 elif IDhash and _scheme!="ERPCS": |
|
102 confnodesroot.logger.write_error( |
|
103 f'URI "{uri}": Non-encrypted ERPC does not take a PLC ID after "#"\n') |
|
104 return None |
|
105 |
95 except Exception as e: |
106 except Exception as e: |
96 confnodesroot.logger.write_error( |
107 confnodesroot.logger.write_error( |
97 'Malformed URI "%s": %s\n' % (uri, str(e))) |
108 'Malformed URI "%s": %s\n' % (uri, str(e))) |
98 return None |
109 return None |
99 |
110 |
134 |
145 |
135 try: |
146 try: |
136 if IDhash: |
147 if IDhash: |
137 ID = IDhash[0] |
148 ID = IDhash[0] |
138 # load PSK from project |
149 # load PSK from project |
139 secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID + '.secret') |
150 secpath = os.path.join(confnodesroot.ProjectPath, 'psk', ID + '.secret') |
140 if not os.path.exists(secpath): |
151 if not os.path.exists(secpath): |
141 confnodesroot.logger.write_error( |
152 confnodesroot.logger.write_error( |
142 'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath) |
153 'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath) |
143 return None |
154 return None |
144 secret = open(secpath).read().partition(':')[2].rstrip('\n\r') |
155 secret = open(secpath).read().partition(':')[2].rstrip('\n\r').encode() |
145 transport = SSLPSKClientTransport(host, port, (secret, ID)) |
156 transport = SSLPSKClientTransport(host, port, (secret, ID.encode())) |
146 else: |
157 else: |
147 # TODO if serial URI then |
158 # TODO if serial URI then |
148 # transport = erpc.transport.SerialTransport(device, baudrate) |
159 # transport = erpc.transport.SerialTransport(device, baudrate) |
149 |
160 |
150 transport = erpc.transport.TCPTransport(host, port, False) |
161 transport = erpc.transport.TCPTransport(host, port, False) |