Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]An error occurred when using the Modbus Service and Openyurt to connect to a real sensor! #2115

Open
HuangYuFe opened this issue Aug 5, 2024 · 6 comments
Labels
kind/question kind/question

Comments

@HuangYuFe
Copy link

What happened:
I tried to use the EdgeX project to complete the integration of real sensor devices based on the ModbusRTU protocol. I completed the deployment of EdgeX using Openyurt' Deployment deployer。
屏幕截图 2024-08-05 173522
In addition, I have completed the access of real sensor devices based on ModbusTCP, which can complete the data collection.
屏幕截图 2024-08-05 172918
But when I try to collect ModbusRTU device data via the USB hardware interface, I get a problem.
屏幕截图 2024-08-05 172951

What you expected to happen:
I checked the deployment information of the EdgeX application according to the permission denial prompted by the log message, and I confirmed that the mount path is /dev/ttyUSB0 and I have the r/w permission.
屏幕截图 2024-08-05 173215
So, it's not clear to me what the cause of the error is, here's the YAML content of my Openyurt deployer:
屏幕截图 2024-08-05 173417
How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:
屏幕截图 2024-08-05 210020
屏幕截图 2024-08-05 210049
Environment:

  • OpenYurt version:v1.4
  • Kubernetes version (use kubectl version):1.22.4
  • OS (e.g: cat /etc/os-release):Ubuntu 20.04.6 LTS
  • Kernel (e.g. uname -a):Linux orangepi5plus 6.1.43-rockchip-rk3588
  • Install tools:
  • Others:

others
/kind question

@HuangYuFe HuangYuFe added the kind/question kind/question label Aug 5, 2024
@rambohe-ch
Copy link
Member

@LavenderQAQ PTAL

@LavenderQAQ
Copy link
Member

@HuangYuFe Hello, could you please provide the version of EdgeX you are using?

@HuangYuFe
Copy link
Author

HuangYuFe commented Aug 6, 2024

@HuangYuFe Hello, could you please provide the version of EdgeX you are using?

@LavenderQAQ The version of EdgeX I'm using is levski, and both of them have image versions 2.3.0

@HuangYuFe
Copy link
Author

@LavenderQAQ
For the access of ModbusRTU devices, I refer to the official EdgeX manual, but the official deployment is done in the way of DockerCompose, mounting directories, and permissions are all completed through Linux instructions. But this way I tried it and it didn't work. Previously, we discussed with Openyurt that when changing the Service to a NodePort type, the Linux command operation is invalid. At that time, it was achieved by modifying the cm platformadmin-framework provided by Openyurt. So, this time, I also tried to add a mount path and permission upgrade in CM platformadmin-framework.

@LavenderQAQ
Copy link
Member

@HuangYuFe Try using a privileged container. Reading and writing to a real device inside a container may require enabling privileges.

apiVersion: v1
kind: Pod
metadata:
  name: privileged-pod
spec:
  containers:
  - name: privileged-container
    image: your-image
    securityContext:
      privileged: true

@HuangYuFe
Copy link
Author

HuangYuFe commented Aug 8, 2024

@LavenderQAQ Yes, I also took this into account afterwards and modified the YMAL file as follows:

    - deployment:
        selector:
          matchLabels:
            app: edgex-device-modbus
        strategy: {}
        template:
          metadata:
            creationTimestamp: null
            labels:
              app: edgex-device-modbus
          spec:
            initContainers:
            - name: init-permissions
              image: edgexfoundry/device-modbus-arm64:2.3.0
              command: ["sh", "-c",  "chown :0 /dev/ttyUSB0"]
              volumeMounts:
              - name: devices
                mountPath: /dev/ttyUSB0
            containers:
            - env:
              - name: SERVICE_HOST
                value: edgex-device-modbus
              envFrom:
              - configMapRef:
                  name: common-variables
              image: edgexfoundry/device-modbus-arm64:2.3.0
              imagePullPolicy: IfNotPresent
              name: edgex-device-modbus
              ports:
              - containerPort: 59901
                name: tcp-59901
                protocol: TCP
              resources: {}
              volumeMounts:
              - name: devices
                mountPath: /dev/ttyUSB0
              securityContext:
                privileged: true
                runAsUser: 0
            hostname: edgex-device-modbus
          volumes:
          - name: devices
            hostPath:
              path: /dev/ttyUSB0
      name: edgex-device-modbus
      service:
        ports:
        - name: tcp-59901
          port: 59901
          protocol: TCP
          targetPort: 59901
        selector:
          app: edgex-device-modbus

After rebuilding the service, the same permission error is still reported.
屏幕截图 2024-08-08 152614
ModbusTCP devices are available, ModbusRTU devices are not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question kind/question
Projects
None yet
Development

No branches or pull requests

3 participants