Estavilizacion de actuadores
parent
f1070e030c
commit
0b2a5f1fde
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef MecanismoPulsoDef
|
#ifndef ActuadorDef
|
||||||
#define MecanismoPulsoDef 1
|
#define ActuadorDef 1
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
//sensor activador envia a topicOut el valor val_send si los activadores cumplen umbral
|
//sensor activador envia a topicOut el valor val_send si los activadores cumplen umbral
|
||||||
class Cactivador
|
class Cactivador
|
||||||
|
|
@ -9,10 +9,11 @@ class Cactivador
|
||||||
DomoEspSensorReceiver *sen;
|
DomoEspSensorReceiver *sen;
|
||||||
float umbral;
|
float umbral;
|
||||||
char operacion;//< > = val oper umbral
|
char operacion;//< > = val oper umbral
|
||||||
|
bool onchange;
|
||||||
};
|
};
|
||||||
#define MAX_ACTIVADORES 5
|
|
||||||
|
|
||||||
class MecanismoPulso: public DomoEspSensorReceiver
|
|
||||||
|
class Actuador: public DomoEspSensorReceiver
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
char topicOut[MAXTOPICVAR];
|
char topicOut[MAXTOPICVAR];
|
||||||
|
|
@ -21,7 +22,7 @@ class MecanismoPulso: public DomoEspSensorReceiver
|
||||||
|
|
||||||
public:
|
public:
|
||||||
char id[10];
|
char id[10];
|
||||||
MecanismoPulso()
|
Actuador()
|
||||||
{
|
{
|
||||||
strcpy(id, "Meca");
|
strcpy(id, "Meca");
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
|
|
@ -36,17 +37,27 @@ class MecanismoPulso: public DomoEspSensorReceiver
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
strcpy(topicOut, topic_id_out);
|
strcpy(topicOut, topic_id_out);
|
||||||
}
|
}
|
||||||
void AddActivador(DomoEspSensorReceiver *sen, char oper, float umbral)
|
void AddActivador(DomoEspSensorReceiver *sen, char oper, float umbral, bool onchange=false)
|
||||||
{
|
{
|
||||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
int i=0;
|
||||||
|
for(; i<MAX_ACTIVADORES; i++)
|
||||||
{
|
{
|
||||||
if(!activador[i].sen)
|
if(!activador[i].sen)
|
||||||
{
|
{
|
||||||
activador[i].sen=sen;
|
activador[i].sen=sen;
|
||||||
activador[i].operacion=oper;
|
activador[i].operacion=oper;
|
||||||
activador[i].umbral=umbral;
|
activador[i].umbral=umbral;
|
||||||
|
activador[i].onchange = onchange;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(i>=MAX_ACTIVADORES)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_PS
|
||||||
|
Serial.print(id);
|
||||||
|
Serial.println("----------------------ERROR NO ENTRAN MAS ACTUADORES---------------- ");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void setValSend(char* _valSend)
|
void setValSend(char* _valSend)
|
||||||
{
|
{
|
||||||
|
|
@ -65,23 +76,32 @@ class MecanismoPulso: public DomoEspSensorReceiver
|
||||||
}
|
}
|
||||||
virtual void OnMqtt(IMqttManager * man, char* _topic, char* payload, int tipo)
|
virtual void OnMqtt(IMqttManager * man, char* _topic, char* payload, int tipo)
|
||||||
{
|
{
|
||||||
if(strcmp(_topic, topic))
|
if(!validaTopic(_topic))
|
||||||
return;
|
return;
|
||||||
if(tipo==Topic::GET)
|
if(tipo==Topic::GET)
|
||||||
{
|
{
|
||||||
float val_act=atof(payload);
|
val=atof(payload);
|
||||||
if (val_act!=val)
|
|
||||||
{
|
|
||||||
val=val_act;
|
|
||||||
ejecuta(man);
|
ejecuta(man);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(tipo==Topic::PUL)
|
else if(tipo==Topic::PUL)
|
||||||
{
|
|
||||||
ejecuta(man);
|
ejecuta(man);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
|
bool validaTopic(char* _topic)
|
||||||
|
{
|
||||||
|
if (!strcmp(_topic, topic))
|
||||||
|
return true;
|
||||||
|
for (int i = 0; i < MAX_ACTIVADORES; i++)
|
||||||
|
{
|
||||||
|
if (activador[i].sen && activador[i].onchange)
|
||||||
|
{
|
||||||
|
if (!strcmp(activador[i].sen->topic, _topic))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
void ejecuta(IMqttManager * man)
|
void ejecuta(IMqttManager * man)
|
||||||
{
|
{
|
||||||
if(valida())
|
if(valida())
|
||||||
|
|
@ -98,11 +118,14 @@ class MecanismoPulso: public DomoEspSensorReceiver
|
||||||
}
|
}
|
||||||
bool valida()
|
bool valida()
|
||||||
{
|
{
|
||||||
|
|
||||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
for(int i=0; i<MAX_ACTIVADORES; i++)
|
||||||
{
|
{
|
||||||
if(activador[i].sen && !opera(i))
|
if(activador[i].sen && !opera(i))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool opera( int i)
|
bool opera( int i)
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
#ifndef AutomatismosDef
|
||||||
|
#define AutomatismosDef 1
|
||||||
|
#include "DomoEspConfig.h"
|
||||||
|
#include "SensorDout.h"
|
||||||
|
#include "SensorDHT.h"
|
||||||
|
#include "SensorDin.h"
|
||||||
|
#include "SensorPulsante.h"
|
||||||
|
#include "SensorAin.h"
|
||||||
|
#include "SensorVD.h"
|
||||||
|
#include "SensorRF.h"
|
||||||
|
#include "Actuador.h"
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
class AutomatismoPulsador//automatismo para encender luz con interruptor o pulsador
|
||||||
|
{
|
||||||
|
|
||||||
|
Actuador pulsador;//cambia estado con pulsador
|
||||||
|
public:
|
||||||
|
AutomatismoPulsador(){}
|
||||||
|
void inicia(ISensorManager* man, DomoEspSensorReceiver* tp_pul, DomoEspSensorReceiver* tpOut, DomoEspSensorReceiver* bloqueo=NULL )
|
||||||
|
{
|
||||||
|
inicia(man, tp_pul->topic, tpOut->topic, bloqueo);
|
||||||
|
}
|
||||||
|
void inicia(ISensorManager* man, char* tp_pul, char* tpOut, DomoEspSensorReceiver* bloqueo=NULL )
|
||||||
|
{
|
||||||
|
pulsador.set(tp_pul, tpOut, 0);
|
||||||
|
pulsador.setValSend("X");
|
||||||
|
strcpy(pulsador.id, "pulsa");
|
||||||
|
if(bloqueo)
|
||||||
|
{
|
||||||
|
pulsador.AddActivador(bloqueo,'>',0);
|
||||||
|
}
|
||||||
|
man->Add(&pulsador);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//automatismo para luz con sensor de presencia y de nivel de luz
|
||||||
|
class AutomatismoPresencia//automatismo para encender luz con presencia
|
||||||
|
{
|
||||||
|
|
||||||
|
Actuador presenciaOn;
|
||||||
|
Actuador presenciaOff;
|
||||||
|
Actuador nivelLuzOff;
|
||||||
|
float fnivelLuz;
|
||||||
|
public:
|
||||||
|
AutomatismoPresencia()
|
||||||
|
{
|
||||||
|
fnivelLuz=50;
|
||||||
|
|
||||||
|
|
||||||
|
strcpy(presenciaOn.id, "PresOn");
|
||||||
|
strcpy(presenciaOff.id, "PresOff");
|
||||||
|
strcpy(nivelLuzOff.id, "luzOff");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void inicia(ISensorManager* man, DomoEspSensorReceiver* presencia, DomoEspSensorReceiver* nivelluz, DomoEspSensorReceiver* out, DomoEspSensorReceiver* bloqueo=NULL )
|
||||||
|
{
|
||||||
|
|
||||||
|
presenciaOn.set(presencia->topic, out->topic, 0);
|
||||||
|
presenciaOn.setValSend("1");
|
||||||
|
presenciaOn.AddActivador(nivelluz,'<',fnivelLuz, 1);//nivel de luz bajo
|
||||||
|
presenciaOn.AddActivador(out,'<',1, 0);//out apagada
|
||||||
|
presenciaOn.AddActivador(presencia,'>',0, 0);//presencia
|
||||||
|
if(bloqueo)
|
||||||
|
{
|
||||||
|
presenciaOn.AddActivador(bloqueo,'>',0);
|
||||||
|
}
|
||||||
|
presenciaOff.set(presencia->topic, out->topic, 0);
|
||||||
|
presenciaOff.setValSend("0");
|
||||||
|
presenciaOff.AddActivador(out,'>',0,0);//out encendido
|
||||||
|
presenciaOff.AddActivador(presencia,'<',1, 0);//no presencia
|
||||||
|
if(bloqueo)
|
||||||
|
{
|
||||||
|
presenciaOff.AddActivador(bloqueo,'>',0);
|
||||||
|
}
|
||||||
|
|
||||||
|
nivelLuzOff.set(nivelluz->topic, out->topic, 0);
|
||||||
|
nivelLuzOff.setValSend("0");
|
||||||
|
nivelLuzOff.AddActivador(out,'>',0, 0);//out encendido
|
||||||
|
nivelLuzOff.AddActivador(nivelluz,'>',fnivelLuz, 0);//no luz
|
||||||
|
if(bloqueo)
|
||||||
|
{
|
||||||
|
nivelLuzOff.AddActivador(bloqueo,'>',0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
man->Add(&presenciaOn);
|
||||||
|
man->Add(&nivelLuzOff);
|
||||||
|
man->Add(&presenciaOff);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -152,4 +152,10 @@ void DomoEspManager::Add(DomoEspSensorReceiver* sensor)
|
||||||
sensores[n]=sensor;
|
sensores[n]=sensor;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_PS
|
||||||
|
Serial.println("----------------------ERROR NO ENTRAN MAS SENSORES---------------- ");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ class SensorRF: public DomoEspSensorReceiver
|
||||||
}
|
}
|
||||||
virtual float getVal()
|
virtual float getVal()
|
||||||
{
|
{
|
||||||
return (float)val;
|
return val;
|
||||||
}
|
}
|
||||||
virtual void SubscribeMqtt(IMqttManager* man){
|
virtual void SubscribeMqtt(IMqttManager* man){
|
||||||
//char buffer_t[MAXTOPICVAR];
|
//char buffer_t[MAXTOPICVAR];
|
||||||
|
|
@ -33,6 +33,12 @@ class SensorRF: public DomoEspSensorReceiver
|
||||||
if(!strcmp(_topic, topic))
|
if(!strcmp(_topic, topic))
|
||||||
{
|
{
|
||||||
val=atof(payload);
|
val=atof(payload);
|
||||||
|
#ifdef DEBUG_PS
|
||||||
|
Serial.print(" RF-> ");
|
||||||
|
Serial.print(topic);
|
||||||
|
Serial.print(" -> ");
|
||||||
|
Serial.println(val);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,109 +1,23 @@
|
||||||
|
|
||||||
#ifndef DomoConfActualDef
|
#ifndef DomoConfActualDef
|
||||||
#define DomoConfActualDef 1
|
#define DomoConfActualDef 1
|
||||||
#include "DomoEspConfig.h"
|
|
||||||
#include "SensorDout.h"
|
#include "automatismos.h"
|
||||||
#include "SensorDHT.h"
|
|
||||||
#include "SensorDin.h"
|
|
||||||
#include "SensorPulsante.h"
|
|
||||||
#include "SensorAin.h"
|
|
||||||
#include "SensorVD.h"
|
|
||||||
#include "SensorRF.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include "MecanismoPulso.h"
|
|
||||||
//----------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
class AutomatismoPulsador//automatismo para encender luz con interruptor o pulsador
|
|
||||||
{
|
|
||||||
|
|
||||||
MecanismoPulso pulsador;//cambia estado con pulsador
|
|
||||||
public:
|
|
||||||
AutomatismoPulsador(){}
|
|
||||||
void inicia(ISensorManager* man, DomoEspSensorReceiver* tp_pul, DomoEspSensorReceiver* tpOut, DomoEspSensorReceiver* bloqueo=NULL )
|
|
||||||
{
|
|
||||||
inicia(man, tp_pul->topic, tpOut->topic, bloqueo);
|
|
||||||
}
|
|
||||||
void inicia(ISensorManager* man, char* tp_pul, char* tpOut, DomoEspSensorReceiver* bloqueo=NULL )
|
|
||||||
{
|
|
||||||
pulsador.set(tp_pul, tpOut, 0);
|
|
||||||
pulsador.setValSend("X");
|
|
||||||
if(bloqueo)
|
|
||||||
{
|
|
||||||
pulsador.AddActivador(bloqueo,'>',0);
|
|
||||||
}
|
|
||||||
man->Add(&pulsador);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
class AutomatismoPresencia//automatismo para encender luz con presencia
|
|
||||||
{
|
|
||||||
|
|
||||||
MecanismoPulso presenciaOn;
|
|
||||||
MecanismoPulso presenciaOff;
|
|
||||||
MecanismoPulso nivelLuzOff;
|
|
||||||
float fnivelLuz;
|
|
||||||
public:
|
|
||||||
AutomatismoPresencia()
|
|
||||||
{
|
|
||||||
fnivelLuz=50;
|
|
||||||
|
|
||||||
|
|
||||||
strcpy(presenciaOn.id, "PresOn");
|
|
||||||
strcpy(presenciaOff.id, "PresOff");
|
|
||||||
strcpy(nivelLuzOff.id, "luzOff");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void inicia(ISensorManager* man, DomoEspSensorReceiver* presencia, DomoEspSensorReceiver* nivelluz, DomoEspSensorReceiver* out, DomoEspSensorReceiver* bloqueo=NULL )
|
|
||||||
{
|
|
||||||
|
|
||||||
presenciaOn.set(presencia->topic, out->topic, 0);
|
|
||||||
presenciaOn.setValSend("1");
|
|
||||||
presenciaOn.AddActivador(nivelluz,'<',fnivelLuz);//nivel de luz bajo
|
|
||||||
presenciaOn.AddActivador(out,'<',1);//out apagada
|
|
||||||
presenciaOn.AddActivador(presencia,'>',0);//presencia
|
|
||||||
if(bloqueo)
|
|
||||||
{
|
|
||||||
presenciaOn.AddActivador(bloqueo,'>',0);
|
|
||||||
}
|
|
||||||
presenciaOff.set(presencia->topic, out->topic, 0);
|
|
||||||
presenciaOff.setValSend("0");
|
|
||||||
presenciaOff.AddActivador(out,'>',0);//out encendido
|
|
||||||
presenciaOff.AddActivador(presencia,'<',1);//no presencia
|
|
||||||
if(bloqueo)
|
|
||||||
{
|
|
||||||
presenciaOff.AddActivador(bloqueo,'>',0);
|
|
||||||
}
|
|
||||||
|
|
||||||
nivelLuzOff.set(nivelluz->topic, out->topic, 0);
|
|
||||||
nivelLuzOff.setValSend("0");
|
|
||||||
nivelLuzOff.AddActivador(out,'>',0);//out encendido
|
|
||||||
nivelLuzOff.AddActivador(nivelluz,'>',fnivelLuz);//no luz
|
|
||||||
if(bloqueo)
|
|
||||||
{
|
|
||||||
nivelLuzOff.AddActivador(bloqueo,'>',0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
man->Add(&presenciaOn);
|
|
||||||
man->Add(&nivelLuzOff);
|
|
||||||
man->Add(&presenciaOff);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//configuraciones-----------------------------------------------------
|
//configuraciones-----------------------------------------------------
|
||||||
class Automatismos: public DomoEspConfig
|
class ConfAutomatismos: public DomoEspConfig
|
||||||
{
|
{
|
||||||
SensorRF presencia;
|
SensorRF presencia;
|
||||||
SensorRF nivelLuz;
|
SensorRF nivelLuz;
|
||||||
SensorRF out;
|
SensorRF out;
|
||||||
SensorVD bloqueo;
|
SensorVD bloqueo;
|
||||||
|
|
||||||
//AutomatismoPulsador pulsadorSalon;
|
AutomatismoPulsador pulsador;
|
||||||
AutomatismoPresencia Apresen;
|
AutomatismoPresencia Apresen;
|
||||||
public:
|
public:
|
||||||
Automatismos()
|
ConfAutomatismos()
|
||||||
{
|
{
|
||||||
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
||||||
strcpy(ideEsp,"Esp8266_auto");//idenitificador del esp (sera único)
|
strcpy(ideEsp,"Esp8266_auto");//idenitificador del esp (sera único)
|
||||||
|
|
@ -124,6 +38,7 @@ class Automatismos: public DomoEspConfig
|
||||||
man->Add(&out);
|
man->Add(&out);
|
||||||
man->Add(&bloqueo);
|
man->Add(&bloqueo);
|
||||||
Apresen.inicia(man, &presencia, &nivelLuz,&out, &bloqueo);
|
Apresen.inicia(man, &presencia, &nivelLuz,&out, &bloqueo);
|
||||||
|
pulsador.inicia(man,"casa/pruebas/pul", "casa/pruebas/luz");
|
||||||
//pulsadorSalon.inicia(man,"casa/pruebas/pul", "casa/pruebas/luz");
|
//pulsadorSalon.inicia(man,"casa/pruebas/pul", "casa/pruebas/luz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,6 +85,6 @@ class ConfActual: public DomoEspConfig
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Automatismos ConfiguracionActual;
|
ConfAutomatismos ConfiguracionActual;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -11,10 +11,16 @@
|
||||||
#define MAXSTR 2024//maximo de caracteres para str
|
#define MAXSTR 2024//maximo de caracteres para str
|
||||||
|
|
||||||
//sens--------------------
|
//sens--------------------
|
||||||
#define MAXSENS 16
|
#define MAXSENS 16 //maximo de sensores totales
|
||||||
|
#define MAX_ACTIVADORES 5//maximo de activadores por actuador
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAXINTERRUP 8
|
#define MAXINTERRUP 8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef DO
|
#ifndef DO
|
||||||
#define D0 16
|
#define D0 16
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue