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
|
#!/usr/bin/python
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import paho.mqtt.client as mqtt
|
|
||||||
import serial
|
import serial
|
||||||
import time, os
|
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 = serial.Serial('/dev/ttyS0',115200)
|
||||||
ser.flushInput()
|
ser.flushInput()
|
||||||
|
|
||||||
|
|
||||||
rec_buff = ''
|
rec_buff = ''
|
||||||
rec_buff2 = ''
|
rec_buff2 = ''
|
||||||
time_count = 0
|
time_count = 0
|
||||||
@ -48,17 +39,12 @@ def get_gps_position():
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
while rec_null:
|
while rec_null:
|
||||||
answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1)
|
answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1)
|
||||||
client.publish("iiot/"+ myhost +"/gps", answer, 0)
|
|
||||||
if 1 == answer:
|
if 1 == answer:
|
||||||
answer = 0
|
answer = 0
|
||||||
if ',,,,,,' in rec_buff:
|
if ',,,,,,' in rec_buff:
|
||||||
gps_info = extract_gps_info(rec_buff)
|
print('GPS no está listo')
|
||||||
client.publish("iiot/" + myhost + "/gps", gps_info, 2)
|
rec_null = False
|
||||||
return True
|
time.sleep(1)
|
||||||
else:
|
|
||||||
print('GPS no está listo')
|
|
||||||
rec_null = False
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
else:
|
||||||
print('error %d'%answer)
|
print('error %d'%answer)
|
||||||
rec_buff = ''
|
rec_buff = ''
|
||||||
@ -66,11 +52,6 @@ def get_gps_position():
|
|||||||
return False
|
return False
|
||||||
time.sleep(1.5)
|
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):
|
def power_on(power_key):
|
||||||
print('SIM7600X is starting:')
|
print('SIM7600X is starting:')
|
||||||
@ -104,4 +85,4 @@ except:
|
|||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
if ser != None:
|
if ser != None:
|
||||||
ser.close()
|
ser.close()
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
@ -1,25 +1,106 @@
|
|||||||
Iniciando GPS
|
Iniciando GPS
|
||||||
AT+CGPS=1,1 ERROR
|
AT+CGPS=0
|
||||||
AT+CGPS=1,1 back: AT+CGPS=1,1
|
OK
|
||||||
ERROR
|
|
||||||
|
|
||||||
|
|
||||||
|
+CGPS: 0
|
||||||
AT+CGPSINFO
|
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
|
OK
|
||||||
|
|
||||||
AT+CGPSINFO
|
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
|
OK
|
||||||
|
|
||||||
AT+CGPSINFO
|
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
|
OK
|
||||||
|
|
||||||
AT+CGPSINFO
|
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
|
OK
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user