diff --git a/GPS.py b/GPS.py index 9d50aa7..986e9b5 100755 --- a/GPS.py +++ b/GPS.py @@ -21,7 +21,7 @@ rec_buff2 = '' time_count = 0 def send_at(command,back,timeout): - rec_buff = '' + rec_buff = '' ser.write((command+'\r\n').encode()) time.sleep(timeout) if ser.inWaiting(): @@ -39,6 +39,9 @@ def send_at(command,back,timeout): print('GPS no está listo') return 0 +def extract_gps_info(rec_buff): + pass + def get_gps_position(): rec_null = True answer = 0 @@ -48,12 +51,14 @@ def get_gps_position(): time.sleep(2) while rec_null: answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1) - client.publish("iiot/"+ myhost +"/gps", answer, 2) if 1 == answer: answer = 0 if ',,,,,,' in rec_buff: + gps_info = extract_gps_info(rec_buff) + client.publish("iiot/" + myhost + "/gps", gps_info, 1) + return True + else: print('GPS no está listo') - rec_null = False time.sleep(1) else: print('error %d'%answer) diff --git a/coordinates.txt b/coordinates.txt new file mode 100644 index 0000000..4ac062f --- /dev/null +++ b/coordinates.txt @@ -0,0 +1,25 @@ +Iniciando GPS +AT+CGPS=1,1 ERROR +AT+CGPS=1,1 back: AT+CGPS=1,1 +ERROR + +AT+CGPSINFO ++CGPSINFO: 0956.397161,N,08406.296290,W,110724,205340.0,1153.2,0.0, + +OK + +AT+CGPSINFO ++CGPSINFO: 0956.397161,N,08406.296288,W,110724,205342.0,1153.2,0.0, + +OK + +AT+CGPSINFO ++CGPSINFO: 0956.397165,N,08406.296286,W,110724,205345.0,1153.2,0.0, + +OK + +AT+CGPSINFO ++CGPSINFO: 0956.397165,N,08406.296287,W,110724,205347.0,1153.2,0.0, + +OK + diff --git a/gps2.py b/gps2.py index d31f19a..9d50aa7 100644 --- a/gps2.py +++ b/gps2.py @@ -52,12 +52,9 @@ def get_gps_position(): if 1 == answer: answer = 0 if ',,,,,,' in rec_buff: - gps_info = extract_gps_info(rec_buff) - client.publish("iiot/" + myhost + "/gps", gps_info, 2) - return True - else: - print('GPS no está listo') - time.sleep(1) + print('GPS no está listo') + rec_null = False + time.sleep(1) else: print('error %d'%answer) rec_buff = ''