-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummy_gps_data.py
116 lines (95 loc) · 2.78 KB
/
dummy_gps_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import argparse
import json
import os
import time
import pika
def get_rabbitmq_connection():
rabbitmq_user = os.environ.get("RABBITMQ_DEFAULT_USER", "user")
rabbitmq_password = os.environ.get("RABBITMQ_DEFAULT_PASS", "pass")
credentials = pika.PlainCredentials(rabbitmq_user, rabbitmq_password)
parameters = pika.ConnectionParameters(
host="localhost", port=5672, credentials=credentials
)
connection = pika.BlockingConnection(parameters)
return connection
def publish_to_rabbitmq(connection, message):
try:
channel = connection.channel()
channel.exchange_declare(exchange="ue_coordinates", exchange_type="topic")
channel.basic_publish(
exchange="ue_coordinates", routing_key="gps_data", body=json.dumps(message)
)
print(" [x] Sent message:", message)
except Exception as e:
print("Error publishing message to RabbitMQ:", e)
def simulate_movement(
supi,
initial_lat,
initial_lon,
update_interval=1,
lat_increment=0.0001,
lon_increment=0.0001,
):
connection = get_rabbitmq_connection()
lat = initial_lat
lon = initial_lon
try:
while True:
lat += lat_increment
lon += lon_increment
message = {"supi": supi, "lat": lat, "lon": lon}
publish_to_rabbitmq(connection, message)
time.sleep(update_interval)
except KeyboardInterrupt:
print("Simulation stopped.")
finally:
connection.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Simulate UE GPS coordinates and publish to RabbitMQ"
)
parser.add_argument(
"--supi",
type=str,
default="202010000000009",
help="SUPI value (default: %(default)s)",
)
parser.add_argument(
"--initial_lat",
type=float,
default=37.998202,
help="Initial latitude (default: %(default)s)",
)
parser.add_argument(
"--initial_lon",
type=float,
default=23.819648,
help="Initial longitude (default: %(default)s)",
)
parser.add_argument(
"--update_interval",
type=int,
default=1,
help="Update interval (default: %(default)s)",
)
parser.add_argument(
"--lat_increment",
type=float,
default=0.0001,
help="Latitude increment (default: %(default)s)",
)
parser.add_argument(
"--lon_increment",
type=float,
default=0.0001,
help="Longitude increment (default: %(default)s)",
)
args = parser.parse_args()
simulate_movement(
args.supi,
args.initial_lat,
args.initial_lon,
args.update_interval,
args.lat_increment,
args.lon_increment,
)