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:
@@ -1,4 +1,4 @@
|
|||||||
#include "BMP280.h"
|
#include "BMP280.hpp"
|
||||||
|
|
||||||
|
|
||||||
void BMP280_Init()
|
void BMP280_Init()
|
||||||
|
|||||||
@@ -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;
|
||||||
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
analogWrite(ANALOG_MQ7, 1023);
|
||||||
delay(90000);
|
analogWrite(ANALOG_MQ7, (1023/5)*1.4);
|
||||||
|
}
|
||||||
|
for(int i = 0; i<50; i++)
|
||||||
|
{
|
||||||
|
if (tiempoActual - tiempoAnterior >= intervalo1){
|
||||||
|
tiempoAnterior = tiempoActual;
|
||||||
|
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tiempoActual - tiempoAnterior >= intervalo1){
|
||||||
|
tiempoAnterior = tiempoActual;
|
||||||
|
sensorValue = sensorValue/100.0;
|
||||||
|
sensorVolt = sensorValue/1024*5.0;
|
||||||
|
RSAir = (5.0-sensorVolt)/sensorVolt;
|
||||||
|
R0 = RSAir/(26+(1/3));
|
||||||
|
|
||||||
|
Serial.print("R0 = ");
|
||||||
|
Serial.println(R0);
|
||||||
}
|
}
|
||||||
|
|
||||||
sensorValue = sensorValue/100.0;
|
|
||||||
sensorVolt = sensorValue/1024*5.0;
|
|
||||||
RSAir = (5.0-sensorVolt)/sensorVolt;
|
|
||||||
R0 = RSAir/(26+(1/3));
|
|
||||||
|
|
||||||
Serial.print("R0 = ");
|
|
||||||
Serial.println(R0);
|
|
||||||
|
|
||||||
delay(1000);
|
|
||||||
}
|
}
|
||||||
@@ -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(), )
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user