|
@@ -8,6 +8,8 @@
|
|
|
#include "SPI.h"
|
|
#include "SPI.h"
|
|
|
#include "Arduino.h"
|
|
#include "Arduino.h"
|
|
|
#include "math.h"
|
|
#include "math.h"
|
|
|
|
|
+#include "WiFi.h"
|
|
|
|
|
+#include "WebServer.h"
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
Uncomment and set up if you want to use custom pins for the SPI communication
|
|
Uncomment and set up if you want to use custom pins for the SPI communication
|
|
@@ -66,6 +68,13 @@ SensorData datosAntiguos;
|
|
|
SemaphoreHandle_t dataMutex; // Mutex para proteger el acceso a latestData
|
|
SemaphoreHandle_t dataMutex; // Mutex para proteger el acceso a latestData
|
|
|
SemaphoreHandle_t buttonSemaphore; // Semáforo para la tarea del botón
|
|
SemaphoreHandle_t buttonSemaphore; // Semáforo para la tarea del botón
|
|
|
|
|
|
|
|
|
|
+WebServer server(80);
|
|
|
|
|
+
|
|
|
|
|
+bool wifiActivado = false;
|
|
|
|
|
+unsigned long wifiLastActivity = 0;
|
|
|
|
|
+const unsigned long WIFI_TIMEOUT_MS = 300000; // 5 minutos
|
|
|
|
|
+const char* apSSID = "ESP32_GPS_Logger";
|
|
|
|
|
+const char* apPassword = "12345678";
|
|
|
bool grabando = false; //inicia apagado
|
|
bool grabando = false; //inicia apagado
|
|
|
bool finalizado = true; //indica que no hay ninguna grabacion ni iniciada ni pausada
|
|
bool finalizado = true; //indica que no hay ninguna grabacion ni iniciada ni pausada
|
|
|
TaskHandle_t medicionesHandle = NULL; //para suspend/resume
|
|
TaskHandle_t medicionesHandle = NULL; //para suspend/resume
|
|
@@ -255,6 +264,61 @@ void cerrar_archivo() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void activarWiFi(){
|
|
|
|
|
+ OLED_print("WiFi","Activando...");
|
|
|
|
|
+
|
|
|
|
|
+ WiFi.mode(WIFI_AP);
|
|
|
|
|
+ WiFi.softAP(apSSID, apPassword);
|
|
|
|
|
+
|
|
|
|
|
+ IPAddress IP = WiFi.softAPIP();
|
|
|
|
|
+ OLED_print("WiFi Activo", IP.toString());
|
|
|
|
|
+ delay(2000);
|
|
|
|
|
+
|
|
|
|
|
+ server.on("/", HTTP_GET, []() {
|
|
|
|
|
+ wifiLastActivity = millis();
|
|
|
|
|
+ String html = "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>ESP32 GPS Logger</title>";
|
|
|
|
|
+ html += "<style>body{font-family:Arial;text-align:center;margin:50px;}";
|
|
|
|
|
+ html += "h1{color:#333;} a.button{background:#4CAF50;color:white;padding:20px 40px;";
|
|
|
|
|
+ html += "text-decoration:none;font-size:24px;border-radius:12px;display:inline-block;margin:20px;}</style></head>";
|
|
|
|
|
+ html += "<body><h1>GPS Logger</h1><p>Archivo listo para descargar:</p>";
|
|
|
|
|
+ html += "<a href='/download' class='button' download>Descargar " + String(filename).substring(1) + "</a>";
|
|
|
|
|
+ html += "<hr><p>IP: " + WiFi.softAPIP().toString() + "</p>";
|
|
|
|
|
+ html += "<p>Se apagará en 5 min sin uso.</p></body></html>";
|
|
|
|
|
+ server.send(200, "text/html", html);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ server.on("/download",HTTP_GET, []() {
|
|
|
|
|
+ wifiLastActivity = millis();
|
|
|
|
|
+
|
|
|
|
|
+ if (!SD.exists(filename)) {
|
|
|
|
|
+ server.send(404, "text/plain", "Archivo no encontrado");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ File file = SD.open(filename, FILE_READ);
|
|
|
|
|
+ if (!file) {
|
|
|
|
|
+ server.send(404, "text/plain", "Error al abrir el archivo");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ server.streamFile(file, "application/gpx+xml");
|
|
|
|
|
+ file.close();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ server.begin();
|
|
|
|
|
+ wifiActivado = true;
|
|
|
|
|
+ wifiLastActivity = millis();
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void desactivarWiFi(){
|
|
|
|
|
+ server.stop();
|
|
|
|
|
+ WiFi.softAPdisconnect(true);
|
|
|
|
|
+ WiFi.mode(WIFI_OFF);
|
|
|
|
|
+ wifiActivado = false;
|
|
|
|
|
+ OLED_print("WiFi","Apagado");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void IRAM_ATTR isr_button() {
|
|
void IRAM_ATTR isr_button() {
|
|
|
unsigned long now = millis();
|
|
unsigned long now = millis();
|
|
|
if (now < ignore_isr_until) {
|
|
if (now < ignore_isr_until) {
|
|
@@ -366,7 +430,12 @@ void task_ui(void *pvParameters){
|
|
|
finalizado = true;
|
|
finalizado = true;
|
|
|
break;
|
|
break;
|
|
|
case 2:
|
|
case 2:
|
|
|
- //implementacion blutuch
|
|
|
|
|
|
|
+ //implementacion wifi
|
|
|
|
|
+ if(!wifiActivado){
|
|
|
|
|
+ activarWiFi();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ desactivarWiFi();
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -384,7 +453,7 @@ void task_ui(void *pvParameters){
|
|
|
pantallaEstado_menu += 1;
|
|
pantallaEstado_menu += 1;
|
|
|
case 2:
|
|
case 2:
|
|
|
if (finalizado) {
|
|
if (finalizado) {
|
|
|
- OLED_print("Conexion","blutuch 'WIP'");
|
|
|
|
|
|
|
+ OLED_print("Conexion","wifi 'WIP'");
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
pantallaEstado_menu += 1;
|
|
pantallaEstado_menu += 1;
|
|
@@ -401,6 +470,18 @@ void task_ui(void *pvParameters){
|
|
|
display.ssd1306_command(SSD1306_DISPLAYOFF); //se apaga la pantalla
|
|
display.ssd1306_command(SSD1306_DISPLAYOFF); //se apaga la pantalla
|
|
|
pantallaOn = false;
|
|
pantallaOn = false;
|
|
|
}
|
|
}
|
|
|
|
|
+ //check wifi timeout
|
|
|
|
|
+ if (wifiActivado){
|
|
|
|
|
+ server.handleClient();
|
|
|
|
|
+
|
|
|
|
|
+ if (WiFi.softAPgetStationNum() > 0){
|
|
|
|
|
+ wifiLastActivity = millis(); //reset si hay clientes conectados
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ((millis() - wifiLastActivity) > WIFI_TIMEOUT_MS){
|
|
|
|
|
+ desactivarWiFi();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|