diff --git a/hardware/.vscode/settings.json b/hardware/.vscode/settings.json index 977f71d..18d3f86 100644 --- a/hardware/.vscode/settings.json +++ b/hardware/.vscode/settings.json @@ -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, diff --git a/hardware/docs/MAX7219.PDF b/hardware/docs/MAX7219.PDF new file mode 100644 index 0000000..7d8611c Binary files /dev/null and b/hardware/docs/MAX7219.PDF differ diff --git a/hardware/include/BME280.hpp b/hardware/include/BME280.hpp index 12ebfee..38efd2d 100644 --- a/hardware/include/BME280.hpp +++ b/hardware/include/BME280.hpp @@ -1,7 +1,8 @@ #include #include -#define I2C_BMP280_ADDRESS 0x76 +#define I2C_BME280_ADDRESS 0x76 void BME280_Init(); +bool BME280_DataReady(); bool BME280_Read(float &pressure, float &temperature, float &humidity); \ No newline at end of file diff --git a/hardware/include/GPS.hpp b/hardware/include/GPS.hpp new file mode 100644 index 0000000..91ca80e --- /dev/null +++ b/hardware/include/GPS.hpp @@ -0,0 +1,7 @@ +#include "TinyGPSPlus.h" + +#define RX 4 +#define TX 5 + +void GPS_Init(); +void GPS_Read(float &lat, float &lon); \ No newline at end of file diff --git a/hardware/include/MAX7219.hpp b/hardware/include/MAX7219.hpp new file mode 100644 index 0000000..c182911 --- /dev/null +++ b/hardware/include/MAX7219.hpp @@ -0,0 +1,17 @@ +#include +#include +#include + +#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); \ No newline at end of file diff --git a/hardware/include/MQ7.hpp b/hardware/include/MQ7.hpp index 8953d66..bc4fba6 100644 --- a/hardware/include/MQ7.hpp +++ b/hardware/include/MQ7.hpp @@ -4,4 +4,4 @@ #define DIGITAL_MQ7 32 void MQ7_Init(); -void MQ7_Read(); \ No newline at end of file +void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue); \ No newline at end of file diff --git a/hardware/include/main.hpp b/hardware/include/main.hpp index 808178f..71a20b0 100644 --- a/hardware/include/main.hpp +++ b/hardware/include/main.hpp @@ -1,8 +1,7 @@ #include -#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 "JsonTools.hpp" @@ -10,5 +9,12 @@ #include "WifiConnection.hpp" #include "MqttClient.hpp" #include "BME280.hpp" +#include "GPS.hpp" +#include "MAX7219.hpp" +#include "MQ7.hpp" -uint32_t getChipID(); \ No newline at end of file +uint32_t getChipID(); +void prettyReadMQ7(); +void prettyReadBME280(); +void prettyReadGPS(); +void testMatrix(); \ No newline at end of file diff --git a/hardware/platformio.ini b/hardware/platformio.ini index 47a0b97..bfae34c 100644 --- a/hardware/platformio.ini +++ b/hardware/platformio.ini @@ -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 finitespace/BME280@^3.0.0 + majicdesigns/MD_MAX72XX@^3.5.1 + majicdesigns/MD_Parola@^3.7.3 diff --git a/hardware/src/BME280.cpp b/hardware/src/BME280.cpp deleted file mode 100644 index f6f8fb4..0000000 --- a/hardware/src/BME280.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "BME280.hpp" - -BME280I2C bme; - -void BME280_Init() -{ - Wire.setPins(21, 22); - Wire.begin(); - while(!bme.begin()) - { - Serial.println("Could not find BME280 sensor!"); - delay(1000); - } -} - -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); -} - diff --git a/hardware/src/lib/actuator/MAX7219.cpp b/hardware/src/lib/actuator/MAX7219.cpp new file mode 100644 index 0000000..55be534 --- /dev/null +++ b/hardware/src/lib/actuator/MAX7219.cpp @@ -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(1); // 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); +} \ No newline at end of file diff --git a/hardware/src/JsonTools.cpp b/hardware/src/lib/http/JsonTools.cpp similarity index 96% rename from hardware/src/JsonTools.cpp rename to hardware/src/lib/http/JsonTools.cpp index 02b7989..e992e23 100644 --- a/hardware/src/JsonTools.cpp +++ b/hardware/src/lib/http/JsonTools.cpp @@ -1,179 +1,179 @@ -#include "JsonTools.hpp" - -String serializeSensorValue(int sensorId, int deviceId, String sensorType, String unit, int sensorStatus, float temperature, float humidity, float carbonMonoxide, float lat, float lon, long timestamp) -{ - DynamicJsonDocument doc(2048); - - doc["sensorId"] = sensorId; - doc["deviceId"] = deviceId; - doc["sensorType"] = sensorType; - doc["unit"] = unit; - doc["sesnsorStatuts"] = sensorStatus; - doc["temperature"] = temperature; - doc["humidity"] = humidity; - doc["carbonMonoxide"] = carbonMonoxide; - doc["lat"] = lat; - doc["lon"] = lon; - doc["timestamp"] = timestamp; - - String output; - serializeJson(doc, output); - Serial.println(output); - - return output; -} - -String serializeActuatorStatus (int actuatorId, int deviceId, int status, long timestamp) -{ - DynamicJsonDocument doc(2048); - - doc["actuatorId"] = actuatorId; - doc["deviceId"] = deviceId; - doc["status"] = status; - doc["timestamp"] = timestamp; - - String output; - serializeJson(doc, output); - Serial.println(output); - - return output; -} - -String serializeDevice(int sensorId, int deviceId, String sensorType, int status, long timestamp) -{ - DynamicJsonDocument doc(2048); - - doc["sensorId"] = sensorId; - doc["deviceId"] = deviceId; - doc["sensorType"] = sensorType; - doc["status"] = status; - doc["timestamp"] = timestamp; - - String output; - serializeJson(doc, output); - Serial.println(output); - - return output; -} - -void deserializeSensorValue (HTTPClient &http, int httpResponseCode) -{ - - if (httpResponseCode > 0) - { - Serial.print("HTTP Response code: "); - Serial.println(httpResponseCode); - String responseJson = http.getString(); - DynamicJsonDocument doc(ESP.getMaxAllocHeap()); - DeserializationError error = deserializeJson(doc, responseJson); - - if (error) - { - Serial.print(F("deserializeJson() failed: ")); - Serial.println(error.f_str()); - return; - } - - JsonArray array = doc.as(); - for (JsonObject sensor : array) - { - int sensorId = sensor["sensorId"]; - int deviceId = sensor["deviceId"]; - String sensorType = sensor["sensorType"]; - String unit = sensor["unit"]; - int sesnsorStatuts = sensor["sesnsorStatuts"]; - float temperature = sensor["temperature"]; - float humidity = sensor["humidity"]; - float carbonMonoxide = sensor["carbonMonoxide"]; - float lat = sensor["lat"]; - float lon = sensor["lon"]; - long timestamp = sensor["timestamp"]; - - Serial.println(("Sensor deserialized: [sensorId: " + String(sensorId) + ", deviceId: " + String(deviceId) + ", sensorType: " + sensorType + ", unit: " + unit +", sesnsorStatuts: " + String(sesnsorStatuts) +", temperature: " + String(temperature) +", humidity: " + String(humidity) +", carbonMonoxide: " + String(carbonMonoxide) +", lat: " + String(lat) +", lon: " + String(lon) +", timestamp: " + String(timestamp) + "]").c_str()); - } - } - else - { - Serial.print("Error code: "); - Serial.println(httpResponseCode); - } -} - -void deserializeActuatorStatus (HTTPClient &http, int httpResponseCode) -{ - - if (httpResponseCode > 0) - { - Serial.print("HTTP Response code: "); - Serial.println(httpResponseCode); - String responseJson = http.getString(); - DynamicJsonDocument doc(ESP.getMaxAllocHeap()); - DeserializationError error = deserializeJson(doc, responseJson); - - if (error) - { - Serial.print(F("deserializeJson() failed: ")); - Serial.println(error.f_str()); - return; - } - - JsonArray array = doc.as(); - for (JsonObject actuator : array) - { - int actuadorId = actuator["actuadorId"]; - int deviceId = actuator["deviceId"]; - int statuts = actuator["statuts"]; - long timestamp = actuator["timestamp"]; - - Serial.println(("Actuador deserialized: [actuadorId: " + String(actuadorId) + - ", deviceId: " + String(deviceId) + - ", statuts: " + String(statuts) + - ", timestamp: " + String(timestamp) + "]").c_str()); - } - } - else - { - Serial.print("Error code: "); - Serial.println(httpResponseCode); - } -} - -void deserializeDevice (HTTPClient &http, int httpResponseCode) -{ - - if (httpResponseCode > 0) - { - Serial.print("HTTP Response code: "); - Serial.println(httpResponseCode); - String responseJson = http.getString(); - DynamicJsonDocument doc(ESP.getMaxAllocHeap()); - DeserializationError error = deserializeJson(doc, responseJson); - - if (error) - { - Serial.print(F("deserializeJson() failed: ")); - Serial.println(error.f_str()); - return; - } - - JsonArray array = doc.as(); - for (JsonObject device : array) - { - int sensorId = device["sensorId"]; - int deviceId = device["deviceId"]; - String sensorType = device["sensorType"]; - long timestamp = device["timestamp"]; - - Serial.println(("Sensor deserialized: [sensorId: " + String(sensorId) + - ", deviceId: " + String(deviceId) + - ", sensorType: " + sensorType + - ", timestamp: " + String(timestamp) + "]").c_str()); - - } - } - else - { - Serial.print("Error code: "); - Serial.println(httpResponseCode); - } +#include "JsonTools.hpp" + +String serializeSensorValue(int sensorId, int deviceId, String sensorType, String unit, int sensorStatus, float temperature, float humidity, float carbonMonoxide, float lat, float lon, long timestamp) +{ + DynamicJsonDocument doc(2048); + + doc["sensorId"] = sensorId; + doc["deviceId"] = deviceId; + doc["sensorType"] = sensorType; + doc["unit"] = unit; + doc["sesnsorStatuts"] = sensorStatus; + doc["temperature"] = temperature; + doc["humidity"] = humidity; + doc["carbonMonoxide"] = carbonMonoxide; + doc["lat"] = lat; + doc["lon"] = lon; + doc["timestamp"] = timestamp; + + String output; + serializeJson(doc, output); + Serial.println(output); + + return output; +} + +String serializeActuatorStatus (int actuatorId, int deviceId, int status, long timestamp) +{ + DynamicJsonDocument doc(2048); + + doc["actuatorId"] = actuatorId; + doc["deviceId"] = deviceId; + doc["status"] = status; + doc["timestamp"] = timestamp; + + String output; + serializeJson(doc, output); + Serial.println(output); + + return output; +} + +String serializeDevice(int sensorId, int deviceId, String sensorType, int status, long timestamp) +{ + DynamicJsonDocument doc(2048); + + doc["sensorId"] = sensorId; + doc["deviceId"] = deviceId; + doc["sensorType"] = sensorType; + doc["status"] = status; + doc["timestamp"] = timestamp; + + String output; + serializeJson(doc, output); + Serial.println(output); + + return output; +} + +void deserializeSensorValue (HTTPClient &http, int httpResponseCode) +{ + + if (httpResponseCode > 0) + { + Serial.print("HTTP Response code: "); + Serial.println(httpResponseCode); + String responseJson = http.getString(); + DynamicJsonDocument doc(ESP.getMaxAllocHeap()); + DeserializationError error = deserializeJson(doc, responseJson); + + if (error) + { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.f_str()); + return; + } + + JsonArray array = doc.as(); + for (JsonObject sensor : array) + { + int sensorId = sensor["sensorId"]; + int deviceId = sensor["deviceId"]; + String sensorType = sensor["sensorType"]; + String unit = sensor["unit"]; + int sesnsorStatuts = sensor["sesnsorStatuts"]; + float temperature = sensor["temperature"]; + float humidity = sensor["humidity"]; + float carbonMonoxide = sensor["carbonMonoxide"]; + float lat = sensor["lat"]; + float lon = sensor["lon"]; + long timestamp = sensor["timestamp"]; + + Serial.println(("Sensor deserialized: [sensorId: " + String(sensorId) + ", deviceId: " + String(deviceId) + ", sensorType: " + sensorType + ", unit: " + unit +", sesnsorStatuts: " + String(sesnsorStatuts) +", temperature: " + String(temperature) +", humidity: " + String(humidity) +", carbonMonoxide: " + String(carbonMonoxide) +", lat: " + String(lat) +", lon: " + String(lon) +", timestamp: " + String(timestamp) + "]").c_str()); + } + } + else + { + Serial.print("Error code: "); + Serial.println(httpResponseCode); + } +} + +void deserializeActuatorStatus (HTTPClient &http, int httpResponseCode) +{ + + if (httpResponseCode > 0) + { + Serial.print("HTTP Response code: "); + Serial.println(httpResponseCode); + String responseJson = http.getString(); + DynamicJsonDocument doc(ESP.getMaxAllocHeap()); + DeserializationError error = deserializeJson(doc, responseJson); + + if (error) + { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.f_str()); + return; + } + + JsonArray array = doc.as(); + for (JsonObject actuator : array) + { + int actuadorId = actuator["actuadorId"]; + int deviceId = actuator["deviceId"]; + int statuts = actuator["statuts"]; + long timestamp = actuator["timestamp"]; + + Serial.println(("Actuador deserialized: [actuadorId: " + String(actuadorId) + + ", deviceId: " + String(deviceId) + + ", statuts: " + String(statuts) + + ", timestamp: " + String(timestamp) + "]").c_str()); + } + } + else + { + Serial.print("Error code: "); + Serial.println(httpResponseCode); + } +} + +void deserializeDevice (HTTPClient &http, int httpResponseCode) +{ + + if (httpResponseCode > 0) + { + Serial.print("HTTP Response code: "); + Serial.println(httpResponseCode); + String responseJson = http.getString(); + DynamicJsonDocument doc(ESP.getMaxAllocHeap()); + DeserializationError error = deserializeJson(doc, responseJson); + + if (error) + { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.f_str()); + return; + } + + JsonArray array = doc.as(); + for (JsonObject device : array) + { + int sensorId = device["sensorId"]; + int deviceId = device["deviceId"]; + String sensorType = device["sensorType"]; + long timestamp = device["timestamp"]; + + Serial.println(("Sensor deserialized: [sensorId: " + String(sensorId) + + ", deviceId: " + String(deviceId) + + ", sensorType: " + sensorType + + ", timestamp: " + String(timestamp) + "]").c_str()); + + } + } + else + { + Serial.print("Error code: "); + Serial.println(httpResponseCode); + } } \ No newline at end of file diff --git a/hardware/src/RestClient.cpp b/hardware/src/lib/http/RestClient.cpp similarity index 73% rename from hardware/src/RestClient.cpp rename to hardware/src/lib/http/RestClient.cpp index 171b041..2ef4778 100644 --- a/hardware/src/RestClient.cpp +++ b/hardware/src/lib/http/RestClient.cpp @@ -1,27 +1,28 @@ -#include "RestClient.hpp" - - -void getRequest(HTTPClient &httpClient, const String url, String &response) -{ - httpClient.begin(url); - int httpCode = httpClient.GET(); - if (httpCode > 0) { - response = httpClient.getString(); - } else { - response = "Error: " + String(httpCode); - } - httpClient.end(); -} - -void postRequest(HTTPClient &httpClient, const String url, String &payload, String &response) -{ - httpClient.begin(url); - httpClient.addHeader("Content-Type", "application/json"); - int httpCode = httpClient.POST(payload); - if (httpCode > 0) { - response = httpClient.getString(); - } else { - response = "Error: " + String(httpCode); - } - httpClient.end(); +#include "RestClient.hpp" + +HTTPClient httpClient; // HTTP client object + +void getRequest(const String url, String &response) +{ + httpClient.begin(url); + int httpCode = httpClient.GET(); + if (httpCode > 0) { + response = httpClient.getString(); + } else { + response = "Error: " + String(httpCode); + } + httpClient.end(); +} + +void postRequest(const String url, String &payload, String &response) +{ + httpClient.begin(url); + httpClient.addHeader("Content-Type", "application/json"); + int httpCode = httpClient.POST(payload); + if (httpCode > 0) { + response = httpClient.getString(); + } else { + response = "Error: " + String(httpCode); + } + httpClient.end(); } \ No newline at end of file diff --git a/hardware/src/MqttClient.cpp b/hardware/src/lib/inet/MqttClient.cpp similarity index 100% rename from hardware/src/MqttClient.cpp rename to hardware/src/lib/inet/MqttClient.cpp diff --git a/hardware/src/WifiConnection.cpp b/hardware/src/lib/inet/WifiConnection.cpp similarity index 94% rename from hardware/src/WifiConnection.cpp rename to hardware/src/lib/inet/WifiConnection.cpp index accbbad..4b0cfc1 100644 --- a/hardware/src/WifiConnection.cpp +++ b/hardware/src/lib/inet/WifiConnection.cpp @@ -1,33 +1,33 @@ -#include - -WiFiClient wifiClient; - -int setupWifi() -{ - Serial.println(); - Serial.print("Connecting to "); - Serial.println(SSID); - WiFi.mode(WIFI_STA); - WiFi.begin(SSID, PASSWORD); - - while (WiFi.status() != WL_CONNECTED) - { - delay(500); - Serial.print("."); - } - - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println("Setup!"); - - if(WiFi.status() == WL_CONNECTED) - { - return 0; - } - else - { - return 1; - } -} +#include + +WiFiClient wifiClient; + +int setupWifi() +{ + Serial.println(); + Serial.print("Connecting to "); + Serial.println(SSID); + WiFi.mode(WIFI_STA); + WiFi.begin(SSID, PASSWORD); + + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println("Setup!"); + + if(WiFi.status() == WL_CONNECTED) + { + return 0; + } + else + { + return 1; + } +} diff --git a/hardware/src/lib/sensor/BME280.cpp b/hardware/src/lib/sensor/BME280.cpp new file mode 100644 index 0000000..05402d3 --- /dev/null +++ b/hardware/src/lib/sensor/BME280.cpp @@ -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); +} + diff --git a/hardware/src/lib/sensor/GPS.cpp b/hardware/src/lib/sensor/GPS.cpp new file mode 100644 index 0000000..51bf9c1 --- /dev/null +++ b/hardware/src/lib/sensor/GPS.cpp @@ -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; + } +} \ No newline at end of file diff --git a/hardware/src/MQ7.cpp b/hardware/src/lib/sensor/MQ7.cpp similarity index 99% rename from hardware/src/MQ7.cpp rename to hardware/src/lib/sensor/MQ7.cpp index f7fbbe0..8739ab2 100644 --- a/hardware/src/MQ7.cpp +++ b/hardware/src/lib/sensor/MQ7.cpp @@ -1,5 +1,5 @@ #include "MQ7.hpp" - + void MQ7_Init() { pinMode(DIGITAL_MQ7, INPUT); diff --git a/hardware/src/main.cpp b/hardware/src/main.cpp index a05802e..ce3f445 100644 --- a/hardware/src/main.cpp +++ b/hardware/src/main.cpp @@ -2,17 +2,70 @@ const uint32_t deviceId = getChipID(); -// instances -HTTPClient httpClient; +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, pressure, altitude; + prettyReadBME280(); + prettyReadMQ7(); + testMatrix(); +} + +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() { @@ -22,28 +75,4 @@ uint32_t getChipID() 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()); */ - - BME280_Init(); - -} - -void loop() -{ - Serial.println(temperature); - Serial.println(pressure); -} +} \ No newline at end of file