Compare commits
3 Commits
519b95a0f9
...
809b2e6d64
| Author | SHA1 | Date |
|---|---|---|
|
|
809b2e6d64 | |
|
|
07a0f53eb8 | |
|
|
6dfafd1390 |
|
|
@ -48,17 +48,17 @@ class AutomatismoPresencia//automatismo para encender luz con presencia
|
||||||
|
|
||||||
Actuador presenciaOn;
|
Actuador presenciaOn;
|
||||||
Actuador presenciaOff;
|
Actuador presenciaOff;
|
||||||
Actuador nivelLuzOff;
|
//Actuador nivelLuzOff;
|
||||||
float fnivelLuz;
|
float fnivelLuz;
|
||||||
public:
|
public:
|
||||||
AutomatismoPresencia()
|
AutomatismoPresencia()
|
||||||
{
|
{
|
||||||
fnivelLuz=50;
|
fnivelLuz=40;
|
||||||
|
|
||||||
|
|
||||||
strcpy(presenciaOn.id, "PresOn");
|
strcpy(presenciaOn.id, "PresOn");
|
||||||
strcpy(presenciaOff.id, "PresOff");
|
strcpy(presenciaOff.id, "PresOff");
|
||||||
strcpy(nivelLuzOff.id, "luzOff");
|
//strcpy(nivelLuzOff.id, "luzOff");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +81,7 @@ class AutomatismoPresencia//automatismo para encender luz con presencia
|
||||||
{
|
{
|
||||||
presenciaOff.AddActivador(bloqueo,'>',0);
|
presenciaOff.AddActivador(bloqueo,'>',0);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
nivelLuzOff.set(nivelluz->topic, out->topic, "0");
|
nivelLuzOff.set(nivelluz->topic, out->topic, "0");
|
||||||
nivelLuzOff.AddActivador(out,'>',0, 0);//out encendido
|
nivelLuzOff.AddActivador(out,'>',0, 0);//out encendido
|
||||||
nivelLuzOff.AddActivador(nivelluz,'>',fnivelLuz, 0);//no luz
|
nivelLuzOff.AddActivador(nivelluz,'>',fnivelLuz, 0);//no luz
|
||||||
|
|
@ -89,10 +89,10 @@ class AutomatismoPresencia//automatismo para encender luz con presencia
|
||||||
{
|
{
|
||||||
nivelLuzOff.AddActivador(bloqueo,'>',0);
|
nivelLuzOff.AddActivador(bloqueo,'>',0);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
man->Add(&presenciaOn);
|
man->Add(&presenciaOn);
|
||||||
man->Add(&nivelLuzOff);
|
//man->Add(&nivelLuzOff);
|
||||||
man->Add(&presenciaOff);
|
man->Add(&presenciaOff);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ DomoEspManager::DomoEspManager()
|
||||||
n=0;
|
n=0;
|
||||||
tiempo=0;
|
tiempo=0;
|
||||||
suscrito=false;
|
suscrito=false;
|
||||||
tiempo_sens=0;
|
|
||||||
SetTimeRefres(15);
|
SetTimeRefres(15);
|
||||||
}
|
}
|
||||||
void DomoEspManager::SetTimeRefres(int seg)
|
void DomoEspManager::SetTimeRefres(int seg)
|
||||||
{
|
{
|
||||||
incre_tsens=seg*1000;
|
timer.set(seg);
|
||||||
}
|
}
|
||||||
void DomoEspManager::inicia(DomoEspConfig* cnf)
|
void DomoEspManager::inicia(DomoEspConfig* cnf)
|
||||||
{
|
{
|
||||||
|
|
@ -70,7 +69,7 @@ void DomoEspManager::loop()
|
||||||
suscrito=true;
|
suscrito=true;
|
||||||
}
|
}
|
||||||
int tiempoAux=0;
|
int tiempoAux=0;
|
||||||
if(MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
if(timer.onTimerReset())
|
||||||
{
|
{
|
||||||
|
|
||||||
tiempo=(tiempo+1)%2;
|
tiempo=(tiempo+1)%2;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ class DomoEspManager: public MqttReceiver, public IMqttManager, public ISensorMa
|
||||||
int n;
|
int n;
|
||||||
int tiempo;
|
int tiempo;
|
||||||
bool suscrito;
|
bool suscrito;
|
||||||
unsigned long tiempo_sens;
|
Ctimer timer;
|
||||||
unsigned long incre_tsens;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,19 @@ class SensorDin: public DomoEspSensorReceiver
|
||||||
{
|
{
|
||||||
bool val;
|
bool val;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
|
bool logTiempo2;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual float getVal()
|
virtual float getVal()
|
||||||
{
|
{
|
||||||
return (float)val;
|
return (float)val;
|
||||||
}
|
}
|
||||||
SensorDin(){}
|
SensorDin(){
|
||||||
void set(uint8_t _pin, char* topic_id)
|
logTiempo2=true;
|
||||||
|
}
|
||||||
|
void set(uint8_t _pin, char* topic_id, bool _logTiempo2=true)
|
||||||
{
|
{
|
||||||
|
logTiempo2=_logTiempo2;
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
val=0;
|
val=0;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
@ -25,7 +28,7 @@ class SensorDin: public DomoEspSensorReceiver
|
||||||
//mirar para configurar por interrupcion
|
//mirar para configurar por interrupcion
|
||||||
int val_ac=digitalRead(pin);
|
int val_ac=digitalRead(pin);
|
||||||
|
|
||||||
if(tiempo==2 || val_ac!=val)
|
if((logTiempo2 && tiempo==2) || val_ac!=val)
|
||||||
{
|
{
|
||||||
val=val_ac;
|
val=val_ac;
|
||||||
//loguea------------
|
//loguea------------
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ bool negado;
|
||||||
val=!val;
|
val=!val;
|
||||||
else
|
else
|
||||||
val=(atoi(payload)==1);
|
val=(atoi(payload)==1);
|
||||||
//cambia estado relle
|
//cambia estado relleH
|
||||||
if(negado)
|
if(negado)
|
||||||
digitalWrite(pin, val==0);
|
digitalWrite(pin, val==0);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,19 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
bool val;
|
bool val;
|
||||||
bool valDef;
|
bool valDef;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
|
unsigned long tiempo_sens;
|
||||||
|
unsigned long incre_tsens;
|
||||||
|
bool espera;
|
||||||
public:
|
public:
|
||||||
virtual float getVal()
|
virtual float getVal()
|
||||||
{
|
{
|
||||||
return (float)val;
|
return (float)val;
|
||||||
}
|
}
|
||||||
SensorPulsante()
|
SensorPulsante()
|
||||||
{}
|
{
|
||||||
|
espera=false;
|
||||||
|
incre_tsens=500;
|
||||||
|
}
|
||||||
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
||||||
{
|
{
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
|
|
@ -22,10 +27,21 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
val=valDef;
|
val=valDef;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
}
|
}
|
||||||
|
void setIncremento(int milis)
|
||||||
|
{
|
||||||
|
incre_tsens=milis;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void procesa(IMqttManager * man, int tiempo)
|
virtual void procesa(IMqttManager * man, int tiempo)
|
||||||
{
|
{
|
||||||
//mirar para configurar por interrupcion
|
//mirar para configurar por interrupcion
|
||||||
int val_ac=digitalRead(pin);
|
int val_ac=val;
|
||||||
|
if(!espera || MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
||||||
|
{
|
||||||
|
val_ac=digitalRead(pin);
|
||||||
|
espera=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(val_ac!=val && val_ac!=valDef)
|
if(val_ac!=val && val_ac!=valDef)
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +52,10 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
sprintf(buffer_p, "%d", (int)val_ac);
|
sprintf(buffer_p, "%d", (int)val_ac);
|
||||||
sprintf(buffer_t, "%s/pul",topic);
|
sprintf(buffer_t, "%s/pul",topic);
|
||||||
man->MqttSend(buffer_t, buffer_p);
|
man->MqttSend(buffer_t, buffer_p);
|
||||||
delay(100);
|
//delay(100);
|
||||||
|
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||||
|
espera=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
val=val_ac;
|
val=val_ac;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
||||||
{
|
{
|
||||||
bool val;
|
bool val;
|
||||||
bool valDef;
|
bool valDef;
|
||||||
unsigned long tiempo_sens;
|
Ctimer t;
|
||||||
unsigned long incre_tsens;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SensorTimer()
|
SensorTimer()
|
||||||
|
|
@ -17,8 +16,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
||||||
}
|
}
|
||||||
void set(char* topic_id, bool _valdef, int segTime)
|
void set(char* topic_id, bool _valdef, int segTime)
|
||||||
{
|
{
|
||||||
incre_tsens=1000*segTime;
|
t.set(segTime);
|
||||||
|
|
||||||
valDef=_valdef;
|
valDef=_valdef;
|
||||||
val=valDef;
|
val=valDef;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
@ -31,7 +29,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
||||||
{
|
{
|
||||||
if(val!=valDef)
|
if(val!=valDef)
|
||||||
{
|
{
|
||||||
if(MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
if(t.onTimer())
|
||||||
{
|
{
|
||||||
val=valDef;
|
val=valDef;
|
||||||
tiempo=2;
|
tiempo=2;
|
||||||
|
|
@ -70,8 +68,8 @@ class SensorTimer: public DomoEspSensorReceiver
|
||||||
val=1;
|
val=1;
|
||||||
else
|
else
|
||||||
val=0;
|
val=0;
|
||||||
|
t.inicia();
|
||||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
//MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||||
}
|
}
|
||||||
else if(tipo==Topic::SET)
|
else if(tipo==Topic::SET)
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +78,8 @@ class SensorTimer: public DomoEspSensorReceiver
|
||||||
else
|
else
|
||||||
val=atof(payload);
|
val=atof(payload);
|
||||||
if(val!=valDef)
|
if(val!=valDef)
|
||||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
t.inicia();
|
||||||
|
//MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(valOld!=val)
|
if(valOld!=val)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class SensorVF: public DomoEspSensorReceiver
|
||||||
val=0;
|
val=0;
|
||||||
topic[0]=0;
|
topic[0]=0;
|
||||||
}
|
}
|
||||||
void set(char* topic_id, float valdef)
|
void set(char* topic_id, float valdef=0)
|
||||||
{
|
{
|
||||||
val=valdef;
|
val=valdef;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,43 @@ void MqttUtiles::resetFunc()
|
||||||
ESP.wdtEnable(1);
|
ESP.wdtEnable(1);
|
||||||
while(1){};
|
while(1){};
|
||||||
}
|
}
|
||||||
|
//**************************************************************************************************************************************************
|
||||||
|
Ctimer::Ctimer()
|
||||||
|
{
|
||||||
|
t=0;
|
||||||
|
}
|
||||||
|
void Ctimer::set(int incremento_seg)
|
||||||
|
{
|
||||||
|
incre=1000*incremento_seg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ctimer::inicia()
|
||||||
|
{
|
||||||
|
t=millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ctimer::onTimer()
|
||||||
|
{
|
||||||
|
unsigned long ta=millis();
|
||||||
|
if(ta<t)
|
||||||
|
return true;
|
||||||
|
if((t+incre)>=ta)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Ctimer::onTimerReset()
|
||||||
|
{
|
||||||
|
unsigned long ta=millis();
|
||||||
|
if(ta<t)
|
||||||
|
{
|
||||||
|
t=ta;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if((t+incre)>=ta)
|
||||||
|
return false;
|
||||||
|
t=ta;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
//**************************************************************************************************************************************************
|
//**************************************************************************************************************************************************
|
||||||
WifiManager::WifiManager()
|
WifiManager::WifiManager()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,20 @@ class MqttUtiles
|
||||||
static void resetFunc();
|
static void resetFunc();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Ctimer
|
||||||
|
{
|
||||||
|
unsigned long t;
|
||||||
|
unsigned long incre;
|
||||||
|
public:
|
||||||
|
Ctimer();
|
||||||
|
|
||||||
|
void set(int incremento_seg);
|
||||||
|
|
||||||
|
void inicia();//inicia contador de incremento
|
||||||
|
bool onTimer();//devuelve true si ha pasado el tiempo
|
||||||
|
bool onTimerReset();//pasa incremento y si ha pasado se reinicia
|
||||||
|
};
|
||||||
|
|
||||||
class MqttOnVarChangeListenner
|
class MqttOnVarChangeListenner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,63 @@ class ConfActual: public DomoEspConfig
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
class ConfCocina: public DomoEspConfig
|
||||||
|
{
|
||||||
|
SensorDHT dht;
|
||||||
|
SensorAin luz;
|
||||||
|
SensorDout lampara;
|
||||||
|
SensorPulsante presencia;
|
||||||
|
SensorTimer tpresencia;
|
||||||
|
|
||||||
|
SensorDin interruptor;
|
||||||
|
SensorVF enable;
|
||||||
|
|
||||||
|
AutomatismoPresencia actuador;
|
||||||
|
AutomatismoPulsador actuadorPul;
|
||||||
|
Actuador actp1;
|
||||||
|
public:
|
||||||
|
ConfCocina()
|
||||||
|
{
|
||||||
|
strcpy(ssidWifi,"Idhun");//nombre wifi
|
||||||
|
strcpy(ideEsp,"Esp8266_cocina");//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(D4,"casa/cocina");
|
||||||
|
|
||||||
|
luz.set(0, "casa/cocina/luz",1,0);
|
||||||
|
lampara.set(D2, "casa/cocina/lam",0,0);
|
||||||
|
presencia.set(D5, "casa/cocina/movPul",0);
|
||||||
|
tpresencia.set("casa/cocina/mov",0, 60);
|
||||||
|
enable.set("casa/cocina/luzAuto");
|
||||||
|
interruptor.set( D1, "casa/cocina/inter", false);
|
||||||
|
actp1.set("casa/cocina/movPul", "casa/cocina/mov","1");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual void inicia(ISensorManager* man)
|
||||||
|
{
|
||||||
|
man->Add(&dht);
|
||||||
|
|
||||||
|
man->Add(&luz);
|
||||||
|
man->Add(&lampara);
|
||||||
|
man->Add(&presencia);
|
||||||
|
man->Add(&tpresencia);
|
||||||
|
man->Add(&enable);
|
||||||
|
man->Add(&interruptor);
|
||||||
|
man->Add(&actp1);
|
||||||
|
|
||||||
|
actuadorPul.inicia(man, &interruptor, &lampara);
|
||||||
|
actuador.inicia(man, &tpresencia, &luz, &lampara, &enable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -203,7 +260,7 @@ class ConfigSalon: public DomoEspConfig
|
||||||
strcpy(ideEsp,"Esp8266_Salon");//idenitificador del esp (sera único)
|
strcpy(ideEsp,"Esp8266_Salon");//idenitificador del esp (sera único)
|
||||||
|
|
||||||
dht.set(D4, "casa/Salon");
|
dht.set(D4, "casa/Salon");
|
||||||
nivelLuz.set(0,"casa/Salon/luz",1, 0);
|
nivelLuz.set(0,"casa/Salon/luz",0, 0);
|
||||||
presencia.set(D5, "casa/Salon/movEven");
|
presencia.set(D5, "casa/Salon/movEven");
|
||||||
presenciaTimer.set("casa/Salon/mov",0,60);
|
presenciaTimer.set("casa/Salon/mov",0,60);
|
||||||
actTimer.set("casa/Salon/movEven", "casa/Salon/mov","1");
|
actTimer.set("casa/Salon/movEven", "casa/Salon/mov","1");
|
||||||
|
|
@ -321,6 +378,6 @@ class ConfPulSalon: public DomoEspConfig
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfPulSalon ConfiguracionActual;
|
ConfigSalon ConfiguracionActual;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue