diff --git a/GPS.py b/GPS.py index 986e9b5..64b0f4b 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,9 +39,6 @@ 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 @@ -51,15 +48,17 @@ def get_gps_position(): time.sleep(2) while rec_null: answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1) + client.publish("iiot/"+ myhost +"/gps", answer, 0) 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 + 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 = '' @@ -67,6 +66,11 @@ def get_gps_position(): return False time.sleep(1.5) +def extract_gps_info(rec_buff): + # Implement this function based on the format of rec_buff + # Example: gps_info = rec_buff.split(',')[2] + return gps_info + def power_on(power_key): print('SIM7600X is starting:')