Co-authored-by: clajimbus <clajimbus@users.noreply.github.com>
This commit is contained in:
25
hardware/src/BMP280.cpp
Normal file
25
hardware/src/BMP280.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "BMP280.hpp"
|
||||
|
||||
BMP280_DEV bme;
|
||||
|
||||
void BMP280_Init()
|
||||
{
|
||||
Wire.setPins(21, 22);
|
||||
if (!bme.begin(NORMAL_MODE, I2C_BMP280_ADDRESS))
|
||||
{
|
||||
Serial.println("BMP280 no detectado o error en la inicialización");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("BMP280 inicializado correctamente");
|
||||
}
|
||||
bme.setTimeStandby(TIME_STANDBY_2000MS);
|
||||
bme.startNormalConversion();
|
||||
}
|
||||
|
||||
bool BMP280_Read(float &temperature, float &pressure, float &altitude)
|
||||
{
|
||||
bme.getCurrentMeasurements(temperature, pressure, altitude);
|
||||
return (temperature != 0.0f && pressure != 0.0f);
|
||||
}
|
||||
|
||||
30
hardware/src/MQ7.cpp
Normal file
30
hardware/src/MQ7.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "MQ7.hpp"
|
||||
|
||||
void MQ7_Init()
|
||||
{
|
||||
pinMode(DIGITAL_MQ7, INPUT);
|
||||
pinMode(ANALOG_MQ7, INPUT);
|
||||
}
|
||||
|
||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
||||
{
|
||||
analogWrite(ANALOG_MQ7, 1023);
|
||||
delay(60000);
|
||||
analogWrite(ANALOG_MQ7, (1023/5)*1.4 );
|
||||
|
||||
for(int i = 0; i<100; i++)
|
||||
{
|
||||
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
||||
delay(90000);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -4,30 +4,31 @@ const uint32_t deviceId = getChipID();
|
||||
|
||||
// instances
|
||||
HTTPClient httpClient;
|
||||
BMP280_DEV bme;
|
||||
|
||||
// HTTP Request
|
||||
String response;
|
||||
|
||||
// MQ7
|
||||
float sensorVolt, sensorValue, RSAir, R0;
|
||||
float sensorVolt, sensorValue, RSAir, R0;
|
||||
|
||||
// BMP280
|
||||
float temperature, humidity, pressure, altitude;
|
||||
float temperature, pressure, altitude;
|
||||
|
||||
uint32_t getChipID()
|
||||
{
|
||||
uint32_t chipId;
|
||||
for (int i = 0; i < 17; i = i + 8) {
|
||||
for (int i = 0; i < 17; i = i + 8)
|
||||
{
|
||||
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
||||
}
|
||||
return chipId;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// WiFi Connection
|
||||
/*// WiFi Connection
|
||||
if(setupWifi() != 0)
|
||||
{
|
||||
Serial.print("Error connecting to WiFi");
|
||||
@@ -35,9 +36,26 @@ void setup() {
|
||||
|
||||
// test get
|
||||
getRequest(httpClient, "http://172.20.10.7:8082/api/v1/sensors/1/values", response);
|
||||
deserializeSensorValue(httpClient, httpClient.GET());
|
||||
deserializeSensorValue(httpClient, httpClient.GET()); */
|
||||
|
||||
BMP280_Init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (BMP280_Read(temperature, pressure, altitude))
|
||||
{
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Pressure: ");
|
||||
Serial.println(pressure);
|
||||
Serial.print("Altitude: ");
|
||||
Serial.println(altitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("❌ Lectura fallida del BMP280");
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
Reference in New Issue
Block a user