我可以使用scp和SSH密钥将本地pi上终端中的文件复制到我的远程pi,而无需密码提示 like this
但是当我使用os.system在Python脚本中运行相同的命令时,终端会中断脚本并提示我输入密码为pi@192.168.0.15。
花了好几个小时尝试不同的SSH密钥对教程试图解决这个问题无济于事。有任何想法吗?这是代码:
# Simple example of reading the MCP3008 analog input channels and printing
# them all out.
# Author: Tony DiCola
# License: Public Domain
import time
# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
import os
# Software SPI configuration:
# CLK = 18
# MISO = 23
# MOSI = 24
# CS = 25
# mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
# Hardware SPI configuration:
SPI_PORT = 0
SPI_DEVICE = 0
mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
num = 1
print('Reading MCP3008 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
print('-' * 57)
# Main program loop.
while True:
# Read all the ADC channel values in a list.
values = [0]*8
for i in range(8):
# The read_adc function will get the value of the specified channel (0-7).
values[i] = mcp.read_adc(i)
# Print the ADC values.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
# Check if distance of object has increased, take a picture if it has.
if values[0] < 100:
num = num + 1
imagename = str(num)
os.system("raspistill -vf -ex night -o "+imagename)
os.system("scp /home/pi/Adafruit_Python_MCP3008/examples/"+imagename+" pi@192.168.0.15:/home/pi/Pictures")
else:
# Pause for half a second.
time.sleep(0.5)