Compare commits
No commits in common. "develop" and "main" have entirely different histories.
|
|
@ -31,14 +31,14 @@ class Actuador: public DomoEspSensorReceiver
|
||||||
activador[i].sen=NULL;
|
activador[i].sen=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, const char* topic_id_out, const char* _valSend)
|
void set(char* topic_id, char* topic_id_out, char* _valSend)
|
||||||
{
|
{
|
||||||
val=0;
|
val=0;
|
||||||
strcpy(valSend, _valSend);
|
strcpy(valSend, _valSend);
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
strcpy(topicOut, topic_id_out);
|
strcpy(topicOut, topic_id_out);
|
||||||
}
|
}
|
||||||
void setId(const char* st)
|
void setId(char* st)
|
||||||
{
|
{
|
||||||
strcpy(id, st);
|
strcpy(id, st);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class AutomatismoPulsador//automatismo para encender luz con interruptor o pulsa
|
||||||
{
|
{
|
||||||
inicia(man, tp_pul->topic, tpOut->topic, bloqueo);
|
inicia(man, tp_pul->topic, tpOut->topic, bloqueo);
|
||||||
}
|
}
|
||||||
void inicia(ISensorManager* man, const char* tp_pul, const char* tpOut, DomoEspSensorReceiver* bloqueo=NULL )
|
void inicia(ISensorManager* man, char* tp_pul, char* tpOut, DomoEspSensorReceiver* bloqueo=NULL )
|
||||||
{
|
{
|
||||||
pulsador.set(tp_pul, tpOut, "X");
|
pulsador.set(tp_pul, tpOut, "X");
|
||||||
pulsador.setId("Pulsa");
|
pulsador.setId("Pulsa");
|
||||||
|
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
#ifndef DomoEspApiConexionDef
|
|
||||||
#define DomoEspApiConexionDef 1
|
|
||||||
#include "defines.h"
|
|
||||||
#ifdef ESP8266
|
|
||||||
#include <ESP8266HTTPClient.h>
|
|
||||||
//sensor Replica, sensor interno que se setea con get y no se publica
|
|
||||||
class DomoEspApiConexion //hay que arreglar compatibilidad con esp32
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DomoEspApiConexion()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool send(char *topic, char*payload)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getDataPendiente(char * idArduino, char *topic, char *payloadOut)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool sendPost(char * buff, char* srv, char* datos)
|
|
||||||
{
|
|
||||||
HTTPClient http;
|
|
||||||
WiFiClient client;
|
|
||||||
int httpCode =-1;
|
|
||||||
if(buff)
|
|
||||||
*buff=0;
|
|
||||||
if(http.begin(client, srv))
|
|
||||||
{
|
|
||||||
http.addHeader("Content-Type", "application/json"); // O el tipo de contenido adecuado
|
|
||||||
//String httpRequestData = "{\"dato1\":\"valor1\", \"dato2\":\"valor2\"}"; // Datos en formato JSON
|
|
||||||
httpCode = http.POST(datos);
|
|
||||||
|
|
||||||
if (httpCode > 0) {
|
|
||||||
String payload = http.getString();
|
|
||||||
if(buff)
|
|
||||||
strcpy( buff, payload.c_str());
|
|
||||||
|
|
||||||
}
|
|
||||||
http.end();
|
|
||||||
}
|
|
||||||
return httpCode==200;
|
|
||||||
}
|
|
||||||
bool sendGet(char * buff, char* srv, char* datos)
|
|
||||||
{
|
|
||||||
HTTPClient http;
|
|
||||||
WiFiClient client;
|
|
||||||
int httpCode =-1;
|
|
||||||
if(buff)
|
|
||||||
*buff=0;
|
|
||||||
if(http.begin(client, srv))
|
|
||||||
{
|
|
||||||
http.addHeader("Content-Type", "application/json"); // O el tipo de contenido adecuado
|
|
||||||
//String httpRequestData = "{\"dato1\":\"valor1\", \"dato2\":\"valor2\"}"; // Datos en formato JSON
|
|
||||||
if(datos)
|
|
||||||
httpCode = http.sendRequest("GET",datos);
|
|
||||||
else
|
|
||||||
httpCode = http.GET();
|
|
||||||
|
|
||||||
|
|
||||||
if (httpCode == HTTP_CODE_OK ) {
|
|
||||||
String payload = http.getString();
|
|
||||||
if(buff)
|
|
||||||
strcpy( buff, payload.c_str());
|
|
||||||
|
|
||||||
}
|
|
||||||
http.end();
|
|
||||||
}
|
|
||||||
return httpCode==200;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
@ -9,9 +9,7 @@ class DomoEspConfig
|
||||||
char ssidWifi[24];//nombre wifi al que conectar
|
char ssidWifi[24];//nombre wifi al que conectar
|
||||||
char keyWifi[32];//key wifi a conectar
|
char keyWifi[32];//key wifi a conectar
|
||||||
char ideEsp[32];//identificador unico por esp
|
char ideEsp[32];//identificador unico por esp
|
||||||
char hostMQTT[32];//ip o url al host
|
char hostMQTT[16];
|
||||||
char keyhost[32];//key para conectar al host
|
|
||||||
bool conexionPorApi;
|
|
||||||
int portMQTT;
|
int portMQTT;
|
||||||
|
|
||||||
int velocidadPortSerie;
|
int velocidadPortSerie;
|
||||||
|
|
@ -21,8 +19,6 @@ class DomoEspConfig
|
||||||
|
|
||||||
DomoEspConfig()
|
DomoEspConfig()
|
||||||
{
|
{
|
||||||
conexionPorApi=false;
|
|
||||||
keyhost[0]=0;
|
|
||||||
velocidadPortSerie=115200;
|
velocidadPortSerie=115200;
|
||||||
strcpy(ssidWifi,"Idhun");//nombre wifi
|
strcpy(ssidWifi,"Idhun");//nombre wifi
|
||||||
strcpy(keyWifi,"Ardileorca1234.");//key wifi
|
strcpy(keyWifi,"Ardileorca1234.");//key wifi
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "DomoEspSensorManager.h"
|
#include "DomoEspSensorManager.h"
|
||||||
#include "configuracionActual.h"
|
#include "configuracionActual.h"
|
||||||
DomoEspManager manager;
|
DomoEspManager manager;
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ DomoEspManager::DomoEspManager()
|
||||||
tiempo=0;
|
tiempo=0;
|
||||||
suscrito=false;
|
suscrito=false;
|
||||||
SetTimeRefres(15);
|
SetTimeRefres(15);
|
||||||
tNoConexion.set(300);
|
|
||||||
tNomqtt.set(300);
|
|
||||||
}
|
}
|
||||||
void DomoEspManager::SetTimeRefres(int seg)
|
void DomoEspManager::SetTimeRefres(int seg)
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +20,7 @@ void DomoEspManager::inicia(DomoEspConfig* cnf)
|
||||||
conf=cnf;
|
conf=cnf;
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
Serial.begin(conf->velocidadPortSerie);
|
Serial.begin(conf->velocidadPortSerie);
|
||||||
delay(1000);
|
delay(100);
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println("Iniciando");
|
Serial.println("Iniciando");
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -33,14 +31,7 @@ void DomoEspManager::inicia(DomoEspConfig* cnf)
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
Serial.println("Inicia Mqtt");
|
Serial.println("Inicia Mqtt");
|
||||||
#endif
|
#endif
|
||||||
if(conf->conexionPorApi)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mqtt.inicia(&clienteMqtt,conf->ideEsp, conf->hostMQTT, conf->portMQTT, this);
|
mqtt.inicia(&clienteMqtt,conf->ideEsp, conf->hostMQTT, conf->portMQTT, this);
|
||||||
//loguea------------
|
|
||||||
MqttSend("casa/log", conf->ideEsp);
|
|
||||||
|
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
Serial.println("Configura Sensores");
|
Serial.println("Configura Sensores");
|
||||||
|
|
@ -60,41 +51,15 @@ void DomoEspManager::loop()
|
||||||
if(!wifi.loop())
|
if(!wifi.loop())
|
||||||
{
|
{
|
||||||
suscrito=false;
|
suscrito=false;
|
||||||
if(!wifi.conecta())
|
|
||||||
{
|
|
||||||
if(tNoConexion.onTimer())
|
|
||||||
{
|
|
||||||
#if defined(ESP8266)
|
|
||||||
ESP.reset();
|
|
||||||
#elif defined(ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ESP32C3)
|
|
||||||
ESP.restart();
|
|
||||||
#else
|
|
||||||
#error "Placa no soportada"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
tNoConexion.inicia();
|
|
||||||
if(!mqtt.loop())
|
if(!mqtt.loop())
|
||||||
{
|
{
|
||||||
suscrito=false;
|
suscrito=false;
|
||||||
if(tNomqtt.onTimer())
|
return;
|
||||||
{
|
}
|
||||||
#if defined(ESP8266)
|
|
||||||
ESP.reset();
|
|
||||||
#elif defined(ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ESP32C3)
|
|
||||||
ESP.restart();
|
|
||||||
#else
|
|
||||||
#error "Placa no soportada"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tNomqtt.inicia();
|
|
||||||
if(!suscrito)
|
if(!suscrito)
|
||||||
{
|
{
|
||||||
for(int i=0; i<n; i++)
|
for(int i=0; i<n; i++)
|
||||||
|
|
@ -105,20 +70,8 @@ void DomoEspManager::loop()
|
||||||
}
|
}
|
||||||
int tiempoAux=0;
|
int tiempoAux=0;
|
||||||
if(timer.onTimerReset())
|
if(timer.onTimerReset())
|
||||||
{
|
|
||||||
#ifdef ESP8266
|
|
||||||
if(conf->conexionPorApi)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
char topic_aux[32];
|
|
||||||
char payload_aux[128];
|
|
||||||
|
|
||||||
while(api.getDataPendiente(conf->ideEsp,topic_aux, payload_aux))
|
|
||||||
{
|
|
||||||
OnMqtt(topic_aux, payload_aux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
tiempo=(tiempo+1)%2;
|
tiempo=(tiempo+1)%2;
|
||||||
tiempoAux=tiempo+1;
|
tiempoAux=tiempo+1;
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
|
|
@ -184,25 +137,10 @@ void DomoEspManager::SubscribeMqtt(PubSubClient *client_mqtt)
|
||||||
|
|
||||||
void DomoEspManager::MqttSend(char* topic, char* payload)
|
void DomoEspManager::MqttSend(char* topic, char* payload)
|
||||||
{
|
{
|
||||||
if(conf->conexionPorApi)
|
|
||||||
{
|
|
||||||
#ifdef ESP8266
|
|
||||||
api.send(topic, payload);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(suscrito);
|
|
||||||
clienteMqtt.publish(topic, payload);
|
clienteMqtt.publish(topic, payload);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void DomoEspManager::MqttSubs(char* topic)
|
void DomoEspManager::MqttSubs(char* topic)
|
||||||
{
|
{
|
||||||
if(conf->conexionPorApi)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
clienteMqtt.subscribe(topic);
|
clienteMqtt.subscribe(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,8 @@
|
||||||
#ifndef DomoEspManagerDef
|
#ifndef DomoEspManagerDef
|
||||||
#define DomoEspManagerDef 1
|
#define DomoEspManagerDef 1
|
||||||
|
|
||||||
|
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#if defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#elif defined(ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ESP32C3)
|
|
||||||
#include <WiFi.h>
|
|
||||||
#else
|
|
||||||
#error "Placa no soportada"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "utiles.h"
|
#include "utiles.h"
|
||||||
#include "DomoEspApiConexion.h"
|
|
||||||
class DomoEspConfig;
|
class DomoEspConfig;
|
||||||
class IDomoEspLisener
|
class IDomoEspLisener
|
||||||
{
|
{
|
||||||
|
|
@ -31,18 +21,13 @@ class DomoEspManager: public MqttReceiver, public IMqttManager, public ISensorMa
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient clienteMqtt;
|
PubSubClient clienteMqtt;
|
||||||
MqttManager mqtt;
|
MqttManager mqtt;
|
||||||
#ifdef ESP8266
|
|
||||||
DomoEspApiConexion api;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
DomoEspSensorReceiver* sensores[MAXSENS];
|
DomoEspSensorReceiver* sensores[MAXSENS];
|
||||||
int n;
|
int n;
|
||||||
int tiempo;
|
int tiempo;
|
||||||
bool suscrito;
|
bool suscrito;
|
||||||
Ctimer timer;
|
Ctimer timer;
|
||||||
Ctimer tNoConexion;
|
|
||||||
Ctimer tNomqtt;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DomoEspManager();
|
DomoEspManager();
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class SensorAin: public DomoEspSensorReceiver
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
SensorAin(){}
|
SensorAin(){}
|
||||||
void set(uint8_t _pin,const char* topic_id, bool _negado, float _dif)
|
void set(uint8_t _pin, char* topic_id, bool _negado, float _dif)
|
||||||
{
|
{
|
||||||
timer.inicia();
|
timer.inicia();
|
||||||
timer.set(1);
|
timer.set(1);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class SensorBMP180: public DomoEspSensorReceiver
|
||||||
t=p=a=0;
|
t=p=a=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, int _sda, int _scl)
|
void set(char* topic_id, int _sda, int _scl)
|
||||||
{
|
{
|
||||||
sda=_sda;
|
sda=_sda;
|
||||||
scl=_scl;
|
scl=_scl;
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ class SensorBuzzer: public DomoEspSensorReceiver
|
||||||
val=0;
|
val=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void setMelodia(int i, const char* melodia)
|
void setMelodia(int i, char* melodia)
|
||||||
{
|
{
|
||||||
buz.Set(i, melodia);
|
buz.Set(i, melodia);
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, int _pin)
|
void set(char* topic_id, int _pin)
|
||||||
{
|
{
|
||||||
val=0;
|
val=0;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ class SensorDHT: public DomoEspSensorReceiver
|
||||||
t=h=0;
|
t=h=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void set(uint8_t _pin, const char* topic_id)
|
void set(uint8_t _pin, char* topic_id)
|
||||||
{
|
{
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
t=h=9.99998;
|
t=h=0;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
}
|
}
|
||||||
virtual void procesa(IMqttManager * man, int tiempo)
|
virtual void procesa(IMqttManager * man, int tiempo)
|
||||||
|
|
@ -43,17 +43,8 @@ class SensorDHT: public DomoEspSensorReceiver
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*if(t==h && t==9.99998)
|
|
||||||
{*/
|
|
||||||
t=ta;
|
t=ta;
|
||||||
h=ha;
|
h=ha;
|
||||||
/*}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
t=(t+ta)/2;
|
|
||||||
h=(h+ha)/2;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class SensorDin: public DomoEspSensorReceiver
|
||||||
SensorDin(){
|
SensorDin(){
|
||||||
logTiempo2=true;
|
logTiempo2=true;
|
||||||
}
|
}
|
||||||
void set(uint8_t _pin, const char* topic_id, bool _logTiempo2=true)
|
void set(uint8_t _pin, char* topic_id, bool _logTiempo2=true)
|
||||||
{
|
{
|
||||||
logTiempo2=_logTiempo2;
|
logTiempo2=_logTiempo2;
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ bool negado;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
negado=false;
|
negado=false;
|
||||||
}
|
}
|
||||||
void set(uint8_t _pin, const char* topic_id, bool valdef,bool _negado=false)
|
void set(uint8_t _pin, char* topic_id, bool valdef,bool _negado=false)
|
||||||
{
|
{
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
val=valdef;
|
val=valdef;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public:
|
||||||
apan=0;
|
apan=0;
|
||||||
|
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, LiquidCrystal * _lcd, int _nchar, int lineas, int seg)
|
void set(char* topic_id, LiquidCrystal * _lcd, int _nchar, int lineas, int seg)
|
||||||
{
|
{
|
||||||
val = 0;
|
val = 0;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
@ -49,7 +49,7 @@ public:
|
||||||
nlin = lineas;
|
nlin = lineas;
|
||||||
|
|
||||||
}
|
}
|
||||||
void AddPan(const char* msg, DomoEspSensorReceiver *sen1=0, DomoEspSensorReceiver *sen2=0)
|
void AddPan(char* msg, DomoEspSensorReceiver *sen1=0, DomoEspSensorReceiver *sen2=0)
|
||||||
{
|
{
|
||||||
if(npan<MAX_PAN_LCD)
|
if(npan<MAX_PAN_LCD)
|
||||||
{
|
{
|
||||||
|
|
@ -126,7 +126,7 @@ private:
|
||||||
Muestra(msg);
|
Muestra(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Muestra(const char * txt)
|
void Muestra(char * txt)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
Serial.println("SenLcd muestra: ");
|
Serial.println("SenLcd muestra: ");
|
||||||
|
|
@ -134,7 +134,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
int linea=0;
|
int linea=0;
|
||||||
int i=0;
|
int i=0;
|
||||||
const char* ini=txt;
|
char* ini=txt;
|
||||||
bool sigue=true;
|
bool sigue=true;
|
||||||
while(sigue && linea<nlin)
|
while(sigue && linea<nlin)
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +166,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void Muestra(const char * txt,int nStr, int linea)
|
void Muestra(char * txt,int nStr, int linea)
|
||||||
{
|
{
|
||||||
char buf[MAXTOPICVAR];
|
char buf[MAXTOPICVAR];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ bool negado;
|
||||||
initDS1803();
|
initDS1803();
|
||||||
}
|
}
|
||||||
|
|
||||||
void set( const char* topic_id, int valdef,bool _negado=false)
|
void set( char* topic_id, int valdef,bool _negado=false)
|
||||||
{
|
{
|
||||||
val=valdef;
|
val=valdef;
|
||||||
negado=_negado;
|
negado=_negado;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
espera=false;
|
espera=false;
|
||||||
timer.setmilis(500);
|
timer.setmilis(500);
|
||||||
}
|
}
|
||||||
void set(uint8_t _pin, const char* topic_id, bool _valDef)
|
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
||||||
{
|
{
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
valDef=_valDef;
|
valDef=_valDef;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class SensorRF: public DomoEspSensorReceiver
|
||||||
val=0;
|
val=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void set(const char* topic_id,bool _negado=0, float valdef=0)
|
void set(char* topic_id,bool _negado=0, float valdef=0)
|
||||||
{
|
{
|
||||||
negado=_negado;
|
negado=_negado;
|
||||||
val=valdef;
|
val=valdef;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class SensorSplitter: public DomoEspSensorReceiver
|
||||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
for(int i=0; i<MAX_ACTIVADORES; i++)
|
||||||
sensorSend[i].sen=0;
|
sensorSend[i].sen=0;
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, float =0)
|
void set(char* topic_id, float =0)
|
||||||
{
|
{
|
||||||
val=0;
|
val=0;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
||||||
val=0;
|
val=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, bool _valdef, int segTime)
|
void set(char* topic_id, bool _valdef, int segTime)
|
||||||
{
|
{
|
||||||
t.set(segTime);
|
t.set(segTime);
|
||||||
valDef=_valdef;
|
valDef=_valdef;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class SensorVF: public DomoEspSensorReceiver
|
||||||
val=0;
|
val=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void set(const char* topic_id, float valdef=0)
|
void set(char* topic_id, float valdef=0)
|
||||||
{
|
{
|
||||||
val=valdef;
|
val=valdef;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,6 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#elif defined(ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ESP32C3)
|
|
||||||
#include <WiFi.h>
|
|
||||||
#else
|
|
||||||
#error "Placa no soportada"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
@ -19,15 +11,7 @@
|
||||||
//**************************************************************************************************************************************************
|
//**************************************************************************************************************************************************
|
||||||
void MqttUtiles::resetFunc()
|
void MqttUtiles::resetFunc()
|
||||||
{
|
{
|
||||||
|
|
||||||
#if defined(ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ESP32C3)
|
|
||||||
ESP.restart();
|
|
||||||
#elif defined(ESP8266)
|
|
||||||
ESP.wdtEnable(1);
|
ESP.wdtEnable(1);
|
||||||
#else
|
|
||||||
#error "Placa no soportada"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while(1){};
|
while(1){};
|
||||||
}
|
}
|
||||||
//**************************************************************************************************************************************************
|
//**************************************************************************************************************************************************
|
||||||
|
|
@ -184,9 +168,9 @@ bool WifiManager::loop()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
Serial.println("Fallo de conexion wifi");
|
Serial.println("Fallo de conexion, se reinicia arduino");
|
||||||
#endif
|
#endif
|
||||||
//ESP.reset();
|
ESP.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//**************************************************************************************************************************************************
|
//**************************************************************************************************************************************************
|
||||||
|
|
@ -223,9 +207,9 @@ bool MqttManager::loop()
|
||||||
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_PS
|
#ifdef DEBUG_PS
|
||||||
Serial.println("Fallo de conexion a mqtt broker");
|
Serial.println("Fallo de conexion, se reinicia arduino");
|
||||||
#endif
|
#endif
|
||||||
//ESP.reset();
|
ESP.reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void MqttManager::subscribe_mqtt()
|
void MqttManager::subscribe_mqtt()
|
||||||
|
|
@ -356,7 +340,7 @@ void SonidoBuzzer::Toca(int pin, int imel)
|
||||||
mel[imel].Toca(pin);
|
mel[imel].Toca(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SonidoBuzzer::Set(int i, const char* melo)
|
void SonidoBuzzer::Set(int i, char* melo)
|
||||||
{
|
{
|
||||||
if(i<MAX_MELODIAS)
|
if(i<MAX_MELODIAS)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@
|
||||||
#define UtilesDef 1
|
#define UtilesDef 1
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
class PubSubClient;
|
class PubSubClient;
|
||||||
#ifdef ESP8266
|
|
||||||
class WiFiClient;
|
class WiFiClient;
|
||||||
#endif
|
|
||||||
class MqttUtiles
|
class MqttUtiles
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -98,7 +97,7 @@ class SonidoBuzzer
|
||||||
int n;
|
int n;
|
||||||
SonidoBuzzer();
|
SonidoBuzzer();
|
||||||
void Toca(int pin, int melodia);
|
void Toca(int pin, int melodia);
|
||||||
void Set(int i, const char* melo);
|
void Set(int i, char* melo);
|
||||||
char* getMelSubSt(char* orig, char caracter, int lim, char* bufOut);
|
char* getMelSubSt(char* orig, char caracter, int lim, char* bufOut);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,29 +7,6 @@
|
||||||
|
|
||||||
|
|
||||||
//configuraciones-----------------------------------------------------
|
//configuraciones-----------------------------------------------------
|
||||||
|
|
||||||
class PruebaConexiones: public DomoEspConfig
|
|
||||||
{
|
|
||||||
SensorDHT dht;
|
|
||||||
SensorDout led;
|
|
||||||
public:
|
|
||||||
PruebaConexiones()
|
|
||||||
{
|
|
||||||
strcpy(hostMQTT,"192.168.2.115");//servidor mqttBroker
|
|
||||||
strcpy(ssidWifi,"IdhunDesa");//nombre wifi
|
|
||||||
strcpy(ideEsp,"Esp8266_PCon");//idenitificador del esp (sera único)
|
|
||||||
dht.set(D1,"casa/PCon");
|
|
||||||
led.set(D4, "casa/PCon/led",0,0);
|
|
||||||
}
|
|
||||||
virtual void inicia(ISensorManager* man)
|
|
||||||
{
|
|
||||||
man->Add(&dht);
|
|
||||||
man->Add(&led);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class ConfAutomatismos: public DomoEspConfig
|
class ConfAutomatismos: public DomoEspConfig
|
||||||
{
|
{
|
||||||
SensorRF presencia;
|
SensorRF presencia;
|
||||||
|
|
@ -414,10 +391,10 @@ class ConfigAltavozCocina: public DomoEspConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
||||||
strcpy(ideEsp,"Esp8266_Av_cocina");//idenitificador del esp (sera único)
|
strcpy(ideEsp,"Esp8266_Av_cocian");//idenitificador del esp (sera único)
|
||||||
|
|
||||||
ampli.set(D4,"casa/cocina/alt",0,1);
|
ampli.set(D4,"casa/cocina/aux",0,1);
|
||||||
altavoz.set(D3,"casa/cocina/blue",0,1);
|
altavoz.set(D3,"casa/cocina/alt",0,1);
|
||||||
radio.set(D5,"casa/cocina/arad",0);
|
radio.set(D5,"casa/cocina/arad",0);
|
||||||
poten.set("casa/cocina/volu",50, 0);
|
poten.set("casa/cocina/volu",50, 0);
|
||||||
pulso.set("casa/cocina/rad",1,1);
|
pulso.set("casa/cocina/rad",1,1);
|
||||||
|
|
@ -461,116 +438,7 @@ class ConfLamSalon: public DomoEspConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
class ConfHabitacionPrincipal: public DomoEspConfig
|
|
||||||
{
|
|
||||||
SensorDHT dht;
|
|
||||||
SensorDout radio;
|
|
||||||
public:
|
|
||||||
ConfHabitacionPrincipal()
|
|
||||||
{
|
|
||||||
strcpy(ssidWifi,"Idhun");//nombre wifi
|
|
||||||
strcpy(ideEsp,"Esp8266_HP");//idenitificador del esp (sera único)
|
|
||||||
dht.set(D4,"casa/habPrin");
|
|
||||||
radio.set(D0, "casa/habPrin/rad",0,0);
|
|
||||||
}
|
|
||||||
virtual void inicia(ISensorManager* man)
|
|
||||||
{
|
|
||||||
man->Add(&dht);
|
|
||||||
man->Add(&radio);
|
|
||||||
|
|
||||||
}
|
ConfigAltavozCocina ConfiguracionActual;
|
||||||
|
|
||||||
};
|
|
||||||
class ConfHabitacionNinas: public DomoEspConfig
|
|
||||||
{
|
|
||||||
SensorDHT dht;
|
|
||||||
SensorDout cartel;
|
|
||||||
SensorDin interruptor;
|
|
||||||
AutomatismoPulsador actuadorPul;
|
|
||||||
public:
|
|
||||||
ConfHabitacionNinas()
|
|
||||||
{
|
|
||||||
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
|
||||||
strcpy(ideEsp,"Esp8266_HN");//idenitificador del esp (sera único)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
int cociMov= vars->AddInternalVarInt( "casa/cocina/mov");
|
|
||||||
int cociLuz= vars->AddInternalVarInt( "casa/cocina/luz");
|
|
||||||
int cociLam= vars->AddInternalVarInt( "casa/cocina/lam");
|
|
||||||
int cociAuto= vars->AddInternalVarInt("casa/cocina/luzAuto");
|
|
||||||
*/
|
|
||||||
dht.set(D0,"casa/habNin");
|
|
||||||
cartel.set(D2, "casa/habNin/cartel",0,0);
|
|
||||||
interruptor.set( D1, "casa/habNin/inter", false);
|
|
||||||
}
|
|
||||||
virtual void inicia(ISensorManager* man)
|
|
||||||
{
|
|
||||||
man->Add(&dht);
|
|
||||||
man->Add(&cartel);
|
|
||||||
man->Add(&interruptor);
|
|
||||||
actuadorPul.inicia(man, &interruptor, &cartel);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
class ConfPruebaDHT: public DomoEspConfig
|
|
||||||
{
|
|
||||||
SensorDHT dht;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ConfPruebaDHT()
|
|
||||||
{
|
|
||||||
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
|
||||||
strcpy(ideEsp,"Esp8266_dht");//idenitificador del esp (sera único)
|
|
||||||
dht.set(D0, "casa/pruebas/dht");
|
|
||||||
}
|
|
||||||
virtual void inicia(ISensorManager* man)
|
|
||||||
{
|
|
||||||
man->Add(&dht);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
class ConfSonofPrueba: public DomoEspConfig
|
|
||||||
{
|
|
||||||
SensorDout luz;
|
|
||||||
SensorDin interruptor;
|
|
||||||
AutomatismoPulsador actuadorInterrup;
|
|
||||||
//SensorPulsante pul;
|
|
||||||
//Actuador actpon;
|
|
||||||
//Actuador actpoff;
|
|
||||||
public:
|
|
||||||
ConfSonofPrueba()
|
|
||||||
{
|
|
||||||
strcpy(ssidWifi,"IdhunDesa");//nombre wifi
|
|
||||||
strcpy(ideEsp,"Esp32c3_soff2");//idenitificador del esp (sera único)
|
|
||||||
luz.set(4, "casa/sonoff2/luz",0,0);
|
|
||||||
interruptor.set( 18, "casa/sonoff2/inter", false);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//pul.set(19,"casa/sonoff/pul",1);
|
|
||||||
|
|
||||||
//actpon.set("casa/sonoff/pul","casa/sonoff/luz","0");
|
|
||||||
//actpoff.set("casa/sonoff/pul","casa/sonoff/luz","1");
|
|
||||||
//actpon.AddActivador(&luz, '>', 0);
|
|
||||||
//actpoff.AddActivador(&luz, '<', 1);
|
|
||||||
}
|
|
||||||
virtual void inicia(ISensorManager* man)
|
|
||||||
{
|
|
||||||
man->Add(&luz);
|
|
||||||
man->Add(&interruptor);
|
|
||||||
//man->Add(&pul);
|
|
||||||
//man->Add(&actpon);
|
|
||||||
//man->Add(&actpoff);
|
|
||||||
|
|
||||||
actuadorInterrup.inicia(man, &interruptor, &luz);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
ConfSonofPrueba ConfiguracionActual;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define DefinesDef 1
|
#define DefinesDef 1
|
||||||
|
|
||||||
#define DEBUG_PS 1
|
#define DEBUG_PS 1
|
||||||
|
|
||||||
#define MAXTOPICVAR 32//maximo de caracteres de los topic de las variables
|
#define MAXTOPICVAR 32//maximo de caracteres de los topic de las variables
|
||||||
#define MAX_CHAR_PAN_LCD 35//MAXIMO DE CARACTRES POR PANTALLA LCD
|
#define MAX_CHAR_PAN_LCD 35//MAXIMO DE CARACTRES POR PANTALLA LCD
|
||||||
#define MAX_PAN_LCD 3//MAXIMO DE PANTALLAS POR SENSOR LCD
|
#define MAX_PAN_LCD 3//MAXIMO DE PANTALLAS POR SENSOR LCD
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue