当前位置:网站首页>Run opcua protocol demo on raspberry pie 4B to access kubeedge
Run opcua protocol demo on raspberry pie 4B to access kubeedge
2022-06-27 05:55:00 【Brother Aaron】
One 、KubeEdge brief introduction
KubeEdge It is a good edge cloud platform . It can support the access and management of edge devices .
KubeEdge Consists of the following components :
- Edged: Agents that run and manage containerized applications on edge nodes .
- EdgeHub: Web Socket client , Responsible for working with Cloud Service Interact for edge calculation ( for example KubeEdge In architecture Edge Controller). This includes synchronizing cloud side resource updates to the edge , And report the status changes of edge hosts and devices to the cloud .
- CloudHub: Web Socket server , Responsible for caching information in the cloud 、 Monitoring changes , And to EdgeHub End send message .
- EdgeController: kubernetes Expansion controller , Used to manage edge nodes and nodes pod Metadata , So that the data can be located to the corresponding edge node .
- EventBus: With a MQTT The server (mosquitto) interactive MQTT client , Provide publish and subscribe capabilities for other components .
- DeviceTwin: Responsible for storing device state and synchronizing device state to cloud . It also provides query interfaces for applications .
- MetaManager: Edged End sum Edgehub Message processors between terminals . It is also responsible for storing metadata into lightweight databases (SQLite) Or from a lightweight database (SQLite) Retrieve metadata .
The principle of equipment management is shown in the figure below :
https://kubeedge.io/zh/docs/kubeedge_zh/

Two 、 Data storage of cloud devices
model Is the device model .
Device Model
apiVersion: devices.kubeedge.io/v1alpha2
kind: DeviceModel
metadata:
name: opcua-model
namespace: default
spec:
properties:
- name: temperature
description: temperature in degree celsius
type:
int:
accessMode: ReadOnly
defaultValue: 1
- name: switcher
description: turn on or turn off
type:
boolean:
accessMode: ReadWrite
instance This is the equipment instance , It refers to a specific equipment .
Device Instance
apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
name: lamp-opcua
labels:
model: opcua-model
spec:
deviceModelRef:
name: opcua-model
protocol:
opcua:
url: opc.tcp://192.168.137.100:4840/
userName: testuser
password: ""
password: /ca/pass
certificate: /ca/clientcert.pem
privateKey: /ca/clientkey.pem
securityMode: None
securityPolicy: ""
common:
customizedValues:
remoteCertificate: /ca/servercert.pem
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: ''
operator: In
values:
- rpi4b2.1
propertyVisitors:
- propertyName: temperature
opcua:
nodeID: ns=3;i=2002 #node1
- propertyName: switcher
opcua:
nodeID: ns=3;i=2003 #node2
status:
twins:
- propertyName: switcher
reported:
metadata:
timestamp: '1550049403598'
type: boolean
value: "false"
desired:
metadata:
timestamp: '1550049403598'
type: boolean
value: "false"
- propertyName: temperature
reported:
metadata:
timestamp: '1550049403598'
type: integer
value: "0"
fhttps://kubeedge.io/zh/docs/developer/device_crd/
Mapper Used for protocol conversion , Realization Kubeedge Support for various protocols .
Device Mapper
Mapper is an application that is used to connect and control devices. Following are the responsibilities of mapper:
1) Scan and connect to the device.
2) Report the actual state of twin-attributes of device.
3) Map the expected state of device-twin to actual state of device-twin.
4) Collect telemetry data from device.
5) Convert readings from device to format accepted by KubeEdge.
6) Schedule actions on the device.
7) Check health of the device.
In short, it is to read device data , Send instructions , Dealing with equipment .
Different devices support different protocols , Several protocols currently implemented in this project :
https://github.com/kubeedge/mappers-go
3、 ... and 、OPCUA DEMO function
download https://github.com/kubeedge/mappers-go
Get into mappers/opcua Catalog
make mapper opcua package ARM64=trueDockfile Some modifications have been made
FROM ubuntu:20.04
RUN mkdir -p kubeedge
RUN mkdir -p ca
COPY ./ca/* /ca/
RUN ls /ca
COPY ./bin/opcua kubeedge/
COPY ./config.yaml kubeedge/
WORKDIR kubeedge
ENTRYPOINT ["/kubeedge/opcua", "--v", "5"]
Compile and generate images opcua-mapper
[email protected]:~/work/mappers-go/mappers/opcua# make mapper opcua package ARM64=true
opcua package
# make mapper opcua package
downloading dependencies for mapper opcua...
tidying
vending
...done
fmt and linting mapper opcua...
...done
crossed packaging for linux/arm64
building linux/arm64
...done
packaging mapper opcua...
crossed packaging for linux/arm64
packaging opcua-mapper:v1.0-linux-arm64
Sending build context to Docker daemon 95.07MB
Step 1/9 : FROM ubuntu:20.04
---> d25e19480966
Step 2/9 : RUN mkdir -p kubeedge
---> Using cache
---> 184c2c6417ac
Step 3/9 : RUN mkdir -p ca
---> Using cache
---> c5eb93feeab0
Step 4/9 : COPY ./ca/* /ca/
---> Using cache
---> 3e3c53d9c9a7
Step 5/9 : RUN ls /ca
---> Using cache
---> 3f2c57f65659
Step 6/9 : COPY ./bin/opcua kubeedge/
---> Using cache
---> d4185abacf94
Step 7/9 : COPY ./config.yaml kubeedge/
---> Using cache
---> 612e41c13320
Step 8/9 : WORKDIR kubeedge
---> Using cache
---> 125000909f46
Step 9/9 : ENTRYPOINT ["/kubeedge/opcua", "--v", "5"]
---> Using cache
---> 0811ee8d139c
Successfully built 0811ee8d139c
Successfully tagged opcua-mapper:v1.0-linux-arm64
...done
docker images Look at the mirror image
[email protected]:~/work/mappers-go/mappers/opcua# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
opcua-mapper v1.0-linux-arm64 0811ee8d139c About an hour ago 72.3MB
<none> <none> 23a240215cc8 3 days ago 72.3MB
<none> <none> 46b34807de81 3 days ago 72.3MB
<none> <none> 72db7f8d0bb4 7 days ago 101MB
Because the image is used at the edge , Also export the image , Transfer to the edge and import . You can also compile and generate images directly on the edge .
docker save -o opcua-mapper-arm64.tar opcua-mapper:v1.0-linux-arm64To write crd/model.yaml crd/instance.yaml
from build/crd-samples/devices Under this directory opcua Of the two Yaml Take out the document and put it in crd,opcua-model.yaml As model.yaml
opcua-device.yaml As instance.yaml See above for details .
My edge node is named rpi4b2.1 , You can modify it as required .
Deploy with the following command APP:
$ kubectl apply -f crd/model.yaml
$ kubectl apply -f crd/instance.yaml
#deploy opcua mapper
$ kubectl apply -f deploy.yamlmodel.yaml
apiVersion: devices.kubeedge.io/v1alpha2
kind: DeviceModel
metadata:
name: opcua-model
namespace: default
spec:
properties:
- name: temperature
description: temperature in degree celsius
type:
int:
accessMode: ReadOnly
defaultValue: 1
- name: switcher
description: turn on or turn off
type:
boolean:
accessMode: ReadWrite
instance.yaml The content of :
apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
name: lamp-opcua
labels:
model: opcua-model
spec:
deviceModelRef:
name: opcua-model
protocol:
opcua:
url: opc.tcp://192.168.137.100:4840/
userName: testuser
password: ""
password: /ca/pass
certificate: /ca/clientcert.pem
privateKey: /ca/clientkey.pem
securityMode: None
securityPolicy: ""
common:
customizedValues:
remoteCertificate: /ca/servercert.pem
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: ''
operator: In
values:
- rpi4b2.1
propertyVisitors:
- propertyName: temperature
opcua:
nodeID: ns=3;i=2002
- propertyName: switcher
opcua:
nodeID: ns=3;i=2003
status:
twins:
- propertyName: switcher
reported:
metadata:
timestamp: '1550049403598'
type: boolean
value: "false"
desired:
metadata:
timestamp: '1550049403598'
type: boolean
value: "false"
- propertyName: temperature
reported:
metadata:
timestamp: '1550049403598'
type: integer
value: "0"
deploy.yaml The content of :
apiVersion: apps/v1
kind: Deployment
metadata:
name: opcua-mapper
spec:
replicas: 1
selector:
matchLabels:
app: opcuamapper
template:
metadata:
labels:
app: opcuamapper
spec:
nodeName: rpi4b2.1 ## This local node name needs to be modified
hostNetwork: true
containers:
- name: opcua-mapper-container
image: opcua-mapper:v1.0 ## I modified this , Matches my container name
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
volumeMounts:
- name: config-volume
mountPath: /opt/kubeedge/
nodeSelector:
opcua: "true"
volumes:
- name: config-volume
configMap:
name: device-profile-config-rpi4b2.1 ## Pay attention to this place
restartPolicy: Always
You can see... In the cloud :

On the edge device, you can see that the container is already running :
~ # docker psIf opcua-mapper No running , You need to view the program running log , Make mistakes .
The most common mistake is opcua Server connection problem .
3、 ... and 、opcua server Simulator
Access... On the edge node opcua server.
Currently available opcua The simulator is Prosys OPC UA Simulate server .
http://www.prosysopc.cn/products/opc-ua-simulation-server/
This software is free for personal use , Can be in csdn Search and download .
Operation interface :
Simulation interface of specific values :
What has not yet been resolved is Prosys OPC UA The simulation server does not seem to support data writing , Namely opcua Client pass opcua The protocol modifies the data on the simulator .
The easy problem in the early stage is that it is not connected opcua The server , You can compile and run at the edge ,opuca The program , Check the results of the program .
https://github.com/kubeedge/mappers-go/tree/main/mappers/opcua

Four 、 View data in the cloud
Use the following command to view device Value .
[email protected]:~/work/mappers-go/mappers/opcua# kubectl get devices lamp-opcua -o yaml
apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"devices.kubeedge.io/v1alpha2","kind":"Device","metadata":{"annotations":{},"labels":{"model":"opcua-model"},"name":"lamp-opcua","namespace":"default"},"spec":{"deviceModelRef":{"name":"opcua-model"},"nodeSelector":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"","operator":"In","values":["rpi4b2.1"]}]}]},"propertyVisitors":[{"opcua":{"nodeID":"ns=3;i=2002"},"propertyName":"temperature"},{"opcua":{"nodeID":"ns=3;i=2003"},"propertyName":"switcher"}],"protocol":{"common":{"customizedValues":{"remoteCertificate":"/ca/servercert.pem"}},"opcua":{"certificate":"/ca/clientcert.pem","password":"/ca/pass","privateKey":"/ca/clientkey.pem","securityMode":"None","securityPolicy":"","url":"opc.tcp://192.168.137.100:4840/","userName":"testuser"}}},"status":{"twins":[{"desired":{"metadata":{"timestamp":"1550049403598","type":"boolean"},"value":"false"},"propertyName":"switcher","reported":{"metadata":{"timestamp":"1550049403598","type":"boolean"},"value":"false"}},{"propertyName":"temperature","reported":{"metadata":{"timestamp":"1550049403598","type":"integer"},"value":"0"}}]}}
creationTimestamp: "2022-06-17T04:04:09Z"
generation: 729
labels:
model: opcua-model
managedFields:
- apiVersion: devices.kubeedge.io/v1alpha2
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:kubectl.kubernetes.io/last-applied-configuration: {}
f:labels:
.: {}
f:model: {}
f:spec:
.: {}
f:deviceModelRef:
.: {}
f:name: {}
f:nodeSelector:
.: {}
f:nodeSelectorTerms: {}
f:propertyVisitors: {}
f:protocol:
.: {}
f:common:
.: {}
f:customizedValues:
.: {}
f:remoteCertificate: {}
f:opcua:
.: {}
f:certificate: {}
f:password: {}
f:privateKey: {}
f:securityMode: {}
f:securityPolicy: {}
f:url: {}
f:userName: {}
f:status: {}
manager: kubectl
operation: Update
time: "2022-06-21T02:29:09Z"
- apiVersion: devices.kubeedge.io/v1alpha2
fieldsType: FieldsV1
fieldsV1:
f:status:
f:twins: {}
manager: cloudcore
operation: Update
time: "2022-06-21T02:39:53Z"
name: lamp-opcua
namespace: default
resourceVersion: "22666744"
selfLink: /apis/devices.kubeedge.io/v1alpha2/namespaces/default/devices/lamp-opcua
uid: cb57e60a-4c80-4b49-a461-2706f7fffc40
spec:
deviceModelRef:
name: opcua-model
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: ""
operator: In
values:
- rpi4b2.1
propertyVisitors:
- opcua:
nodeID: ns=3;i=2002
propertyName: temperature
- opcua:
nodeID: ns=3;i=2003
propertyName: switcher
protocol:
common:
customizedValues:
remoteCertificate: /ca/servercert.pem
opcua:
certificate: /ca/clientcert.pem
password: /ca/pass
privateKey: /ca/clientkey.pem
securityMode: None
securityPolicy: ""
url: opc.tcp://192.168.137.100:4840/
userName: testuser
status:
twins:
- desired:
metadata:
timestamp: "1550049403598"
type: boolean
value: "false"
propertyName: switcher
reported:
metadata:
timestamp: "1655779193063"
type: boolean
value: "true"
- desired:
value: ""
propertyName: temperature
reported:
metadata:
timestamp: "1655779193079"
type: string
value: "17"
边栏推荐
- Openresty usage document
- 多线程基础部分Part3
- Assembly language - Wang Shuang Chapter 13 int instruction - Notes
- Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems
- openresty使用文档
- Using domain name forwarding mqtt protocol, pit avoidance Guide
- Web3 has not been implemented yet, web5 suddenly appears!
- Spark 之 Projection
- 洛谷P4683 [IOI2008] Type Printer 题解
- 双位置继电器DLS-34A DC0.5A 220VDC
猜你喜欢

30 SCM common problems and solutions!

Asp.Net Core6 WebSocket 简单案例

我对于测试团队建设的意见

How win 10 opens the environment variables window

leetcode298周赛记录
![[nips 2017] pointnet++: deep feature learning of point set in metric space](/img/3e/0a47eecc27f236d629c611e683b37a.png)
[nips 2017] pointnet++: deep feature learning of point set in metric space

EasyExcel合并相同内容单元格及动态标题功能的实现

IAR systems fully supports Centrino technology 9 series chips
软件测试年终总结报告模板

块级元素&行内元素
随机推荐
Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems
mysql 查询时将状态改为相对应的文字
Asp. Net core6 websocket simple case
[622. design cycle queue]
Spark 之 Projection
Unity中跨平台获取系统音量
Assembly language - Wang Shuang Chapter 3 notes and experiments
洛谷P2939 [USACO09FEB]Revamping Trails G 题解
leetcode299周赛记录
310. 最小高度树
双位置继电器JDP-1440/DC110V
EasyExcel合并相同内容单元格及动态标题功能的实现
Win 10 如何打开环境变量窗口
《汇编语言-王爽》第3章笔记及实验
Qt使用Valgrind分析内存泄漏
Double position relay rxmd2-1mrk001984 dc220v
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
Openresty usage document
Neon optimization 1: how to optimize software performance and reduce power consumption?
竣达技术丨多品牌精密空调集中监控方案