我正在尝试使用Threading操作GPS流和Raspberry Pi相机。我正在使用python 3.5并运行Rasbian。
昨天,我能够运行我的代码并获得不错的结果。今天,我没有任何成功。我是刚来这里的人,所以如果我错过任何有用的信息,请告诉我。
如何解决此问题?我是否可以使用任何bash命令来确保不会再次发生这种情况?
错误
GPSDSocket.connect exception is--> [Errno 111]
Connection refused
AGPS3 connection to a gpsd at '127.0.0.1' on port
'2947' failed
Traceback (most recent call last):
File "grgr.py", line 75, in <module>
g= gps_thread()
File "grgr.py", line 33, in __init__
self.agps_thread.stream_data()
File "/home/pi/.local/lib/python2.7/site-
packages/gps3/agps3threaded.py", line 36, in
stream_data
self.socket.watch(enable, gpsd_protocol,
devicepath)
File "/home/pi/.local/lib/python2.7/site-
packages/gps3/agps3.py", line 88, in watch
return self.send(command)
File "/home/pi/.local/lib/python2.7/site-
packages/gps3/agps3.py", line 98, in send
self.streamSock.send(commands) # 2.7 chokes on
'bytes' and 'encoding='
socket.error: [Errno 32] Broken pipe
这是我的代码
import os
from picamera import PiCamera
from time import *
import time
import subprocess
import threading
import csv
from apscheduler.schedulers.background import BackgroundScheduler
from gps3.agps3threaded import AGPS3mechanism
gpsd = None #seting the global variable
os.system('clear') #clear the terminal (optional)
# os.system('clear') #clear the terminal (optional)
global cwd
cwd=os.getcwd()
class gps_thread:
def __init__(self):
## self._host=
## self._port=
self.scheduler = BackgroundScheduler()
self.job = self.scheduler.add_job(self.pull_data, 'interval', seconds=1, max_instances=4)
self.agps_thread = AGPS3mechanism() # Instantiate AGPS3 Mechanisms
## self.agps_thread.stream_data(host=self._host, port= self._port) # From localhost (), or other hosts, by example, (host='gps.ddns.net')
self.agps_thread.stream_data()
self.agps_thread.run_thread() # Throttle time to sleep after an empty lookup, default '()' 0.2 two tenths of a second gps
self.scheduler.start()
def pull_data(self):
print('in pull data')
data=[self.agps_thread.data_stream.time, self.agps_thread.data_stream.speed,
self.agps_thread.data_stream.lat, self.agps_thread.data_stream.lon, self.agps_thread.data_stream.alt]
print(data)
addToFile("log.csv", data)
##class cam_thread:
## def __init__(self):
## self.scheduler= BackgroundScheduler()
## self.job = self.scheduler.add_job(self.cap_image, 'interval', seconds=4, max_instances=4)
## self.scheduler.start()
##
##
## def cap_image(self):
## print("in cap_image")
## with PiCamera() as cam:
## time.sleep(2)
## logdt = datetime.datetime.now().strftime("%H%M%S")
## cam.capture(str(cwd)+ 'gr_log' + str(logdt) + '.jpg')
##
def addToFile(file, what):
# f = open(file, 'a', newline='').write(str(what))
with open(file, 'a', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(what)
if __name__ == '__main__':
f = open("log.csv", "w")
f.truncate()
f.write(str(["Time", "Speed", "Latitude", "Longitude", "Altitude", ]))#"XAcc", "YAcc", "ZAcc"
f.close()
g= gps_thread()
## c= cam_thread()
try:
while True:
print("inside While")
time.sleep(.5)
except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
print ("\nKilling Thread...")
print ("Done.\nExiting.")
这是netstat -anp的输出
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:4957 0.0.0.0:* LISTEN 4063/python3
tcp 0 0 192.168.86.31:55798 192.0.73.2:443 ESTABLISHED 986/libpepflashplay
tcp 0 0 192.168.86.31:57216 23.21.193.199:443 ESTABLISHED 986/libpepflashplay
tcp 0 0 192.168.86.31:45936 23.21.193.169:443 TIME_WAIT -
tcp 0 0 192.168.86.31:51772 104.16.29.34:443 ESTABLISHED 986/libpepflashplay
tcp 0 0 192.168.86.31:50696 74.125.138.132:443 ESTABLISHED 986/libpepflashplay
tcp 0 0 192.168.86.31:47866 151.101.129.69:443 ESTABLISHED 986/libpepflashplay
tcp 0 0 192.168.86.31:40694 74.125.196.188:443 ESTABLISHED 986/libpepflashplay
tcp 1 0 192.168.86.31:53922 192.168.86.100:8060 CLOSE_WAIT 986/libpepflashplay
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 ::1:3350 :::* LISTEN -
tcp6 0 0 :::3389 :::* LISTEN -
udp 0 0 0.0.0.0:41412 0.0.0.0:* -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* 986/libpepflashplay
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp6 0 0 :::36909 :::* -
udp6 0 0 :::5353 :::* 986/libpepflashplay
udp6 0 0 :::5353 :::* -
raw6 0 0 :::58 :::* 7 -