连接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文件下AuthenticationMode、Username、Password:
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文件下的AuthenticationMode、CertificateFileName、PrivateKeyFileName:
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
进入nginx的pod:
$ kubectl exec -it nginx -n deviceshifu -- bash
向deviceShifu发起HTTP请求,获取数据:
$ curl http://deviceshifu-opcua/get_value
25
本文由边无际授权发布