对于有经验的python来说,这是一个简单的问题。我不是,只是需要使用这一小段代码,可能永远不会在其他任何地方使用它,因此我要求stackoverflow众神的怜悯。我试图从终端运行。 cd进入桌面并运行ourfleet.py.rtf。我的错误是可怕的:文件" ourfleet.py.rtf",第1行 {\ RTF1 \ ANSI \ ansicpg1252 \ cocoartf1347 \ cocoasubrtf570 ^ SyntaxError:行继续符后面的意外字符
最终的第一次python用户以及上次python用户只需要这个工作。竖起大拇指最好的答案。我安装了最新的python版本&运行一个macbook。
import serial
import time
import requests
import json
firebase_url = 'https://ourfleet.firebaseio.com'
#Connect to Serial Port for communication
ser = serial.Serial(‘dev/tty.wchusbserial410’, 4800, timeout=0)
#Setup a loop to send GPS values at fixed intervals
#in seconds
fixed_interval = 10
while 1:
try:
#gps value obtained from Arduino + LM35 Temp Sensor
gps_c = ser.readline()
#current time and date
time_hhmmss = time.strftime("%H:%M:%S")
date_mmddyyyy = time.strftime("%d/%m/%Y")
#current location name
gps_location = "Doug C."
print “gps_c + ',' + time_hhmmss + ',' + date_mmddyyyy + ',' + gps_location”
#insert record
data = {'date':date_mmddyyyy,'time':time_hhmmss,'value’:gps_c}
result = requests.post(firebase_url + "/" + gps_location + "/gps.json", data=json.dumps(data))
#insert record
print “"Record inserted. Result Code = " + str(result.status_code) + "," + result.text”
time.sleep(fixed_interval)
except IOError:
print('Error! Something went wrong.')
time.sleep(fixed_interval)