2024-07-11 -
This commit is contained in:
parent
0733127ea0
commit
7923e98a22
27
GPS.py
27
GPS.py
@ -1,21 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding:utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import paho.mqtt.client as mqtt
|
||||
import serial
|
||||
import time, os
|
||||
|
||||
# MQTT Broker settings
|
||||
|
||||
mqttBroker ="65.108.199.212"
|
||||
myhost = os.uname()[1]
|
||||
client = mqtt.Client(myhost)
|
||||
client.connect(mqttBroker, 1883)
|
||||
|
||||
ser = serial.Serial('/dev/ttyS0',115200)
|
||||
ser.flushInput()
|
||||
|
||||
|
||||
rec_buff = ''
|
||||
rec_buff2 = ''
|
||||
time_count = 0
|
||||
@ -48,17 +39,12 @@ 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, 2)
|
||||
return True
|
||||
else:
|
||||
print('GPS no está listo')
|
||||
rec_null = False
|
||||
time.sleep(1)
|
||||
print('GPS no está listo')
|
||||
rec_null = False
|
||||
time.sleep(1)
|
||||
else:
|
||||
print('error %d'%answer)
|
||||
rec_buff = ''
|
||||
@ -66,11 +52,6 @@ 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:')
|
||||
@ -104,4 +85,4 @@ except:
|
||||
GPIO.cleanup()
|
||||
if ser != None:
|
||||
ser.close()
|
||||
GPIO.cleanup()
|
||||
GPIO.cleanup()
|
||||
|
@ -1,25 +1,106 @@
|
||||
Iniciando GPS
|
||||
AT+CGPS=1,1 ERROR
|
||||
AT+CGPS=1,1 back: AT+CGPS=1,1
|
||||
ERROR
|
||||
AT+CGPS=0
|
||||
OK
|
||||
|
||||
|
||||
+CGPS: 0
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.397161,N,08406.296290,W,110724,205340.0,1153.2,0.0,
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.397161,N,08406.296288,W,110724,205342.0,1153.2,0.0,
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.397165,N,08406.296286,W,110724,205345.0,1153.2,0.0,
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.397165,N,08406.296287,W,110724,205347.0,1153.2,0.0,
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
AT+CGPSINFO
|
||||
+CGPSINFO: 0956.398923,N,08406.296438,W,120724,010243.0,1137.5,0.0,
|
||||
|
||||
OK
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user