DomoEsp_v2.0/DomoEspSensor/SensorRF.h

52 lines
1.1 KiB
C++

#ifndef SensorRFDef
#define SensorRFDef 1
#include "defines.h"
//sensor Replica, sensor interno que se setea con get y no se publica
class SensorRF: public DomoEspSensorReceiver
{
float val;
bool negado;
public:
SensorRF()
{
negado=0;
val=0;
topic[0]=0;
}
void set(char* topic_id,bool _negado=0, float valdef=0)
{
negado=_negado;
val=valdef;
strcpy(topic, topic_id);
}
virtual float getVal()
{
return val;
}
virtual void SubscribeMqtt(IMqttManager* man){
//char buffer_t[MAXTOPICVAR];
sprintf(buffer_t, "%s/get",topic);
man->MqttSubs(buffer_t);
}
virtual void OnMqtt(IMqttManager * man, char* _topic, char* payload, int tipo)
{
if(tipo!=Topic::GET)
return;
if(!strcmp(_topic, topic))
{
val=atof(payload);
if(negado && val>0)
val=0;
/*#ifdef DEBUG_PS
Serial.print(" RF-> ");
Serial.print(topic);
Serial.print(" -> ");
Serial.println(val);
#endif*/
}
}
};
#endif