我找不到为什么出现此错误的原因,特别是在程序运行后。很抱歉直接询问
pi@raspberrypi:~/Desktop/Testing $ python Fire.py
Traceback (most recent call last):
File "Fire.py", line 32, in <module>
'temp': temp_data()
File "Fire.py", line 23, in temp_data
cTemp, fTemp, humidity =temp_out()
File "Fire.py", line 13, in temp_out
bus.write_i2c_block_data(0x44, 0x2C, [0x06])
IOError: [Errno 121] Remote I/O error
有人可以在代码方面帮助我吗?我是python的新手,我编写了一个代码,使用树莓派pi将温度和湿度传感器SHT31的数据发送到Firebase
import glob
import subprocess
import calendar
import time
import urllib2
import json
import smbus
bus = smbus.SMBus(1)
def temp_out():
bus.write_i2c_block_data(0x44, 0x2C, [0x06])
data = bus.read_i2c_block_data(0x44, 0x00, 6)
# Convert the data
temp = data[0] * 256 + data[1]
cTemp = -45 + (175 * temp / 65535.0)
fTemp = -49 + (315 * temp / 65535.0)
humidity = 100 * (data[3] * 256 + data[4]) / 65535.0
return cTemp, fTemp, humidity
def temp_data():
cTemp, fTemp, humidity =temp_out()
print("Temperature in Celsius is : %.2f C" %cTemp)
print ("Temperature in Fahrenheit is : %.2f F" %fTemp)
print ("Relative Humidity is : %.2f %%RH" %humidity)
url = 'Firebase api destination'
postdata = {
'date': str(calendar.timegm(time.gmtime())),
'temp': temp_data()
}
req = urllib2.Request(url)
req.add_header('Content-Type','application/json')
data = json.dumps(postdata)
response = urllib2.urlopen(req,data)
我不知道是什么原因引起了您的建议。
注意:我正在使用Python 3.5.3