99 lines
2.1 KiB
C++
99 lines
2.1 KiB
C++
#ifndef SensorSplitterDef
|
|
#define SensorSplitterDef 1
|
|
#include "defines.h"
|
|
//sensor virtual
|
|
class SplitterSend
|
|
{
|
|
public:
|
|
SplitterSend(){}
|
|
DomoEspSensorReceiver *sen;
|
|
};
|
|
|
|
class SensorSplitter: public DomoEspSensorReceiver
|
|
{
|
|
float val;
|
|
SplitterSend sensorSend[MAX_ACTIVADORES];
|
|
|
|
public:
|
|
SensorSplitter()
|
|
{
|
|
val=0;
|
|
topic[0]=0;
|
|
for(int i=0; i<MAX_ACTIVADORES; i++)
|
|
sensorSend[i].sen=0;
|
|
}
|
|
void set(const char* topic_id, float =0)
|
|
{
|
|
val=0;
|
|
strcpy(topic, topic_id);
|
|
}
|
|
void AddSens(DomoEspSensorReceiver* sen)
|
|
{
|
|
for(int i=0; i<MAX_ACTIVADORES; i++)
|
|
{
|
|
if(sensorSend[i].sen==NULL)
|
|
{
|
|
sensorSend[i].sen=sen;
|
|
return;
|
|
}
|
|
}
|
|
#ifdef DEBUG_PS
|
|
|
|
Serial.println("----------------------ERROR NO ENTRAN MAS SENSORES EN SPLITTER---------------- ");
|
|
#endif
|
|
}
|
|
virtual float getVal()
|
|
{
|
|
return (float)val;
|
|
}
|
|
virtual void SubscribeMqtt(IMqttManager* man){
|
|
//char buffer_t[MAXTOPICVAR];
|
|
sprintf(buffer_t, "%s/set",topic);
|
|
man->MqttSubs(buffer_t);
|
|
sprintf(buffer_t, "%s/pul",topic);
|
|
man->MqttSubs(buffer_t);
|
|
}
|
|
virtual void OnMqtt(IMqttManager * man, char* _topic, char* payload, int tipo)
|
|
{
|
|
if(tipo!=Topic::SET && tipo!=Topic::PUL)
|
|
return;
|
|
if(strcmp(_topic, topic))
|
|
return;
|
|
|
|
if(tipo==Topic::SET )
|
|
{
|
|
if(payload[0]=='X')
|
|
{
|
|
if(val==0)
|
|
val=1;
|
|
else
|
|
val=0;
|
|
}
|
|
else
|
|
val=atof(payload);
|
|
for(int i=0; i<MAX_ACTIVADORES; i++)
|
|
{
|
|
if(sensorSend[i].sen)
|
|
{
|
|
sprintf(buffer_t, "%s/set",sensorSend[i].sen->topic);
|
|
man->MqttSend(buffer_t, payload);
|
|
}
|
|
}
|
|
|
|
}
|
|
else if(tipo==Topic::PUL )
|
|
{
|
|
for(int i=0; i<MAX_ACTIVADORES; i++)
|
|
{
|
|
|
|
if(sensorSend[i].sen)
|
|
{
|
|
sprintf(buffer_t, "%s/pul",sensorSend[i].sen->topic);
|
|
man->MqttSend(buffer_t, payload);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif |