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

连贯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

本文由边无际受权公布