Node-red Client ,OPCUA Invalid Endpoint 错误

接触NODE-RED . OPCUA 看了B站视频操作了几个星期,都没成功,终于今天成功了,每次均在Invalid Endpoint此处错误

假期无事,打开调试C:\Users\xxx.node-red\node_modules\node-red-contrib-opcua\opcua

总是卡在这一步错误

        set_node_status_to("invalid certificate");
        verbose_warn("证书错误 ");
        let msg = {};
        msg.error = {};
        msg.error.message = "Certificate error: " + error1.message;
        msg.error.source = this;
        node.error("Certificate error", msg);
      }
      node.debug(chalk.yellow("Trusted folder:      ") + chalk.cyan(node.client.clientCertificateManager.trustedFolder));
      node.debug(chalk.yellow("Rejected folder:     ") + chalk.cyan(node.client.clientCertificateManager.rejectedFolder));
      node.debug(chalk.yellow("Crl folder:          ") + chalk.cyan(node.client.clientCertificateManager.crlFolder));
      node.debug(chalk.yellow("Issuers Cert folder: ") + chalk.cyan(node.client.clientCertificateManager.issuersCertFolder));
      node.debug(chalk.yellow("Issuers Crl folder:  ") + chalk.cyan(node.client.clientCertificateManager.issuersCrlFolder));

      try {
        verbose_log(chalk.green("2) Connecting using endpoint: ") + chalk.cyan(opcuaEndpoint.endpoint) +
          chalk.green(" securityMode: ") + chalk.cyan(connectionOption.securityMode) +
          chalk.green(" securityPolicy: ") + chalk.cyan(connectionOption.securityPolicy));
          verbose_warn("正式开始连接 ");
        await node.client.connect(opcuaEndpoint.endpoint);
        //总是在这一步报错,怀疑Client.CONNECT API错误,要不就是OPCUAEndPoint的选项与这个函数不匹配

      } catch (err) {
        verbose_warn("Case A: Endpoint does not contain, 1==None 2==Sign 3==Sign&Encrypt, using securityMode: " + stringify(connectionOption.securityMode));
        verbose_warn("        using securityPolicy: " + stringify(connectionOption.securityPolicy));
        verbose_warn("Case B: UserName & password does not match to server (needed by Sign or SignAndEncrypt), check username: " + userIdentity.userName + " and password: " + userIdentity.password);
        verbose_warn("Case C: With Sign you cannot use SecurityPolicy None!!");
        // verbose_error("Invalid endpoint parameters: ", err);
        node_error("Wrong endpoint parameters: " + JSON.stringify(opcuaEndpoint.toString()));
        set_node_status_to("invalid endpoint");
        let msg = {};

删除了所有NODE-RED,升级了NODEJS==>22.9版本都没用
删除了NODE-RED-CONTRIB-OPCUA 所有.node-red下内容,都没用
查网上资料说可能是证书加密错误。

在这里插入图片描述
最终把这两个文件夹都删除,问题解决了,sh

4 Oct 20:48:53 - [info] Node-RED version: v4.0.3
4 Oct 20:48:53 - [info] Node.js  version: v22.9.0
4 Oct 20:48:53 - [info] Windows_NT 10.0.17763 x64 LE
4 Oct 20:48:53 - [info] Loading palette nodes
+-------------------------------------------------------------------------------------+
| Warning:                                                                            |
| node-opcua-client-crawler module has been deprecated and is not maintained anymore. |
| Please use '@sterfive/crawler' instead.                                             |
| '@sterfive/crawler' is available to the NodeOPCUA Subscription members              |
+-------------------------------------------------------------------------------------+
4 Oct 20:48:55 - [info] Settings file  : C:\Users\xxx\.node-red\settings.js
4 Oct 20:48:55 - [info] Context store  : 'default' [module=memory]
4 Oct 20:48:55 - [info] User directory : \Users\xxx\.node-red
4 Oct 20:48:55 - [warn] Projects disabled : editorTheme.projects.enabled=false
4 Oct 20:48:55 - [info] Flows file     : \Users\xxx\.node-red\flows.json
4 Oct 20:48:55 - [info] Server now running at http://127.0.0.1:1880/
4 Oct 20:48:55 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

4 Oct 20:48:55 - [info] Starting flows
4 Oct 20:48:55 - [error] [OpcUa-Server:ecdcb38488031f5b] File: users.json not found! You can inject users to server or add file to current folder: C:\Users\xxx\.node-red\node_modules\node-red-contrib-opcua\opcua
4 Oct 20:48:55 - [warn] [OpcUa-Client:5c6b0222f76160e5] userIdentity is ANONYMOUS
4 Oct 20:48:55 - [info] Started flows
4 Oct 20:48:55 - [warn] [OpcUa-Client:5c6b0222f76160e5] Case A: Endpoint does not contain, 1==None 2==Sign 3==Sign&Encrypt, using securityMode: [1]
4 Oct 20:48:55 - [warn] [OpcUa-Client:5c6b0222f76160e5]         using securityPolicy: ["None"]
4 Oct 20:48:55 - [warn] [OpcUa-Client:5c6b0222f76160e5] Case B: UserName & password does not match to server (needed by Sign or SignAndEncrypt), check username: undefined and password: undefined
4 Oct 20:48:55 - [warn] [OpcUa-Client:5c6b0222f76160e5] Case C: With Sign you cannot use SecurityPolicy None!!
4 Oct 20:48:55 - [error] [OpcUa-Client:5c6b0222f76160e5] Client node error on 新加:  error: ["Wrong endpoint parameters: {\"id\":\"678c6a415680e2af\",\"type\":\"OpcUa-Endpoint\",\"_closeCallbacks\":[],\"_inputCallback\":null,\"_inputCallbacks\":null,\"_expectedDoneCount\":0,\"wires\":[],\"_wireCount\":0,\"credentials\":{},\"endpoint\":\"opc.tcp://localhost:53880/UA/Sim\",\"securityPolicy\":\"None\",\"securityMode\":\"None\",\"login\":false,\"none\":true,\"usercert\":false,\"userCertificate\":\"\",\"userPrivatekey\":\"\",\"user\":null,\"password\":null}"]
4 Oct 20:48:55 - [error] [OpcUa-Client:5c6b0222f76160e5] Invalid endpoint
4 Oct 20:53:47 - [info] Stopping flows
4 Oct 20:53:47 - [warn] [OpcUa-Client:5c6b0222f76160e5] closing opcua client true userIdentity {"type":0}
4 Oct 20:53:47 - [info] Stopped flows

增加代码执行中文调试

4 Oct 21:17:29 - [info] Starting flows
4 Oct 21:17:29 - [error] [OpcUa-Server:ecdcb38488031f5b] File: users.json not found! You can inject users to server or add file to current folder: C:\Users\adv\.node-red\node_modules\node-red-contrib-opcua\opcua
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] userIdentity is ANONYMOUS
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] 连接中:
4 Oct 21:17:29 - [info] Started flows
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] 测试证书初始化:
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] 正式开始连接
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] Case A: Endpoint does not contain, 1==None 2==Sign 3==Sign&Encrypt, using securityMode: [1]
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5]         using securityPolicy: ["None"]
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] Case B: UserName & password does not match to server (needed by Sign or SignAndEncrypt), check username: undefined and password: undefined
4 Oct 21:17:29 - [warn] [OpcUa-Client:5c6b0222f76160e5] Case C: With Sign you cannot use SecurityPolicy None!!
4 Oct 21:17:29 - [error] [OpcUa-Client:5c6b0222f76160e5] Client node error on 新加:  error: ["Wrong endpoint parameters: \"opc.tcp://localhost:53880/UA/Sim\""]
4 Oct 21:17:29 - [error] [OpcUa-Client:5c6b0222f76160e5] Invalid endpoint

删除文件后

4 Oct 21:46:10 - [info] Starting flows
4 Oct 21:46:10 - [error] [OpcUa-Server:ecdcb38488031f5b] File: users.json not found! You can inject users to server or add file to current folder: C:\Users\adv\.node-red\node_modules\node-red-contrib-opcua\opcua
4 Oct 21:46:10 - [warn] [OpcUa-Client:5c6b0222f76160e5] userIdentity is ANONYMOUS
4 Oct 21:46:10 - [warn] [OpcUa-Client:5c6b0222f76160e5] 连接中:
4 Oct 21:46:10 - [info] Started flows
4 Oct 21:46:10 - [warn] [OpcUa-Client:5c6b0222f76160e5] 测试证书初始化:
4 Oct 21:46:10 - [warn] [OpcUa-Client:5c6b0222f76160e5] 正式开始连接
13:46:10.269Z :*client_base_impl*              :586   Creating default certificate ... please wait
4 Oct 21:46:10 - [error] [OpcUa-Client:5c6b0222f76160e5] reconnect
4 Oct 21:46:15 - [warn] [OpcUa-Client:5c6b0222f76160e5] Create session with userIdentity node.client false userIdentity {"type":0}

多了这一步骤
13:46:10.269Z :client_base_impl :586 Creating default certificate … please wait
代码会自动生产证书

我认为可能之前几次安装的文件与加密文件不一致,没有更新一致导致的

以下图片为成功后的
在这里插入图片描述

### 配置Node-RED实现崩溃后自动重启 对于希望确保Node-RED实例在发生意外终止时能够自动重启的情况,可以利用PM2这一强大的进程管理工具来达成目标。当遇到`Invalid or unexpected token`这样的错误信息时,调整自启动命令至确切的Node-RED入口脚本位置有助于解决问题[^1]。 具体而言,在Windows环境下,应将启动命令更改为指向实际部署于本地系统的Node-RED JavaScript文件的确切路径: ```bash pm2 start D:\nodev20\node-global\node_modules\node-red\red.js ``` 此操作不仅解决了上述提到的语法异常问题,还实现了对Node-RED应用的有效监控与自动化恢复机制。一旦应用程序因任何原因停止响应或崩溃,PM2将会立即检测到并尝试重新启动服务,从而保持其持续在线状态。 另外,在Linux发行版如Ubuntu 20.04 LTS中,除了基本的安装流程外,为了使Node-RED能够在后台稳定运行并且具备自我修复能力,同样推荐采用PM2作为守护程序解决方案[^2]。完成Node-RED的基础配置之后(比如开放必要的网络端口),执行如下命令可将其加入开机自启项列表,并开启自动重试功能: ```bash sudo npm install pm2@latest -g pm2 start /usr/lib/node_modules/node-red/red.js --name "nodered" pm2 startup systemd pm2 save ``` 以上步骤确保即使遭遇非计划性的中断事件,Node-RED也能迅速恢复正常运作模式,保障业务连续性和用户体验不受影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值