156 lines
2.7 KiB
C++
156 lines
2.7 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);
|
|
static void resetFunc()
|
|
{
|
|
ESP.wdtEnable(1);
|
|
while(1){};
|
|
}
|
|
};
|
|
|
|
|
|
class WifiManager
|
|
{
|
|
public:
|
|
|
|
char nred[32];
|
|
char pass[32];
|
|
char idArduino[32];
|
|
WiFiClient *espClient;
|
|
|
|
WifiManager();
|
|
bool conecta();
|
|
void inicia( WiFiClient *espClient, char *ssid, char* key, char *idArduino);
|
|
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[32];
|
|
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]);
|
|
};
|
|
};
|
|
|
|
class MelodiaBuzzer
|
|
{
|
|
public:
|
|
//melodia se compone de notas (primera letra y tiempo de duracion) silecio es #
|
|
char melodia[64];
|
|
MelodiaBuzzer();
|
|
int st2nota(char st);
|
|
int str2t(char* st, int *t);
|
|
|
|
void Toca(int pin);
|
|
};
|
|
|
|
class SonidoBuzzer
|
|
{
|
|
public:
|
|
MelodiaBuzzer mel[4];
|
|
int n;
|
|
SonidoBuzzer();
|
|
void Toca(int pin, int melodia);
|
|
int Add(char* melodia);
|
|
};
|
|
#endif
|