diff --git a/.DS_Store b/.DS_Store index 8600bca..5e8e073 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/location.py b/location.py index 357ae4c..9941273 100644 --- a/location.py +++ b/location.py @@ -2,53 +2,4 @@ import time import paho.mqtt.client as mqtt from tkinter import Tk, Button -from tkintermapview import TkinterMapView - -# MQTT settings -MQTT_BROKER = "broker.hivemq.com" -MQTT_PORT = 1883 -MQTT_TOPIC_LOCATION = "owntracks/DE/#" -MQTT_TOPIC_UPDATE = "home/location_updates" - -# Initialize MQTT client -client = mqtt.Client() - -# Variable to store the latest location -latest_location = None - -def on_connect(client, userdata, flags, rc): - print(f"Connected to MQTT broker with result code {rc}") - client.subscribe(MQTT_TOPIC_LOCATION) - -def on_message(client, userdata, msg): - global latest_location - try: - payload = json.loads(msg.payload) - if 'lat' in payload and 'lon' in payload: - latest_location = (payload['lat'], payload['lon']) - print(f"Updated location: {latest_location}") - publish_location() - except Exception as e: - print(f"Failed to parse MQTT message: {e}") - -def publish_location(): - global coordinates - if latest_location: - location_data = { - "latitude": latest_location[0], - "longitude": latest_location[1], - "timestamp": int(time.time()) - } - client.publish(MQTT_TOPIC_UPDATE, json.dumps(location_data)) - coordinates = location_data - -# Initialize coordinates with a default value -coordinates = {"latitude": 0.0, "longitude": 0.0} - -# Tkinter setup -window = Tk() -window.title("Map Viewer") -window.config(width=800, height=600) - -map_widget = TkinterMapView(window, width=800, height=600, corner_radius=0) -map_widget.place(relx=0.5, rely=0.5, anchor="center") +from tkintermapview import TkinterMapView \ No newline at end of file