我无法从raspberry pi 3B+上的控制台运行脚本(最终用于在启动时运行脚本),尽管它在Thonny中运行得非常好。
我得到以下错误:FileNotFoundError:[Errno 2]没有这样的文件或目录:“image1.jpg”
我的脚本和图像文件在同一个文件夹中,脚本在错误发生前生成了第一个名为“image1.jpg”的图像。
代码的目的是使用picame拍摄照片,并通过PUT json请求将其发送到在线平台。我认为在控制台上运行的脚本可能更快,而且Pi在发送图像文件之前没有时间保存它。我试图延迟Json请求,但这不是问题所在。下面不是我的全部代码,而是最有可能出现问题的地方。
这是循环的开始,在循环中用“tick”创建和索引图像文件
camera = PiCamera()
go = 1
tick = 1
starttime=time.time()
deltick = 1
camera.resolution = (640, 480)
while go == 1:
camera.capture('/home/pi/ghettoCam/image%s.jpg' % tick)
image = '/home/pi/ghettoCam/image%s.jpg' % tick
#this is the Json part where the images are sent out
url = 'destinationURL'
###### Parameters to update ##################
thingName = 'armedResponder2'
propName = 'video'
imageName = 'image%s.jpg' % tick
#below is where I get the error
with open(imageName, "rb") as image_file:
imageSend = base64.b64encode(image_file.read())
payload = {propName: imageSend}
# Extend this as needed {'prop1': data1,'prop2': data2, etc.}
###### End Parameters ############################
headers = { 'Content-Type': 'application/json', 'appKey': '1c6026f9-2310-4e36-98b5-8b4aa0e35dfc' }
response = requests.put(url + '/Things/'+ thingName+ '/Properties/*', headers=headers, json=payload, verify=False)
#tick update
tick = tick+1
预期结果:程序运行起来和空闲时一样,它每秒钟拍一张照片并成功地发送到平台。
实际结果:在控制台中运行脚本时,在只拍摄一张照片并将注释发送到联机平台后,我会得到前面描述的错误。