mirror of
https://github.com/adrigongv23/G26---Telemetry-Software.git
synced 2026-08-25 11:33:17 +02:00
Inicio del Django y base de datos
This commit is contained in:
parent
57494f02e5
commit
0e0c8d7d1b
66 changed files with 647 additions and 69 deletions
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue