DomoEsp_v1/DomoEsp_v01/MqttUtiles.h

129 lines
2.2 KiB
C++

#ifndef MqttUtilesrDef
#define MqttUtilesDef 1
//#include <WiFi.h>//este para esp32
#include <ESP8266WiFi.h>//este para esp8266*/
class PubSubClient;
class WiFiClient;
#ifndef DO
#define D0 16
#endif
#ifndef D1
#define D1 5
#endif
#ifndef D2
#define D2 4
#endif
#ifndef D3
#define D3 0
#endif
#ifndef D4
#define D4 2
#endif
#ifndef D5
#define D5 14
#endif
#ifndef D6
#define D6 12
#endif
#ifndef D7
#define D7 13
#endif
#ifndef D8
#define D8 15
#endif
#include "MQTTDefines.h"
//interfaces listener---------------------------------------
class MqttUtiles
{
public:
static bool pasa_incre( unsigned long *tt, unsigned long incre);
static bool pasa_incre( volatile unsigned long *tt, unsigned long incre);
};
class WifiManager
{
public:
char nred[32];
char pass[32];
WiFiClient *espClient;
WifiManager();
void inicia( WiFiClient *espClient, char *ssid, char* key);
bool loop();
};
class MqttReceiver
{
public:
virtual void OnMqtt(char* topic, char* payload)=0;
virtual void SubscribeMqtt(PubSubClient *client_mqtt){}
};
class MqttManager
{
public:
private:
char idEsp[16];
public:
PubSubClient *client_mqtt;
MqttManager();
/*
WiFiClient espClient;//conexion a wifi
PubSubClient client_qqtt(espClient);//para conexion con mqtt
*/
void inicia(PubSubClient *mqttClient,char *ideEsp, char *host, int port, MqttReceiver* classReceiver);
bool loop();
void desconecta();
//auxiliar------------------
static void OnMqtt(char* topic, byte* payload, unsigned int length);
void subscribe_mqtt();
};
static MqttReceiver* Mqttlistener;
class Ceprom_manager
{
public:
int nb;
Ceprom_manager();
void leeb(byte *p);//lee un byte y deja en p
void grabab(byte p);//graba en eprom un byte
void graba_st(char *st);
void fin_grabacion();//hace efectivos los cambios en la eprom
void cursor(int pos=0);//mueve cursor a posicion indicada
template <class Cgeneg>
void get(Cgeneg* dout)//lee entero
{
byte *b=(byte)dout;
for(int i=sizeof(Cgeneg); i>0;i--)
leeb(&b[i]);
};
template <class Cgenes>
void set(Cgenes* dout)//lee entero
{
byte *b=(byte*)dout;
for(int i=sizeof(Cgenes); i>0;i--)
grabab(b[i]);
};
};
#endif