kubeedge的设备接入采用的是mapper,

用mapper去适配不同的协议类型。
已经实现的协议在这个地方:
GitHub - kubeedge/mappers-go: KubeEdge Device Mappers written in go
包括modbus, opcua, 蓝牙等。
运行的时候mapper是运行在容器中,会根据云端下发的设备数据,与设备建立连接。
但是在容器中调试非常不便。
其实在容器外面也是可以运行的,只不过需要把云端下发的.json准备好。
以opcua mapper为例。
https://github.com/kubeedge/mappers-go/blob/main/mappers/opcua/config.yaml
这个文件定义configmap: /opt/kubeedge/deviceProfile.json的位置
改成configmap: ./deviceProfile.json
deviceProfile.json的内容从云端拿
kubectl get cm XXXXXXX -o json
就导出了这个边缘节点上的设备信息。

保存到deviceProfile.json中, deviceProfile.json中最后面有几个关于证书的配置,需要修改成本地的证书(mappers-go项目中有)。
以及opcua的参数修改成需要的,就可以运行这个mapper了。
{"deviceInstances": [{"id": "plc-instance-sl1-8g-108","name": "plc-instance-sl1-8g-108","protocol": "opcua-plc-instance-sl1-8g-108","model": "plc-model","twins": [{"propertyName": "status","desired": {"value": ""},"reported": {"value": "0","metadata": {"timestamp": "1678938009371","type": "int"}}}]}],"deviceModels": [{"name": "plc-model","properties": [{"name": "status","dataType": "int","description": "status","accessMode": "ReadOnly","defaultValue": 0,"minimum": 0,"maximum": 0}]}],"protocols": [{"name": "opcua-plc-instance-sl1-8g-108","protocol": "opcua","protocolConfig": {"url": "opc.tcp://127.0.0.1:4840/","userName": "testuser","password": "./ca/pass","securityMode": "None","certificate": "./ca/clientcert.pem","privateKey": "./ca/clientkey.pem"},"protocolCommonConfig": {"customizedValues": {"remoteCertificate": "./ca/servercert.pem"}}}]
}
make mapper 后, 生成的程序在bin/目录下。
./bin/opcua --v 5