1
0

Update WiFi credentials, modify DEVICE_ROLE to SENSOR, and refactor GROUP_ID initialization; enhance MQ7_Read_Fake logic

This commit is contained in:
Jose
2025-06-03 22:16:22 +02:00
parent fb53c0fb83
commit 24802271bb
5 changed files with 28 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
#include <WiFi.h> #include <WiFi.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#define SSID "DIGIFIBRA-D2ys" #define SSID "iPhone de Jose"
#define WIFI_PASSWORD "4EEATsyTcZ" #define WIFI_PASSWORD "bombardeenlaus"
int WiFi_Init(); int WiFi_Init();

View File

@@ -1,6 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#define DEVICE_ROLE ACTUATOR // se cambia entre SENSOR y ACTUATOR #define DEVICE_ROLE SENSOR // se cambia entre SENSOR y ACTUATOR
#define MQTT_URI "miarma.net" #define MQTT_URI "miarma.net"
#define API_URI "https://contaminus.miarma.net/api/v1/" #define API_URI "https://contaminus.miarma.net/api/v1/"
@@ -18,5 +18,5 @@
#define DEBUG #define DEBUG
extern const uint32_t DEVICE_ID; extern const uint32_t DEVICE_ID;
extern const int GROUP_ID; extern int GROUP_ID;
extern String currentMessage; extern String currentMessage;

View File

@@ -47,3 +47,4 @@ void writeMatrix(const char *message);
void printAllData(); void printAllData();
void sendSensorData(); void sendSensorData();
uint32_t getChipID(); uint32_t getChipID();
int getGroupId(int deviceId);

View File

@@ -1,5 +1,7 @@
#include "MQ7v2.hpp" #include "MQ7v2.hpp"
uint8_t flag = 0;
void MQ7_Init() void MQ7_Init()
{ {
pinMode(MQ7_A0, INPUT); pinMode(MQ7_A0, INPUT);
@@ -24,12 +26,14 @@ MQ7Data_t MQ7_Read_Fake()
float ppm; float ppm;
bool d0; bool d0;
if (random(0, 100) < 50) { if (flag == 0) {
ppm = random(80, 500); // valores entre 101 y 500 ppm ppm = 100.0f; // valores entre 101 y 500 ppm
d0 = true; d0 = true;
flag = 1;
} else { } else {
ppm = random(10, 79); // valores entre 10 y 99 ppm ppm = 10.0f; // valores entre 10 y 99 ppm
d0 = false; d0 = false;
flag = 0;
} }
return {ppm, d0}; return {ppm, d0};

View File

@@ -2,10 +2,10 @@
const uint32_t DEVICE_ID = getChipID(); const uint32_t DEVICE_ID = getChipID();
const String mqttId = "CUS-" + String(DEVICE_ID, HEX); const String mqttId = "CUS-" + String(DEVICE_ID, HEX);
const int GROUP_ID = 1; int GROUP_ID;
TaskTimer globalTimer{0, 60000}; TaskTimer globalTimer{0, 10000};
TaskTimer mqttTimer{0, 5000}; TaskTimer mqttTimer{0, 2500};
#if DEVICE_ROLE == ACTUATOR #if DEVICE_ROLE == ACTUATOR
TaskTimer matrixTimer{0, 25}; TaskTimer matrixTimer{0, 25};
@@ -39,6 +39,7 @@ void setup()
{ {
#if DEVICE_ROLE == SENSOR #if DEVICE_ROLE == SENSOR
GROUP_ID = getGroupId(DEVICE_ID);
BME280_Init(); BME280_Init();
Serial.println("Sensor BME280 inicializado"); Serial.println("Sensor BME280 inicializado");
GPS_Init(); GPS_Init();
@@ -119,7 +120,8 @@ void loop()
void writeMatrix(const char *message) void writeMatrix(const char *message)
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.println("Escribiendo mensaje: "); Serial.print(message); Serial.println("Escribiendo mensaje: ");
Serial.print(message);
#endif #endif
MAX7219_DisplayText(message, PA_LEFT, 50, 0); MAX7219_DisplayText(message, PA_LEFT, 50, 0);
} }
@@ -139,7 +141,7 @@ void readBME280()
void readGPS() void readGPS()
{ {
gpsData = GPS_Read_Fake(); gpsData = GPS_Read();
} }
void printAllData() void printAllData()
@@ -218,3 +220,11 @@ uint32_t getChipID()
#endif #endif
return chipId; return chipId;
} }
int getGroupId(int deviceId)
{
String url = String(API_URI) + "groups/" + GROUP_ID + "/devices/" + String(DEVICE_ID, HEX) + "/actuators/" + MAX7219_ID + "/status";
getRequest(url, response);
MAX7219Status_t statusData = deserializeActuatorStatus(httpClient, httpClient.GET());
currentMessage = statusData.actuatorStatus;
}