Co-authored-by: clajimbus <clajimbus@users.noreply.github.com>
This commit is contained in:
@@ -4,5 +4,4 @@
|
||||
#define I2C_BMP280_ADDRESS 0x76
|
||||
|
||||
void BMP280_Init();
|
||||
uint8_t BMP280_DataReady();
|
||||
void BMP280_Read();
|
||||
bool BMP280_Read(float &temperature, float &pressure, float &altitude);
|
||||
@@ -1,23 +1,14 @@
|
||||
<<<<<<< HEAD
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "json.hpp"
|
||||
#include "rest.hpp"
|
||||
#include "wifi.hpp"
|
||||
#include "test.hpp"
|
||||
#include "mqtt.hpp"
|
||||
|
||||
#define LED 2
|
||||
#define SERVER_IP "192.168.1.178"
|
||||
#define REST_PORT 80
|
||||
#define MQTT_PORT 1883
|
||||
=======
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "JsonTools.hpp"
|
||||
#include "RestClient.hpp"
|
||||
#include "WifiConnection.hpp"
|
||||
#include "MqttClient.hpp"
|
||||
#include "BMP280.hpp"
|
||||
|
||||
uint32_t getChipID();
|
||||
>>>>>>> main
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include "BMP280.h"
|
||||
|
||||
|
||||
void BMP280_Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t BMP280_DataReady()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BMP280_Read(float &temperature, float &humidity, float &pressure, float &altitude)
|
||||
{
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
#include "MQ7.h"
|
||||
#include "MQ7.hpp"
|
||||
|
||||
void MQ7_Init()
|
||||
{
|
||||
pinMode(digitalMQ7, INPUT);
|
||||
pinMode(analogMQ7, INPUT);
|
||||
pinMode(DIGITAL_MQ7, INPUT);
|
||||
pinMode(ANALOG_MQ7, INPUT);
|
||||
}
|
||||
|
||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
||||
{
|
||||
analogWrite(analogMQ7, 1023);
|
||||
analogWrite(ANALOG_MQ7, 1023);
|
||||
delay(60000);
|
||||
analogWrite(analogMQ7, (1023/5)*1.4 );
|
||||
analogWrite(ANALOG_MQ7, (1023/5)*1.4 );
|
||||
|
||||
for(int i = 0; i<100; i++)
|
||||
{
|
||||
sensorValue = sensorValue + analogRead(analogMQ7);
|
||||
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
||||
delay(90000);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ const uint32_t deviceId = getChipID();
|
||||
|
||||
// instances
|
||||
HTTPClient httpClient;
|
||||
BMP280_DEV bme;
|
||||
|
||||
// HTTP Request
|
||||
String response;
|
||||
@@ -13,21 +12,23 @@ String response;
|
||||
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