-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraffic_generator copy.py
More file actions
25 lines (22 loc) · 974 Bytes
/
Copy pathtraffic_generator copy.py
File metadata and controls
25 lines (22 loc) · 974 Bytes
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
import time
import random
from datetime import datetime
import requests
# Function to generate random traffic data
def generate_traffic_data():
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sensor_name = "Sensor2" # Adjust sensor name for VM2
car_types = ["Truck", "Sedan", "SUV", "Minivan", "Pickup"]
car_type = random.choice(car_types)
speed = random.randint(10, 150)
return f"<timestamp: {timestamp}, sensor name: {sensor_name}, car type: {car_type}, speed: {speed} kmph>"
# Main function to periodically generate and send traffic data
def main():
target_ip = "10.132.187.53" # IP address of the target machine (adjust as per your setup)
while True:
traffic_data = generate_traffic_data()
# Send traffic data to the target machine
requests.post(f"http://{target_ip}:5000/traffic_data", data=traffic_data)
time.sleep(5) # Data generated every 5 seconds
if __name__ == "__main__":
main()