|
@@ -57,6 +57,7 @@ struct SensorData {
|
|
|
double longitude = 0.0;
|
|
double longitude = 0.0;
|
|
|
float altura = 0.0;
|
|
float altura = 0.0;
|
|
|
String tiempo = "";
|
|
String tiempo = "";
|
|
|
|
|
+ float velocidad = 0.0;
|
|
|
float temperature = 0.0;
|
|
float temperature = 0.0;
|
|
|
float humidity = 0.0;
|
|
float humidity = 0.0;
|
|
|
float pressure = 0.0;
|
|
float pressure = 0.0;
|
|
@@ -83,7 +84,7 @@ int pantallaEstado_menu = -1; //maquina de estados cuando no se esta grabando ru
|
|
|
float distancia_total = 0.0;
|
|
float distancia_total = 0.0;
|
|
|
volatile unsigned long ignore_isr_until = 0; //para debounce
|
|
volatile unsigned long ignore_isr_until = 0; //para debounce
|
|
|
|
|
|
|
|
-char filename[13];
|
|
|
|
|
|
|
+char filename[13] = "/panchas.gpx";
|
|
|
|
|
|
|
|
void OLED_print(const String& line1, const String& line2) {
|
|
void OLED_print(const String& line1, const String& line2) {
|
|
|
display.clearDisplay();
|
|
display.clearDisplay();
|
|
@@ -151,15 +152,25 @@ if (!SD.begin()) {
|
|
|
|
|
|
|
|
void GPS_test_wait() {
|
|
void GPS_test_wait() {
|
|
|
// Iniciar Serial2 para GPS
|
|
// Iniciar Serial2 para GPS
|
|
|
|
|
+ bool fixObtained = false;
|
|
|
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RX_PIN, TX_PIN);
|
|
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RX_PIN, TX_PIN);
|
|
|
- while (((gpsSerial.available() > 0) && gps.location.isValid()) && (gps.speed.age() < 2000)) {
|
|
|
|
|
- gps.encode(gpsSerial.read());
|
|
|
|
|
- delay(100);
|
|
|
|
|
- OLED_print("GPS", "Esperando.");
|
|
|
|
|
- delay(100);
|
|
|
|
|
- OLED_print("GPS", "Esperando..");
|
|
|
|
|
- delay(100);
|
|
|
|
|
- OLED_print("GPS", "Esperando...");
|
|
|
|
|
|
|
+ while (!fixObtained) {
|
|
|
|
|
+ while (gpsSerial.available() > 0) {
|
|
|
|
|
+ if (gps.encode(gpsSerial.read())) { // Procesa si hay sentencia NMEA completa
|
|
|
|
|
+ if (gps.location.isValid() && gps.date.isValid() && gps.time.isValid() && gps.satellites.value() >= 3 && gps.hdop.value() < 50) {
|
|
|
|
|
+ fixObtained = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ delay(300);
|
|
|
|
|
+ OLED_print("GPS", "Esperando");
|
|
|
|
|
+ delay(300);
|
|
|
|
|
+ OLED_print("GPS", "Esperando .");
|
|
|
|
|
+ delay(300);
|
|
|
|
|
+ OLED_print("GPS", "Esperando ..");
|
|
|
|
|
+ delay(300);
|
|
|
|
|
+ OLED_print("GPS", "Esperando ...");
|
|
|
}
|
|
}
|
|
|
OLED_print("GPS", "Encontrado");
|
|
OLED_print("GPS", "Encontrado");
|
|
|
}
|
|
}
|
|
@@ -190,6 +201,7 @@ void task_mediciones(void *pvParameters) {
|
|
|
String(gps.date.day())+"T"+String(gps.time.hour())+":"+
|
|
String(gps.date.day())+"T"+String(gps.time.hour())+":"+
|
|
|
String(gps.time.minute())+":"+String(gps.time.second())+"."+
|
|
String(gps.time.minute())+":"+String(gps.time.second())+"."+
|
|
|
String(gps.time.centisecond());
|
|
String(gps.time.centisecond());
|
|
|
|
|
+ float new_speed = gps.speed.kmph();
|
|
|
float new_temp = dht.readTemperature();
|
|
float new_temp = dht.readTemperature();
|
|
|
float new_hum = dht.readHumidity();
|
|
float new_hum = dht.readHumidity();
|
|
|
float new_press = 0.0; // Placeholder, no hay sensor de presión
|
|
float new_press = 0.0; // Placeholder, no hay sensor de presión
|
|
@@ -203,6 +215,7 @@ void task_mediciones(void *pvParameters) {
|
|
|
latestData.longitude = new_longitude;
|
|
latestData.longitude = new_longitude;
|
|
|
latestData.altura = new_altitude;
|
|
latestData.altura = new_altitude;
|
|
|
latestData.tiempo = new_fecha;
|
|
latestData.tiempo = new_fecha;
|
|
|
|
|
+ latestData.velocidad = new_speed;
|
|
|
latestData.temperature = new_temp;
|
|
latestData.temperature = new_temp;
|
|
|
latestData.humidity = new_hum;
|
|
latestData.humidity = new_hum;
|
|
|
latestData.pressure = new_press;
|
|
latestData.pressure = new_press;
|
|
@@ -227,6 +240,10 @@ void task_mediciones(void *pvParameters) {
|
|
|
file.print(datosAntiguos.tiempo);
|
|
file.print(datosAntiguos.tiempo);
|
|
|
file.println(F("</time>"));
|
|
file.println(F("</time>"));
|
|
|
|
|
|
|
|
|
|
+ file.print(F("\t\t\t\t<speed>"));
|
|
|
|
|
+ file.print(datosAntiguos.velocidad);
|
|
|
|
|
+ file.println(F("</speed>"));
|
|
|
|
|
+
|
|
|
file.println(F("\t\t\t\t<extensions>"));
|
|
file.println(F("\t\t\t\t<extensions>"));
|
|
|
file.println(F("\t\t\t\t\t<gpxtpx:TrackPointExtension>"));
|
|
file.println(F("\t\t\t\t\t<gpxtpx:TrackPointExtension>"));
|
|
|
file.print(F("\t\t\t\t\t\t<gpxtpx:atemp>"));
|
|
file.print(F("\t\t\t\t\t\t<gpxtpx:atemp>"));
|
|
@@ -245,8 +262,6 @@ void task_mediciones(void *pvParameters) {
|
|
|
file.println(F("\t\t\t\t</extensions>"));
|
|
file.println(F("\t\t\t\t</extensions>"));
|
|
|
file.println(F("\t\t\t</trkpt>"));
|
|
file.println(F("\t\t\t</trkpt>"));
|
|
|
|
|
|
|
|
- // Escribir datos en el archivo
|
|
|
|
|
- file.println(frase);
|
|
|
|
|
file.close();
|
|
file.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -255,6 +270,7 @@ void task_mediciones(void *pvParameters) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void crear_archivo(){
|
|
void crear_archivo(){
|
|
|
|
|
+ distancia_total = 0.0;
|
|
|
int num = 1;
|
|
int num = 1;
|
|
|
sprintf(filename, "/data%03d.gpx", num);
|
|
sprintf(filename, "/data%03d.gpx", num);
|
|
|
while (SD.exists(filename)) {
|
|
while (SD.exists(filename)) {
|
|
@@ -271,6 +287,14 @@ void crear_archivo(){
|
|
|
"\txmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v2\"\n"
|
|
"\txmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v2\"\n"
|
|
|
"\txmlns:gpxdata=\"http://www.cluetrust.com/XML/GPXDATA/1/0\"\n"
|
|
"\txmlns:gpxdata=\"http://www.cluetrust.com/XML/GPXDATA/1/0\"\n"
|
|
|
"\txsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
|
|
"\txsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
|
|
|
|
|
+ "\t<metadata>\n"
|
|
|
|
|
+ "\t\t<name>Ruta grabada con ESP32 GPS Logger</name>\n"
|
|
|
|
|
+ "\t\t<time>");
|
|
|
|
|
+ file.print(String(gps.date.year()) + "-" + String(gps.date.month()) + "-" +
|
|
|
|
|
+ String(gps.date.day()) + "T" + String(gps.time.hour()) + ":" +
|
|
|
|
|
+ String(gps.time.minute()) + ":" + String(gps.time.second()) +
|
|
|
|
|
+ "." + String(gps.time.centisecond()));
|
|
|
|
|
+ file.println("</time>\n\t</metadata>\n"
|
|
|
"\t<trk>\n"
|
|
"\t<trk>\n"
|
|
|
"\t\t<name>Rutita</name>\n"
|
|
"\t\t<name>Rutita</name>\n"
|
|
|
"\t\t<type>hiking</type>\n"
|
|
"\t\t<type>hiking</type>\n"
|
|
@@ -278,6 +302,7 @@ void crear_archivo(){
|
|
|
file.close();
|
|
file.close();
|
|
|
} else {
|
|
} else {
|
|
|
OLED_print("Error","creando archivo");
|
|
OLED_print("Error","creando archivo");
|
|
|
|
|
+ delay(2000);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -287,12 +312,12 @@ void cerrar_archivo() {
|
|
|
file.print("\t\t</trkseg>\n\t</trk>\n</gpx>");
|
|
file.print("\t\t</trkseg>\n\t</trk>\n</gpx>");
|
|
|
file.close();
|
|
file.close();
|
|
|
}
|
|
}
|
|
|
- int num = 1;
|
|
|
|
|
- sprintf(filename, "/data%03d.gpx", num);
|
|
|
|
|
- while (SD.exists(filename)) {
|
|
|
|
|
- num++;
|
|
|
|
|
- sprintf(filename, "/data%03d.gpx", num);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //int num = 1;
|
|
|
|
|
+ //sprintf(filename, "/data%03d.gpx", num);
|
|
|
|
|
+ //while (SD.exists(filename)) {
|
|
|
|
|
+ // num++;
|
|
|
|
|
+ // sprintf(filename, "/data%03d.gpx", num);
|
|
|
|
|
+ //}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void activarWiFi(){
|
|
void activarWiFi(){
|
|
@@ -312,7 +337,8 @@ void activarWiFi(){
|
|
|
html += "h1{color:#333;} a.button{background:#4CAF50;color:white;padding:20px 40px;";
|
|
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 += "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 += "<body><h1>GPS Logger</h1><p>Archivo listo para descargar:</p>";
|
|
|
- html += "<a href='/download' class='button' download>Descargar " + String(filename).substring(1) + "</a>";
|
|
|
|
|
|
|
+ String nombreArchivo = String(filename).substring(1); // Ej. "data001.gpx"
|
|
|
|
|
+ html += "<a href='/download' class='button' download='" + nombreArchivo + "'>Descargar " + nombreArchivo + "</a>";
|
|
|
html += "<hr><p>IP: " + WiFi.softAPIP().toString() + "</p>";
|
|
html += "<hr><p>IP: " + WiFi.softAPIP().toString() + "</p>";
|
|
|
html += "<p>Se apagará en 5 min sin uso.</p></body></html>";
|
|
html += "<p>Se apagará en 5 min sin uso.</p></body></html>";
|
|
|
server.send(200, "text/html", html);
|
|
server.send(200, "text/html", html);
|
|
@@ -332,6 +358,9 @@ void activarWiFi(){
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ String nombreArchivo = String(filename).substring(1); // Ej. "data001.gpx"
|
|
|
|
|
+ server.sendHeader("Content-Disposition", "attachment; filename=\"" + nombreArchivo + "\"");
|
|
|
|
|
+
|
|
|
server.streamFile(file, "application/gpx+xml");
|
|
server.streamFile(file, "application/gpx+xml");
|
|
|
file.close();
|
|
file.close();
|
|
|
});
|
|
});
|
|
@@ -454,6 +483,7 @@ void task_ui(void *pvParameters){
|
|
|
vTaskResume(medicionesHandle);
|
|
vTaskResume(medicionesHandle);
|
|
|
OLED_print("Ruta","iniciada");
|
|
OLED_print("Ruta","iniciada");
|
|
|
finalizado = false;
|
|
finalizado = false;
|
|
|
|
|
+ grabando = true;
|
|
|
break;
|
|
break;
|
|
|
case 1:
|
|
case 1:
|
|
|
//cerrar el archivo y cambiar el valor de 'filename'
|
|
//cerrar el archivo y cambiar el valor de 'filename'
|
|
@@ -471,23 +501,31 @@ void task_ui(void *pvParameters){
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
|
|
pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
|
|
|
- switch (pantallaEstado_menu){
|
|
|
|
|
- case 0:
|
|
|
|
|
- if (!finalizado) OLED_print("Reanudar","ruta");
|
|
|
|
|
- else OLED_print("Iniciar","ruta");
|
|
|
|
|
- break;
|
|
|
|
|
- case 1:
|
|
|
|
|
- if (SD.exists(filename)) {
|
|
|
|
|
- OLED_print("Finalizar","ruta");
|
|
|
|
|
|
|
+ int previous_state = -1;
|
|
|
|
|
+ while (pantallaEstado_menu != previous_state) {
|
|
|
|
|
+ previous_state = pantallaEstado_menu;
|
|
|
|
|
+ switch (pantallaEstado_menu) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ if (!finalizado) OLED_print("Reanudar","ruta");
|
|
|
|
|
+ else OLED_print("Iniciar","ruta");
|
|
|
break;
|
|
break;
|
|
|
- }
|
|
|
|
|
- pantallaEstado_menu += 1;
|
|
|
|
|
- case 2:
|
|
|
|
|
- if (finalizado) {
|
|
|
|
|
- OLED_print("Conexion","wifi 'WIP'");
|
|
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ if (SD.exists(filename) && !finalizado) {
|
|
|
|
|
+ OLED_print("Finalizar","ruta");
|
|
|
|
|
+ break;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
- }
|
|
|
|
|
- pantallaEstado_menu += 1;
|
|
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ if (finalizado) {
|
|
|
|
|
+ OLED_print("Conexion","WiFi");
|
|
|
|
|
+ break;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|