11
hardware/.vscode/settings.json
vendored
11
hardware/.vscode/settings.json
vendored
@@ -7,10 +7,17 @@
|
||||
"functional": "cpp",
|
||||
"tuple": "cpp",
|
||||
"utility": "cpp",
|
||||
"bmp280.h": "c"
|
||||
"bmp280.h": "c",
|
||||
"deque": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp"
|
||||
},
|
||||
"github.copilot.enable": {
|
||||
"*": false,
|
||||
"*": true,
|
||||
"plaintext": false,
|
||||
"markdown": false,
|
||||
"scminput": false,
|
||||
|
||||
BIN
hardware/docs/MAX7219.PDF
Normal file
BIN
hardware/docs/MAX7219.PDF
Normal file
Binary file not shown.
8
hardware/include/BME280.hpp
Normal file
8
hardware/include/BME280.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <Wire.h>
|
||||
#include <BME280I2C.h>
|
||||
|
||||
#define I2C_BME280_ADDRESS 0x76
|
||||
|
||||
void BME280_Init();
|
||||
bool BME280_DataReady();
|
||||
bool BME280_Read(float &pressure, float &temperature, float &humidity);
|
||||
7
hardware/include/GPS.hpp
Normal file
7
hardware/include/GPS.hpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "TinyGPSPlus.h"
|
||||
|
||||
#define RX 4
|
||||
#define TX 5
|
||||
|
||||
void GPS_Init();
|
||||
void GPS_Read(float &lat, float &lon);
|
||||
16
hardware/include/MAX7219.hpp
Normal file
16
hardware/include/MAX7219.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_MAX72XX.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
|
||||
#define MAX_DEVICES 4 // 4 modulos 8x8
|
||||
#define DATA_PIN 19
|
||||
#define CS_PIN 18
|
||||
#define CLK_PIN 17
|
||||
|
||||
void MAX7219_Init();
|
||||
void MAX7219_DisplayText(const char *text, textPosition_t align, int speed, int pause);
|
||||
void MAX7219_StartAnimation();
|
||||
void MAX7219_StopAnimation();
|
||||
void MAX7219_ClearDisplay();
|
||||
void MAX7219_SetBrightness(uint8_t brightness);
|
||||
@@ -4,4 +4,4 @@
|
||||
#define DIGITAL_MQ7 32
|
||||
|
||||
void MQ7_Init();
|
||||
void MQ7_Read();
|
||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue);
|
||||
@@ -1,23 +1,20 @@
|
||||
<<<<<<< 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 SERVER_IP "https://contaminus.miarma.net/api/v1/"
|
||||
#define REST_PORT 443
|
||||
#define MQTT_PORT 1883
|
||||
=======
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "JsonTools.hpp"
|
||||
#include "RestClient.hpp"
|
||||
#include "WifiConnection.hpp"
|
||||
#include "MqttClient.hpp"
|
||||
#include "BME280.hpp"
|
||||
#include "GPS.hpp"
|
||||
#include "MAX7219.hpp"
|
||||
#include "MQ7.hpp"
|
||||
|
||||
uint32_t getChipID();
|
||||
>>>>>>> main
|
||||
void prettyReadMQ7();
|
||||
void prettyReadBME280();
|
||||
void prettyReadGPS();
|
||||
void testMatrix();
|
||||
@@ -12,8 +12,11 @@
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
upload_port = COM3
|
||||
lib_deps =
|
||||
knolleary/PubSubClient@^2.8
|
||||
mikalhart/TinyGPSPlus@^1.0.2
|
||||
bblanchon/ArduinoJson@^6.17.3
|
||||
martinl1/BMP280_DEV@^1.0.21
|
||||
finitespace/BME280@^3.0.0
|
||||
majicdesigns/MD_MAX72XX@^3.5.1
|
||||
majicdesigns/MD_Parola@^3.7.3
|
||||
|
||||
35
hardware/src/lib/actuator/MAX7219.cpp
Normal file
35
hardware/src/lib/actuator/MAX7219.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "MAX7219.hpp"
|
||||
|
||||
MD_Parola display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
|
||||
|
||||
void MAX7219_Init()
|
||||
{
|
||||
display.begin();
|
||||
display.setIntensity(15); // 0-15
|
||||
display.displayClear();
|
||||
}
|
||||
|
||||
void MAX7219_DisplayText(const char *text, textPosition_t align, int speed, int pause)
|
||||
{
|
||||
display.displayText(text, align, speed, pause, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
|
||||
}
|
||||
|
||||
void MAX7219_StartAnimation()
|
||||
{
|
||||
display.displayAnimate();
|
||||
}
|
||||
|
||||
void MAX7219_StopAnimation()
|
||||
{
|
||||
display.displayReset();
|
||||
}
|
||||
|
||||
void MAX7219_ClearDisplay()
|
||||
{
|
||||
display.displayClear();
|
||||
}
|
||||
|
||||
void MAX7219_SetBrightness(uint8_t brightness)
|
||||
{
|
||||
display.setIntensity(brightness);
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "RestClient.hpp"
|
||||
|
||||
HTTPClient httpClient; // HTTP client object
|
||||
|
||||
void getRequest(HTTPClient &httpClient, const String url, String &response)
|
||||
void getRequest(const String url, String &response)
|
||||
{
|
||||
httpClient.begin(url);
|
||||
int httpCode = httpClient.GET();
|
||||
@@ -13,7 +14,7 @@ void getRequest(HTTPClient &httpClient, const String url, String &response)
|
||||
httpClient.end();
|
||||
}
|
||||
|
||||
void postRequest(HTTPClient &httpClient, const String url, String &payload, String &response)
|
||||
void postRequest(const String url, String &payload, String &response)
|
||||
{
|
||||
httpClient.begin(url);
|
||||
httpClient.addHeader("Content-Type", "application/json");
|
||||
34
hardware/src/lib/sensor/BME280.cpp
Normal file
34
hardware/src/lib/sensor/BME280.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "BME280.hpp"
|
||||
|
||||
BME280I2C bme;
|
||||
|
||||
void BME280_Init()
|
||||
{
|
||||
Wire.setPins(21, 22);
|
||||
Wire.begin();
|
||||
|
||||
BME280I2C::Settings settings(
|
||||
BME280I2C::OSR::OSR_X1,
|
||||
BME280I2C::OSR::OSR_X1,
|
||||
BME280I2C::OSR::OSR_X1,
|
||||
BME280I2C::Mode::Mode_Forced, // modo forzado
|
||||
BME280I2C::StandbyTime::StandbyTime_1000ms,
|
||||
BME280I2C::Filter::Filter_16,
|
||||
BME280I2C::SpiEnable::SpiEnable_False,
|
||||
BME280I2C::I2CAddr::I2CAddr_0x76 // dirección I2C del BME280
|
||||
);
|
||||
|
||||
bme.setSettings(settings);
|
||||
|
||||
while (!bme.begin());
|
||||
}
|
||||
|
||||
bool BME280_Read(float &pressure, float &temperature, float &humidity)
|
||||
{
|
||||
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
|
||||
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
|
||||
bme.read(pressure, temperature, humidity, tempUnit, presUnit);
|
||||
|
||||
return (temperature != 0.0f && pressure != 0.0f);
|
||||
}
|
||||
|
||||
22
hardware/src/lib/sensor/GPS.cpp
Normal file
22
hardware/src/lib/sensor/GPS.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "GPS.hpp"
|
||||
|
||||
TinyGPSPlus gps;
|
||||
|
||||
void GPS_Init()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void GPS_Read(float &lat, float &lon)
|
||||
{
|
||||
if (gps.location.isValid())
|
||||
{
|
||||
lat = gps.location.lat();
|
||||
lon = gps.location.lng();
|
||||
}
|
||||
else
|
||||
{
|
||||
lat = 0.0f;
|
||||
lon = 0.0f;
|
||||
}
|
||||
}
|
||||
26
hardware/src/lib/sensor/MQ7.cpp
Normal file
26
hardware/src/lib/sensor/MQ7.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#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)
|
||||
{
|
||||
// preheat
|
||||
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(1200);
|
||||
}
|
||||
|
||||
sensorValue = sensorValue/100.0;
|
||||
sensorVolt = sensorValue/1024*5.0;
|
||||
RSAir = (5.0-sensorVolt)/sensorVolt;
|
||||
R0 = RSAir/(26+(1/3));
|
||||
}
|
||||
@@ -2,42 +2,78 @@
|
||||
|
||||
const uint32_t deviceId = getChipID();
|
||||
|
||||
// instances
|
||||
HTTPClient httpClient;
|
||||
BMP280_DEV bme;
|
||||
extern HTTPClient httpClient; // HTTP client object
|
||||
String response; // HTTP Response
|
||||
float sensorVolt, sensorValue, RSAir, R0; // MQ7 vars
|
||||
float temperature, pressure, humidity; // BME280 vars
|
||||
float lon, lat; // GPS vars
|
||||
extern MD_Parola display; // Display object
|
||||
|
||||
// HTTP Request
|
||||
String response;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// MQ7
|
||||
float sensorVolt, sensorValue, RSAir, R0;
|
||||
/*Serial.println("Iniciando...");
|
||||
MQ7_Init();
|
||||
Serial.println("Sensor MQ7 inicializado");
|
||||
BME280_Init();
|
||||
Serial.println("Sensor BME280 inicializado");
|
||||
GPS_Init();
|
||||
Serial.println("GPS inicializado"); */
|
||||
MAX7219_Init();
|
||||
Serial.println("Display inicializado");
|
||||
|
||||
// BMP280
|
||||
float temperature, humidity, pressure, altitude;
|
||||
//prettyReadBME280();
|
||||
testMatrix();
|
||||
//prettyReadMQ7();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void prettyReadMQ7()
|
||||
{
|
||||
Serial.println("Leyendo sensor MQ7...");
|
||||
MQ7_Read(sensorVolt, RSAir, R0, sensorValue);
|
||||
Serial.print("\t - Voltaje: "); Serial.print(sensorVolt); Serial.print("V\r\n");
|
||||
Serial.print("\t - Valor sensor: "); Serial.print(sensorValue); Serial.print("\r\n");
|
||||
Serial.print("\t - Resistencia aire: "); Serial.print(RSAir); Serial.print("kOhm\r\n");
|
||||
Serial.print("\t - Resistencia aire: "); Serial.print(R0); Serial.print("kOhm\r\n");
|
||||
Serial.print("\t - Concentración CO: "); Serial.print(sensorValue); Serial.print("ppm\r\n");
|
||||
}
|
||||
|
||||
void prettyReadBME280()
|
||||
{
|
||||
Serial.println("Leyendo sensor BME280...");
|
||||
BME280_Read(pressure, temperature, humidity);
|
||||
Serial.print("\t - Presión: "); Serial.print(pressure/100); Serial.print("hPa\r\n");
|
||||
Serial.print("\t - Temperatura: "); Serial.print(temperature); Serial.print("°C\r\n");
|
||||
Serial.print("\t - Humedad: "); Serial.print(humidity); Serial.print("%\r\n");
|
||||
}
|
||||
|
||||
void prettyReadGPS()
|
||||
{
|
||||
Serial.println("Leyendo GPS...");
|
||||
GPS_Read(lat, lon);
|
||||
Serial.print("\t - Latitud: "); Serial.print(lat); Serial.print("\r\n");
|
||||
Serial.print("\t - Longitud: "); Serial.print(lon); Serial.print("\r\n");
|
||||
}
|
||||
|
||||
void testMatrix()
|
||||
{
|
||||
Serial.println("Escribiendo en el display...");
|
||||
MAX7219_DisplayText("Prueba de texto", PA_LEFT, 100, 500);
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// WiFi Connection
|
||||
if(setupWifi() != 0)
|
||||
{
|
||||
Serial.print("Error connecting to WiFi");
|
||||
}
|
||||
|
||||
// test get
|
||||
getRequest(httpClient, "http://172.20.10.7:8082/api/v1/sensors/1/values", response);
|
||||
deserializeSensorValue(httpClient, httpClient.GET());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user