From d95089a294b1b7115d23c91f7ad7d514522afd9e Mon Sep 17 00:00:00 2001 From: Adolfo Delorenzo Date: Sat, 13 Jul 2024 12:42:04 -0600 Subject: [PATCH] 2024-07-13 - --- GPS.py | 98 ------------------------------------- GPS2.py | 118 --------------------------------------------- GPS3.py | 118 --------------------------------------------- gps.py | 98 ------------------------------------- gps2.py | 98 ------------------------------------- gps_coordinates.db | Bin 12288 -> 0 bytes 6 files changed, 530 deletions(-) delete mode 100755 GPS.py delete mode 100644 GPS2.py delete mode 100644 GPS3.py delete mode 100644 gps.py delete mode 100644 gps2.py delete mode 100644 gps_coordinates.db diff --git a/GPS.py b/GPS.py deleted file mode 100755 index d802cfc..0000000 --- a/GPS.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/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 - -def send_at(command,back,timeout): - rec_buff = '' - ser.write((command+'\r\n').encode()) - time.sleep(timeout) - if ser.inWaiting(): - time.sleep(0.01 ) - rec_buff = ser.read(ser.inWaiting()) - if rec_buff != '': - if back not in rec_buff.decode(): - print(command + ' ERROR') - print(command + ' back:\t' + rec_buff.decode()) - return 0 - else: - print(rec_buff.decode()) - return 1 - else: - print('GPS no está listo') - return 0 - -def get_gps_position(): - rec_null = True - answer = 0 - print('Iniciando GPS') - rec_buff = '' - send_at('AT+CGPS=1,1','OK',1) - 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: - print('GPS no está listo') - rec_null = False - time.sleep(1) - else: - print('error %d'%answer) - rec_buff = '' - send_at('AT+CGPS=0','OK',1) - return False - time.sleep(1.5) - - -def power_on(power_key): - print('SIM7600X is starting:') - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - GPIO.setup(power_key,GPIO.OUT) - time.sleep(0.1) - GPIO.output(power_key,GPIO.HIGH) - time.sleep(2) - GPIO.output(power_key,GPIO.LOW) - time.sleep(20) - ser.flushInput() - print('SIM7600X is ready') - -def power_down(power_key): - print('SIM7600X is loging off:') - GPIO.output(power_key,GPIO.HIGH) - time.sleep(3) - GPIO.output(power_key,GPIO.LOW) - time.sleep(18) - print('Good bye') - -try: - #power_on(power_key) - get_gps_position() - #power_down(power_key) -except: - if ser != None: - ser.close() - #power_down(power_key) - GPIO.cleanup() -if ser != None: - ser.close() - GPIO.cleanup() diff --git a/GPS2.py b/GPS2.py deleted file mode 100644 index 0950048..0000000 --- a/GPS2.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/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 - -def send_at(command,back,timeout): - rec_buff = '' - ser.write((command+'\r\n').encode()) - time.sleep(timeout) - if ser.inWaiting(): - time.sleep(0.01 ) - rec_buff = ser.read(ser.inWaiting()) - if rec_buff != '': - if back not in rec_buff.decode(): - print(command + ' ERROR') - print(command + ' back:\t' + rec_buff.decode()) - return 0 - else: - print(rec_buff.decode()) - return 1 - else: - print('GPS no está listo') - return 0 - -def get_gps_position(): - rec_null = True - answer = 0 - print('Iniciando GPS') - rec_buff = '' - send_at('AT+CGPS=1,1','OK',1) - time.sleep(2) - while rec_null: - answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1) - if 1 == answer: - answer = 0 - if ',,,,,,' in rec_buff: - print('GPS no está listo') - rec_null = False - time.sleep(1) - else: - # Parse GPS data - gps_data = rec_buff.decode().split('+CGPSINFO: ')[1].strip() - lat, lon = parse_gps_data(gps_data) - if lat and lon: - # Send GPS coordinates to MQTT broker - mqtt_payload = f"{lat},{lon}" - client.publish("iiot/"+ myhost +"/gps", mqtt_payload) - else: - print('error %d'%answer) - rec_buff = '' - send_at('AT+CGPS=0','OK',1) - return False - time.sleep(1.5) - -def parse_gps_data(gps_data): - parts = gps_data.split(',') - if len(parts) >= 4: - lat = convert_to_degrees(parts[0]) - lon = convert_to_degrees(parts[2]) - return lat, lon - return None, None - -def convert_to_degrees(raw_value): - if raw_value: - degree = float(raw_value[:2]) - minute = float(raw_value[2:]) - return degree + (minute / 60.0) - return None - -def power_on(power_key): - print('SIM7600X is starting:') - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - GPIO.setup(power_key,GPIO.OUT) - time.sleep(0.1) - GPIO.output(power_key,GPIO.HIGH) - time.sleep(2) - GPIO.output(power_key,GPIO.LOW) - time.sleep(20) - ser.flushInput() - print('SIM7600X is ready') - -def power_down(power_key): - print('SIM7600X is loging off:') - GPIO.output(power_key,GPIO.HIGH) - time.sleep(3) - GPIO.output(power_key,GPIO.LOW) - time.sleep(18) - print('Good bye') - -try: - #power_on(power_key) - get_gps_position() - #power_down(power_key) -except: - if ser != None: - ser.close() - #power_down(power_key) - GPIO.cleanup() -if ser != None: - ser.close() - GPIO.cleanup() diff --git a/GPS3.py b/GPS3.py deleted file mode 100644 index 5fa53c3..0000000 --- a/GPS3.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/python -# -*- coding:utf-8 -*- -import RPi.GPIO as GPIO -import serial -import time -import paho.mqtt.client as mqtt - -ser = serial.Serial('/dev/ttyS0', 115200) -ser.flushInput() - -# MQTT Configuration -MQTT_BROKER = "65.108.199.212" -MQTT_PORT = 1883 -MQTT_TOPIC = "gps/coordinates" - -# Create MQTT client -client = mqtt.Client() - -def connect_mqtt(): - client.connect(MQTT_BROKER, MQTT_PORT) - client.loop_start() - -def send_at(command, back, timeout): - rec_buff = '' - ser.write((command+'\r\n').encode()) - time.sleep(timeout) - if ser.inWaiting(): - time.sleep(0.01) - rec_buff = ser.read(ser.inWaiting()) - if rec_buff != '': - if back not in rec_buff.decode(): - print(command + ' ERROR') - print(command + ' back:\t' + rec_buff.decode()) - return 0, rec_buff - else: - print(rec_buff.decode()) - return 1, rec_buff - else: - print('GPS no está listo') - return 0, rec_buff - -def get_gps_position(): - rec_null = True - answer = 0 - print('Iniciando GPS') - send_at('AT+CGPS=1,1','OK',1) - time.sleep(2) - while rec_null: - answer, rec_buff = send_at('AT+CGPSINFO','+CGPSINFO: ',1) - if answer == 1: - if ',,,,,,' in rec_buff.decode(): - print('GPS no está listo') - else: - # Parse GPS data - gps_data = rec_buff.decode().split('+CGPSINFO: ')[1].strip() - lat, lon = parse_gps_data(gps_data) - if lat and lon: - # Send GPS coordinates to MQTT broker - mqtt_payload = f"{lat},{lon}" - client.publish(MQTT_TOPIC, mqtt_payload) - print(f"Sent to MQTT: {mqtt_payload}") - rec_null = False - else: - print('error %d'%answer) - send_at('AT+CGPS=0','OK',1) - return False - time.sleep(1.5) - -def parse_gps_data(gps_data): - parts = gps_data.split(',') - if len(parts) >= 4: - lat = convert_to_degrees(parts[0]) - lon = convert_to_degrees(parts[2]) - return lat, lon - return None, None - -def convert_to_degrees(raw_value): - if raw_value: - degree = float(raw_value[:2]) - minute = float(raw_value[2:]) - return degree + (minute / 60.0) - return None - -def power_on(power_key): - print('SIM7600X is starting:') - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - GPIO.setup(power_key,GPIO.OUT) - time.sleep(0.1) - GPIO.output(power_key,GPIO.HIGH) - time.sleep(2) - GPIO.output(power_key,GPIO.LOW) - time.sleep(20) - ser.flushInput() - print('SIM7600X is ready') - -def power_down(power_key): - print('SIM7600X is loging off:') - GPIO.output(power_key,GPIO.HIGH) - time.sleep(3) - GPIO.output(power_key,GPIO.LOW) - time.sleep(18) - print('Good bye') - -try: - power_key = 6 # Assuming power key is connected to GPIO 6 - connect_mqtt() - power_on(power_key) - get_gps_position() - power_down(power_key) -except Exception as e: - print(f"An error occurred: {e}") -finally: - if ser is not None: - ser.close() - client.loop_stop() - client.disconnect() - GPIO.cleanup() diff --git a/gps.py b/gps.py deleted file mode 100644 index 5e8264f..0000000 --- a/gps.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/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() - -power_key = 6 -rec_buff = '' -rec_buff2 = '' -time_count = 0 - -def send_at(command,back,timeout): - rec_buff = '' - ser.write((command+'\r\n').encode()) - time.sleep(timeout) - if ser.inWaiting(): - time.sleep(0.01 ) - rec_buff = ser.read(ser.inWaiting()) - if rec_buff != '': - if back not in rec_buff.decode(): - print(command + ' ERROR') - print(command + ' back:\t' + rec_buff.decode()) - return 0 - else: - print(rec_buff.decode()) - return 1 - else: - print('GPS is not ready') - return 0 - -def get_gps_position(): - rec_null = True - answer = 0 - print('Start GPS session...') - rec_buff = '' - send_at('AT+CGPS=1,1','OK',1) - time.sleep(2) - while rec_null: - answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1) - client.publish("iiot/"+ myhost +"/gps", answer) - if 1 == answer: - answer = 0 - if ',,,,,,' in rec_buff: - print('GPS is not ready') - rec_null = False - time.sleep(1) - else: - print('error %d'%answer) - rec_buff = '' - send_at('AT+CGPS=0','OK',1) - return False - time.sleep(1.5) - - -def power_on(power_key): - print('SIM7600X is starting:') - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - GPIO.setup(power_key,GPIO.OUT) - time.sleep(0.1) - GPIO.output(power_key,GPIO.HIGH) - time.sleep(2) - GPIO.output(power_key,GPIO.LOW) - time.sleep(20) - ser.flushInput() - print('SIM7600X is ready') - -def power_down(power_key): - print('SIM7600X is loging off:') - GPIO.output(power_key,GPIO.HIGH) - time.sleep(3) - GPIO.output(power_key,GPIO.LOW) - time.sleep(18) - print('Good bye') - -try: - power_on(power_key) - get_gps_position() - power_down(power_key) -except: - if ser != None: - ser.close() - power_down(power_key) - GPIO.cleanup() -if ser != None: - ser.close() - GPIO.cleanup() diff --git a/gps2.py b/gps2.py deleted file mode 100644 index 9d50aa7..0000000 --- a/gps2.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/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 - -def send_at(command,back,timeout): - rec_buff = '' - ser.write((command+'\r\n').encode()) - time.sleep(timeout) - if ser.inWaiting(): - time.sleep(0.01 ) - rec_buff = ser.read(ser.inWaiting()) - if rec_buff != '': - if back not in rec_buff.decode(): - print(command + ' ERROR') - print(command + ' back:\t' + rec_buff.decode()) - return 0 - else: - print(rec_buff.decode()) - return 1 - else: - print('GPS no está listo') - return 0 - -def get_gps_position(): - rec_null = True - answer = 0 - print('Iniciando GPS') - rec_buff = '' - send_at('AT+CGPS=1,1','OK',1) - 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: - print('GPS no está listo') - rec_null = False - time.sleep(1) - else: - print('error %d'%answer) - rec_buff = '' - send_at('AT+CGPS=0','OK',1) - return False - time.sleep(1.5) - - -def power_on(power_key): - print('SIM7600X is starting:') - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - GPIO.setup(power_key,GPIO.OUT) - time.sleep(0.1) - GPIO.output(power_key,GPIO.HIGH) - time.sleep(2) - GPIO.output(power_key,GPIO.LOW) - time.sleep(20) - ser.flushInput() - print('SIM7600X is ready') - -def power_down(power_key): - print('SIM7600X is loging off:') - GPIO.output(power_key,GPIO.HIGH) - time.sleep(3) - GPIO.output(power_key,GPIO.LOW) - time.sleep(18) - print('Good bye') - -try: - #power_on(power_key) - get_gps_position() - #power_down(power_key) -except: - if ser != None: - ser.close() - #power_down(power_key) - GPIO.cleanup() -if ser != None: - ser.close() - GPIO.cleanup() diff --git a/gps_coordinates.db b/gps_coordinates.db deleted file mode 100644 index c9b5c067772c96693b0e6dd65e29eb0a535ced1f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI#KTE?v7{~FuRCJQMb$y^qYm19-z$k}={x!xSlf>qfK%3C^y1Dcv_>R4Z#oEPH z%J+fG9ta%4@Y+WKOQth0