93 lines
1.5 KiB
C++
93 lines
1.5 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
|
|
|
|
|
|
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:
|
|
static MqttReceiver* listener;
|
|
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();
|
|
};
|
|
#endif
|