【问题标题】:Get temperature of Raspberry from greengrass从青草中获取覆盆子的温度
【发布时间】:2019-08-25 06:13:37
【问题描述】:

我可以使用 python 命令获取树莓派的温度:

os.popen("vcgencmd measure_temp").readline()

但是当我在设备上部署的 greengrass 上的 lambda 函数 (python 2.7) 中运行此命令时,它给了我错误:

VCHI 初始化失败

我相信这是因为在容器中运行的 lambda 函数不知道它运行在哪个树莓派上。

如何通过在 greengrass 上运行的 lambda 函数获取树莓派的温度?

【问题讨论】:

    标签: raspberry-pi aws-lambda aws-iot greengrass


    【解决方案1】:

    有两种方法可以读取 CPU 温度 - 一种使用vcgencmd,另一种使用文件接口。可能是 greengrass 阻止您运行 vcgencmd,也可能是它也不允许您访问文件接口,但值得一试。该文件位于/sys/class/thermal/thermal_zone0/temp

    一种方法是使用gpiozero's CPUTemperature class

    from gpiozero import CPUTemperature
    
    cpu = CPUTemperature()
    
    print(cpu.temperature)
    

    或者,直接读取文件,并提取温度(就像 gpiozero 在下面所做的那样):

    def cpu_temp():
        sensor_file = '/sys/class/thermal/thermal_zone0/temp'
    
        with io.open(sensor_file, 'r') as f:
            return float(f.readline().strip()) / 1000
    
    print(cpu_temp())
    

    【讨论】:

      猜你喜欢
      • 2017-06-21
      • 1970-01-01
      • 2018-05-31
      • 2020-10-28
      • 1970-01-01
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多