1
0

Refactor BMP280 header inclusion and enhance MQ7 reading logic; update main loop to include GPS data retrieval and post request

This commit is contained in:
AlejandroJose2001
2025-04-24 17:04:08 +02:00
parent 9da30e9e79
commit 2e425a04f9
3 changed files with 31 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
#include "BMP280.h" #include "BMP280.hpp"
void BMP280_Init() void BMP280_Init()

View File

@@ -1,5 +1,9 @@
#include "MQ7.hpp" #include "MQ7.hpp"
unsigned long tiempoAnterior = 0;
const long intervalo1 = 60000;
const long intervalo2 = 3000;
void MQ7_Init() void MQ7_Init()
{ {
pinMode(DIGITAL_MQ7, INPUT); pinMode(DIGITAL_MQ7, INPUT);
@@ -8,23 +12,29 @@ void MQ7_Init()
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue) void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
{ {
analogWrite(ANALOG_MQ7, 1023); unsigned long tiempoActual = millis();
delay(60000);
analogWrite(ANALOG_MQ7, (1023/5)*1.4);
for(int i = 0; i<100; i++) if (tiempoActual - tiempoAnterior >= intervalo1){
tiempoAnterior = tiempoActual;
analogWrite(ANALOG_MQ7, 1023);
analogWrite(ANALOG_MQ7, (1023/5)*1.4);
}
for(int i = 0; i<50; i++)
{ {
sensorValue = sensorValue + analogRead(ANALOG_MQ7); if (tiempoActual - tiempoAnterior >= intervalo1){
delay(90000); tiempoAnterior = tiempoActual;
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
}
} }
sensorValue = sensorValue/100.0; if (tiempoActual - tiempoAnterior >= intervalo1){
sensorVolt = sensorValue/1024*5.0; tiempoAnterior = tiempoActual;
RSAir = (5.0-sensorVolt)/sensorVolt; sensorValue = sensorValue/100.0;
R0 = RSAir/(26+(1/3)); sensorVolt = sensorValue/1024*5.0;
RSAir = (5.0-sensorVolt)/sensorVolt;
R0 = RSAir/(26+(1/3));
Serial.print("R0 = "); Serial.print("R0 = ");
Serial.println(R0); Serial.println(R0);
}
delay(1000);
} }

View File

@@ -8,6 +8,7 @@ BMP280_DEV bme;
// HTTP Request // HTTP Request
String response; String response;
const String url = "/api/v1/sensors/:sensorId/values";
// MQ7 // MQ7
float sensorVolt, sensorValue, RSAir, R0; float sensorVolt, sensorValue, RSAir, R0;
@@ -51,4 +52,6 @@ void loop() {
GPS_Read(); GPS_Read();
lon = GPS_longitud(); lon = GPS_longitud();
lat = GPS_latitud(); lat = GPS_latitud();
//postRequest(HTTPClient &httpClient, const String url, String &payload, String &response)
postRequest(httpClient, url, serializeSensorValue(), )
} }