从 Azure IoT Edge 的模块内访问 Raspi 上的/dev/serial0 时遇到问题 [英] Having trouble accessing /dev/serial0 on a Raspi from within a Module in Azure IoT Edge

查看:87
本文介绍了从 Azure IoT Edge 的模块内访问 Raspi 上的/dev/serial0 时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个模块,该模块将与运行 Raspian Stretch 的 Raspberry Pi B+ 上的 /dev/serial0 进行交互.我在 /boot/config.txt 中使用了 dtoverlay=pi3-miniuart-bt 将 UART0/ttyAMA0 恢复到 GPIOs 14 和 15(这是我基于 Raspi 的硬件需要我做).

I'm trying to set up a Module which will interact with /dev/serial0 on a Raspberry Pi B+ running Raspian Stretch. I've used dtoverlay=pi3-miniuart-bt in /boot/config.txtto restore UART0/ttyAMA0 to GPIOs 14 and 15 (which is what my Raspi-based HW needs me to do).

我已尝试使用以下容器创建选项使模块可以访问该设备:

I have attempted to make that device accessible to the Module using the following Container Create Options:

{
  "HostConfig": {
    "PortBindings": {
      "1880/tcp": [
        {
          "HostPort": "1880"
        }
      ]
    },
    "Privileged": true,
    "Devices": [
      {
        "PathOnHost": "/dev/serial0",
        "PathInContainer": "/dev/serial0",
        "CgroupPermissions": "rwm"
      },
      {
        "PathOnHost": "/dev/ttyAMA0",
        "PathInContainer": "/dev/ttyAMA0",
        "CgroupPermissions": "rwm"
      },
      {
        "PathOnHost": "/dev/ttyS0",
        "PathInContainer": "/dev/ttyS0",
        "CgroupPermissions": "rwm"
      }
    ]
  }
}

当我 ssh 进入时,我可以看到 /dev/serial0,但是我在正在运行的模块中看不到它:

I can see /dev/serial0 when I ssh in, but I can't see it from within the running Module:

pi@azure-iot-test:~ $ ls -l /dev/ser*
lrwxrwxrwx 1 root root 7 Sep 24 21:17 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Sep 24 21:17 /dev/serial1 -> ttyS0
pi@azure-iot-test:~ $ sudo docker exec hub-nodered ls -l /dev/ser*
ls: /dev/serial0: No such file or directory
ls: /dev/serial1: No such file or directory

有什么想法吗?

跟进:

我尝试了从 这里收集的以下想法的其他内容:

  • "User": "node-red" 添加到容器创建选项的根目录
  • "User": "root" 添加到容器创建选项的根目录
  • 在容器创建选项中将 "GroupAdd": "dialout" 添加到 "HostConfig": {...}
  • Adding "User": "node-red" to the root of the Container Create Options
  • Adding "User": "root" to the root of the Container Create Options
  • Adding "GroupAdd": "dialout" to "HostConfig": {...} in the Container Create Options

后续行动 #2

虽然我仍然无法与 /dev/serial0 交互,但我能够使用以下方法与 /dev/ttyAMA0 交互容器创建选项:

While I still can't interact with /dev/serial0, I am able to interact with /dev/ttyAMA0 using the following Container Create Options:

{
  "HostConfig": {
    "GroupAdd": [
      "dialout"
    ],
    "PortBindings": {
      "1880/tcp": [
        {
          "HostPort": "80"
        }
      ]
    },
    "Devices": [
      {
        "PathOnHost": "/dev/serial0",
        "PathInContainer": "/dev/serial0",
        "CgroupPermissions": "rwm"
      },
      {
        "PathOnHost": "/dev/ttyAMA0",
        "PathInContainer": "/dev/ttyAMA0",
        "CgroupPermissions": "rwm"
      }
    ]
  }
}

值得注意的项目似乎是:

The noteworthy items appear to be:

  • 我不需要 "Privileged": true"HostConfig"
  • 我似乎不需要添加用户"
  • 我需要 "GroupAdd": ["dialout"]"HostConfig"
  • I didn't need "Privileged": true in "HostConfig"
  • I don't seem to need a "User" added
  • I needed "GroupAdd": ["dialout"] in "HostConfig"

所以,虽然我可以随心所欲地与串行设备交互很令人满意,但我无法与 /dev/serial0 交互似乎很奇怪,这似乎是推荐的方式"来自我所做的阅读.

So, while it's satisfying that I can interact with a serial device as I wanted to, it seems odd that I can't interact with /dev/serial0, which seems like it's "the recommended way" from the reading I've done.

推荐答案

感谢来自 Raymond Mouthaan 在非常有用的 Node-RED Slack 频道 上,我找到了通往此容器创建选项的方法,它为我提供了访问/dev/serial0:

Thanks to help and insight from Raymond Mouthaan over on the very helpful Node-RED Slack channel, I found my way to this Container Create Options providing me access to /dev/serial0:

{
  "User": "node-red:dialout",
  "HostConfig": {
    "PortBindings": {
      "1880/tcp": [
        {
          "HostPort": "80"
        }
      ]
    },
    "Devices": [
      {
        "PathOnHost": "/dev/serial0",
        "PathInContainer": "/dev/serial0",
        "CgroupPermissions": "rwm"
      }
    ]
  }
}

这与我在上面的后续 #2"中找到的部分解决方案不同,因为我现在可以根据需要访问 /dev/serial0.

This is different than the partial solution I found in "Followup #2" above in that I now do get access to /dev/serial0 as desired.

更新:我最初使用 "User": "root:dialout" 而不是 "User": "node-red:dialout" 发布了这个答案" 你目前在上面看到.

UPDATE: I originally posted this answer using "User": "root:dialout" rather than the "User": "node-red:dialout" you currently see above.

第一个可行的解决方案是使用 "User": "root:root",但我认为只限制在 Devicesroot:dialout 似乎是这样做的.

The first working solution was with "User": "root:root", but it seemed good to me to constrain to just the devices that are called out in Devices, which root:dialout seemed to do.

但我想知道我是否应该考虑以 root 身份运行的安全性.

But I wondered whether I should be concerned security-wise with running as root at all.

然后我尝试使用 node-red:dialout 并且它似乎工作得很好,所以我更新了上面的容器创建选项,我认为这是最好的答案.

Then I tried using node-red:dialout and it seems to be working perfectly, so I've updated the Container Create Options above to be what I think is the best answer.

这篇关于从 Azure IoT Edge 的模块内访问 Raspi 上的/dev/serial0 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆