Inicio del Django y base de datos

This commit is contained in:
adrigongv23 2026-02-17 13:39:49 +01:00
parent 57494f02e5
commit 0e0c8d7d1b
66 changed files with 647 additions and 69 deletions

View file

@ -2,34 +2,28 @@ import socket
import time
import math
import random
from datetime import datetime # <--- IMPORTANTE: Nueva librería
UDP_IP = "127.0.0.1"
# --- CONFIGURACIÓN ---
UDP_IP = "127.0.0.1"
UDP_PORT = 4210
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("TELEMETRÍA SIMULADA - ENVÍO DE DATOS")
print(" Formato: ECT | RPM | BATT | SPEED | HH:MM:SS")
print(f"--- SIMULADOR DE COCHE G26 ---")
print(f"Enviando datos falsos a {UDP_IP}:{UDP_PORT}")
t = 0
while True:
# Generación de datos (Igual que antes)
ect = 85 + (5 * math.sin(t / 5.0)) + random.uniform(-0.2, 0.2)
rpm = 3000 + (1000 * math.sin(t / 2.0))
batt = 13.8 + random.uniform(-0.1, 0.1)
speed = 90 + (30 * math.sin(t / 3.0))
# Generar una temperatura que sube y baja mucho para probar todos los colores
# Oscilará entre 40ºC y 120ºC
ect = 80 + (40 * math.sin(t / 10.0)) + random.uniform(-0.5, 0.5)
# --- CAMBIO AQUÍ: OBTENER HORA REAL ---
# Obtenemos hora actual y la convertimos a texto
hora_real = datetime.now().strftime("%H:%M:%S.%f")[:-3] # Hora con milisegundos
# Mensaje con la hora legible al final
mensaje = f"{ect:.2f}|{int(rpm)}|{batt:.2f}|{int(speed)}|{hora_real}"
# Enviar solo el número
mensaje = f"{ect:.2f}"
sock.sendto(mensaje.encode(), (UDP_IP, UDP_PORT))
print(f"TX: {mensaje}")
print(f"Simulando: {mensaje} °C")
t += 0.1
time.sleep(0.002)
time.sleep(0.05)