Update WiFi credentials, modify DEVICE_ROLE to SENSOR, and refactor GROUP_ID initialization; enhance MQ7_Read_Fake logic
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#define SSID "DIGIFIBRA-D2ys"
|
||||
#define WIFI_PASSWORD "4EEATsyTcZ"
|
||||
#define SSID "iPhone de Jose"
|
||||
#define WIFI_PASSWORD "bombardeenlaus"
|
||||
|
||||
int WiFi_Init();
|
||||
@@ -1,6 +1,6 @@
|
||||
#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 API_URI "https://contaminus.miarma.net/api/v1/"
|
||||
@@ -18,5 +18,5 @@
|
||||
#define DEBUG
|
||||
|
||||
extern const uint32_t DEVICE_ID;
|
||||
extern const int GROUP_ID;
|
||||
extern int GROUP_ID;
|
||||
extern String currentMessage;
|
||||
@@ -46,4 +46,5 @@ void readGPS();
|
||||
void writeMatrix(const char *message);
|
||||
void printAllData();
|
||||
void sendSensorData();
|
||||
uint32_t getChipID();
|
||||
uint32_t getChipID();
|
||||
int getGroupId(int deviceId);
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "MQ7v2.hpp"
|
||||
|
||||
uint8_t flag = 0;
|
||||
|
||||
void MQ7_Init()
|
||||
{
|
||||
pinMode(MQ7_A0, INPUT);
|
||||
@@ -24,12 +26,14 @@ MQ7Data_t MQ7_Read_Fake()
|
||||
float ppm;
|
||||
bool d0;
|
||||
|
||||
if (random(0, 100) < 50) {
|
||||
ppm = random(80, 500); // valores entre 101 y 500 ppm
|
||||
if (flag == 0) {
|
||||
ppm = 100.0f; // valores entre 101 y 500 ppm
|
||||
d0 = true;
|
||||
flag = 1;
|
||||
} else {
|
||||
ppm = random(10, 79); // valores entre 10 y 99 ppm
|
||||
ppm = 10.0f; // valores entre 10 y 99 ppm
|
||||
d0 = false;
|
||||
flag = 0;
|
||||
}
|
||||
|
||||
return {ppm, d0};
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
const uint32_t DEVICE_ID = getChipID();
|
||||
const String mqttId = "CUS-" + String(DEVICE_ID, HEX);
|
||||
const int GROUP_ID = 1;
|
||||
int GROUP_ID;
|
||||
|
||||
TaskTimer globalTimer{0, 60000};
|
||||
TaskTimer mqttTimer{0, 5000};
|
||||
TaskTimer globalTimer{0, 10000};
|
||||
TaskTimer mqttTimer{0, 2500};
|
||||
|
||||
#if DEVICE_ROLE == ACTUATOR
|
||||
TaskTimer matrixTimer{0, 25};
|
||||
@@ -39,6 +39,7 @@ void setup()
|
||||
{
|
||||
|
||||
#if DEVICE_ROLE == SENSOR
|
||||
GROUP_ID = getGroupId(DEVICE_ID);
|
||||
BME280_Init();
|
||||
Serial.println("Sensor BME280 inicializado");
|
||||
GPS_Init();
|
||||
@@ -119,7 +120,8 @@ void loop()
|
||||
void writeMatrix(const char *message)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Serial.println("Escribiendo mensaje: "); Serial.print(message);
|
||||
Serial.println("Escribiendo mensaje: ");
|
||||
Serial.print(message);
|
||||
#endif
|
||||
MAX7219_DisplayText(message, PA_LEFT, 50, 0);
|
||||
}
|
||||
@@ -139,7 +141,7 @@ void readBME280()
|
||||
|
||||
void readGPS()
|
||||
{
|
||||
gpsData = GPS_Read_Fake();
|
||||
gpsData = GPS_Read();
|
||||
}
|
||||
|
||||
void printAllData()
|
||||
@@ -218,3 +220,11 @@ uint32_t getChipID()
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user