关于程序员:用户手册接入设备之连接OPCUA设备

29次阅读

共计 1859 个字符,预计需要花费 5 分钟才能阅读完成。

连贯 OPCUA 设施

Shifu作为 Kubernetes 原生的开源物联网开发框架,集成了 OPC UA 协定。开发者无需思考协定的具体连贯过程,仅需设置协定中的要害参数即可建设连贯,监督或者管制设施运行。

OPC UA 简介

OPC UA (OPC Unified Architecture) 是 OPC 基金会利用在自动化技术的机器对机器网络传输协定。OPC UA 协定反对两种通信协议:二进制通信协议 (opc.tcp://Server) 和 Web 服务通信协定(http:// Server),其中二进制通信协议效率最高,提供较强的互操控性,其应用任意选取的 TCP 通道,能够较容易的进行隧道协定,也能够从透过防火墙开启。

上面将介绍如何应用 Shifu 通过 OPC UA 协定连贯设施。

设置 Shifu 的配置文件

配置设施 IP 信息

编辑 examples/opcuaDeviceShifu/opcua_deploy/opcua_edgedevice.yaml 文件,将 address 批改成设施的 IP 地址:

address: opc.tcp://192.168.14.163:4840/freeopcua/server

配置 OPCUA 连贯设施认证形式

匿名模式

AuthenticationMode 批改成 Anonymous 即可:

AuthenticationMode: Anonymous

用户明码模式

用户明码模式,须要批改 opcua_edgedevice.yaml 文件下AuthenticationModeUsernamePassword:

AuthenticationMode: UserName 
Username: user1  
Password: pwd1

应用 Secret 存储明码

创立 Secret,在 opcua_password 字段填写明码,它会笼罩 opcua_edgedevice.yaml 文件中的明码

kubectl create secret generic deviceshifu-secret --from-literal=opcua_password=your_password -n deviceshifu

证书模式

首先须要为证书以及私钥创立Configmap

$ kubectl create configmap edgedevice-opcua-certificate --from-file=your_certificate_file.pem --from-file=your_private_key.pem -n deviceshifu

批改 opcua_edgedevice.yaml 文件下的AuthenticationModeCertificateFileNamePrivateKeyFileName:

CertificateFileName: cert.pem  
PrivateKeyFileName: key.pem  
AuthenticationMode: Certificate

启动 Shifu 的 OPCUA 组件

启动deviceshifu-opcua:

$ kubectl apply -f examples/opcuaDeviceShifu/opcua_deploy
configmap/opcua-configmap-0.0.1 created
deployment.apps/deviceshifu-opcua-deployment created
service/deviceshifu-opcua created
edgedevice.shifu.edgenesis.io/edgedevice-opcua created

通过 kubectl 命令可查看 deviceShifu 运行状况:

$ kubectl get pods -n deviceshifu
deviceshifu-opcua-deployment-765b77cfcf-f7swc   1/1     Running   0          63s

运行成果

nginx:1.21 载入到 Kubernetes 集群中:

$  kubectl run nginx --image=nginx:1.21 -n deviceshifu

通过 kubectl 查看 nginx 运行状况:

$ kubectl get pods -n deviceshifu  | grep nginx
nginx              1/1     Running   0          3m43s

进入 nginxpod:

$ kubectl exec -it nginx -n deviceshifu -- bash

deviceShifu 发动 HTTP 申请,获取数据:

$ curl http://deviceshifu-opcua/get_value
25

本文由边无际受权公布

正文完
 0