1

这是我的脚本有错误的部分:

while:
    sensorIn = 8
    sensorOut = 5
    sensorAC = 7
    blue = 0
    white = 1
    [tempIn, humIn] = grovepi.dht(sensorIn, 1)
    print("tempIn = %.02f C humIn =%.02f%%"%(tempIn, humIn))
    [tempOut, humOut] = grovepi.dht(sensorOut, 1)
    print("tempOut = %.02f C humOut =%.02f%%"%(tempOut, humOut))
    [tempAC, humAC] = grovepi.dht(sensorAC, 1)
    print("tempAC = %.02f C humAC =%.02f%%"%(tempAC, humAC))

它随机出错:

TypeError: 'int' object not iterable on the line: [tempAC, humAC] = grovepi.dht(sensorAC, 1)

这与 Raspberry Pi 和 GrovePi 板一起使用,以获取来自温度和湿度传感器的读数。它会循环播放,读取读数,然后用这些读数做一些事情,然后睡 15 分钟,然后重新开始。

也许while循环是问题......我曾经在没有while循环的情况下运行它,并将它设置在crontab中以这种方式每15分钟运行一次。有时读数会出现错误,但会以 0 的形式通过脚本,脚本不会停止并出错,它会继续并仅将值报告为零。

我看过很多关于这个错误的不同帖子,但我只遇到过总是出现错误并且根本不允许脚本运行完成的帖子,就我而言,它只是偶尔发生。

4

1 回答 1

1

看起来这是 grovepi.dht 函数的一个已知问题,有时可能是由与设备的通信问题引起的。http://forum.dexterindustries.com/t/incorrect-readings-and-typeerror/1582/2

解决方案只是为类型错误添加异常处理,因为它只是一个间歇性问题(有关如何执行此操作的示例,请参阅链接的帖子)。

于 2017-03-30T13:43:32.110 回答