diff --git a/G26-Telemetria.ino b/G26-Telemetria.ino index 4ddb9ae..23bde5a 100644 --- a/G26-Telemetria.ino +++ b/G26-Telemetria.ino @@ -6,15 +6,9 @@ #include "include/data_processor.hpp" -// --- CONFIGURACIÓN SD (HSPI, pines de la PCB validados por esquemático) --- -#define SD_CS 25 -#define SD_MOSI 26 -#define SD_SCK 27 -#define SD_MISO 14 - -SPIClass spiSD(HSPI); -#define SD_CONFIG SdSpiConfig(SD_CS, DEDICATED_SPI, SD_SCK_MHZ(1), &spiSD) - +// --- CONFIGURACIÓN SD (VSPI) --- +#define SD_CS_PIN 5 +#define SPI_CLOCK SD_SCK_MHZ(20) SdFat sd; SdFile logFile; @@ -28,44 +22,38 @@ void setup() { Serial.println("\n--- G26 TELEMETRY: INICIO DE SISTEMA ---"); // 1. INICIALIZACIÓN SD - spiSD.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS); - - if (!sd.begin(SD_CONFIG)) { + if (!sd.begin(SD_CS_PIN, SPI_CLOCK)) { Serial.println("[FALLO] SD no detectada. El sistema continuará sin Datalogging."); } else { - char filename[24]; - int session = 1; - bool opened = false; + if (logFile.open("G26.csv", O_RDWR | O_CREAT | O_APPEND)) { - while (!opened && session < 100000) { - snprintf(filename, sizeof(filename), "G26-%d.csv", session); - if (logFile.open(filename, O_RDWR | O_CREAT | O_EXCL)) { - opened = true; - Serial.printf("[OK] Nueva sesion: %s\n", filename); - } else { - session++; - } - } - - if (opened) { - logFile.println("Time,ECT,RPM,TPS,VBATT"); + // Si el archivo es nuevo (tamaño 0), escribimos la cabecera + if (logFile.fileSize() == 0) { + logFile.println("Time,ECT"); logFile.sync(); - } else { - Serial.println("[ERROR] No se pudo abrir archivo de sesion"); } + + // El archivo se queda abierto y listo. + Serial.println("[OK] Archivo abierto"); + + } else { + Serial.println("[ERROR] No se pudo abrir el archivo G26.csv"); + } } // 2. VINCULACIÓN + // Le damos al procesador acceso a la SD para que guarde cuando lleguen datos processor.setLogSystem(&sd, &logFile); can_interface.set_data_proccessor(&processor); // 3. INICIO CAN can_interface.start(); - can_interface.start_listening_task(); - + can_interface.start_listening_task(); // Escucha en Core 1 (Background) + Serial.println("[OK] Sistema ONLINE."); } void loop() { - delay(100); -} \ No newline at end of file + + delay(100); +} diff --git a/include/can.hpp b/include/can.hpp index 94467b2..7a03905 100644 --- a/include/can.hpp +++ b/include/can.hpp @@ -1,8 +1,8 @@ #ifndef CAN_HPP #define CAN_HPP -#define RX_PIN 23 -#define TX_PIN 22 +#define RX_PIN 13 +#define TX_PIN 38 #define POLLING_RATE_MS 1000 #define TRANSMIT_RATE_MS 1000 diff --git a/include/data_processor.hpp b/include/data_processor.hpp index f5c05d3..33b4992 100644 --- a/include/data_processor.hpp +++ b/include/data_processor.hpp @@ -9,11 +9,7 @@ public: // Estructura de datos struct CarState { - int ect = 0; - int rpm = 0; - int tps = 0; - double vbatt = 0; - + int ect = 0; // Temperatura (IMPORTANTE POR AHORA). Luego habría que añadir aquí todas las variables que se vallan a guardar. }; // Configuración SD diff --git a/index.html b/index.html new file mode 100644 index 0000000..886c04d --- /dev/null +++ b/index.html @@ -0,0 +1,254 @@ + + + + + Telemetría IoT - Sesiones + + + + +
+

🔬 Telemetría IoT

+
❌ Sesión Inactiva
+
--- kg
+
Socket: desconocido
+ +
+
Ventanas recibidas
0
+
Muestras totales
0
+
Última actualización
---
+
+ +
+ + + +
+ +
+
+ + + + + + + diff --git a/src/can.cpp b/src/can.cpp index bb076e1..f4ef323 100644 --- a/src/can.cpp +++ b/src/can.cpp @@ -11,7 +11,7 @@ static bool driver_installed = false; void CAN::start() { Serial.println("Starting CAN Controller..."); twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)TX_PIN, (gpio_num_t)RX_PIN, TWAI_MODE_NORMAL); - twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); + twai_timing_config_t t_config = TWAI_TIMING_CONFIG_125KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); esp_err_t install_status = twai_driver_install(&g_config, &t_config, &f_config); diff --git a/src/data_processor.cpp b/src/data_processor.cpp index 7305ef1..bfc23b1 100644 --- a/src/data_processor.cpp +++ b/src/data_processor.cpp @@ -6,14 +6,10 @@ void DataProcessor::send_serial_frame_0(int rpmh, int rpml, int tpsh, int tpsl, car.ect = ect; // GUARDAR LA VARIABLE DEL FRAME EN LA ESTRUCTURA - int rpm = (rpmh * 256) + rpml; - car.rpm = rpm; - - int tps = (tpsh * 256) + tpsl; - car.tps = tps; - - double vbatt = ((vbatth * 256) + vbattl) / 100.0; - car.vbatt = vbatt; + // El resto de variables no son relevantes ahora, se quedan comentadas para ahorrar memoria + // int rpm = (rpmh * 256) + rpml; + // int tps = (tpsh * 256) + tpsl; + // double vbatt = ((vbatth * 256) + vbattl) / 100.0; // 2. Escribimos en la SD flushToSD();