124 lines
2.8 KiB
C
124 lines
2.8 KiB
C
#include <Arduino.h>
|
|
#include <RotaryEncoder.h>
|
|
#include <Wire.h>
|
|
#include "ClosedCube_HDC1080.h"
|
|
#include <OneButton.h>
|
|
#include <PCF8574.h>
|
|
#include <LiquidCrystal_PCF8574.h>
|
|
#include <ArduinoOTA.h>
|
|
#include <pcf_butt.h>
|
|
#include <I2C_eeprom.h>
|
|
//#include <PubSubClient.h>
|
|
#include <OneWire.h>
|
|
#include <DallasTemperature.h>
|
|
#include <leds.h>
|
|
#include <Ticker.h>
|
|
#include <AsyncMqttClient.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
|
|
#define DEBUG
|
|
#define WIFI_SSID "wf-home"
|
|
#define WIFI_PASSWORD "0ndthnrf"
|
|
#define MY_HOSTNAME "ESP8266_GW"
|
|
//#define MQTT_SERV "192.168.1.250"
|
|
#define MQTT_SERV "192.168.1.111"
|
|
#define TOPIC "home/"
|
|
|
|
#define MAX_PAGE (4)
|
|
#define MAX_HSP (99)
|
|
#define MAX_HDB (99)
|
|
#define MAX_TWORK (99)
|
|
#define MAX_TPAUSE (99)
|
|
#define MAX_LCDPAUSE (99)
|
|
|
|
//#define LIGHT_SENS D0
|
|
#define VENT_VANNA (D0)
|
|
#define ASDA (D1)
|
|
#define ASCL (D2)
|
|
#define ENC_A (D3)
|
|
#define ENC_B (D4)
|
|
#define ONE_WIRE (D5)
|
|
#define VENT_TUAL (D6)
|
|
#define BUTT_ENC (D7)
|
|
|
|
#define LIGHT_SENS (0)
|
|
#define LED_RED (4)
|
|
#define LED_BLUE (5)
|
|
#define LED_GREEN (6)
|
|
#define LED_YELLOW (7)
|
|
#define FLOOD (1)
|
|
#define Q_C (3)
|
|
#define Q_H (2)
|
|
|
|
ClosedCube_HDC1080 hdc1080;
|
|
|
|
unsigned long cRun;
|
|
int8_t page;
|
|
float hum, temp;
|
|
float cTemp, hTemp;
|
|
uint8_t pcf_w;
|
|
uint8_t LCDtimeout, LCDsec;
|
|
bool modeEdit;
|
|
uint8_t itemEdit;
|
|
uint16_t adc;
|
|
float mws;
|
|
long curPos;
|
|
bool vvannaSent1, vvannaSent0;
|
|
|
|
AsyncMqttClient mqttClient;
|
|
Ticker mqttReconnectTimer;
|
|
WiFiEventHandler wifiConnectHandler;
|
|
WiFiEventHandler wifiDisconnectHandler;
|
|
Ticker wifiReconnectTimer;
|
|
//const char* mqtt_server = "192.168.1.250";
|
|
const char* mqtt_server = "192.168.1.111";
|
|
char v[12];
|
|
|
|
struct contacts
|
|
{
|
|
bool QC;
|
|
bool QH;
|
|
bool Flood;
|
|
} wconts;
|
|
|
|
struct wCnt
|
|
{
|
|
float QC;
|
|
float QH;
|
|
} wCounter, oldwCounter;
|
|
|
|
struct wUst{
|
|
uint8_t hSP;
|
|
uint8_t hDB;
|
|
} wUstavki, oldwUstavki;
|
|
|
|
struct stTualVent
|
|
{
|
|
uint8_t tWork;
|
|
uint8_t tPause;
|
|
} ventUst, oldventUst;
|
|
|
|
void printSerialNumber();
|
|
void buttClick();
|
|
void chkCount();
|
|
// void callback(char* topic, byte* payload, unsigned int length);
|
|
// void reconnect();
|
|
void showLCD(uint8_t page, bool chgd);
|
|
void chkEnc();
|
|
void getTemps();
|
|
void buttLongClick();
|
|
void chkLight();
|
|
void connectToWifi();
|
|
void connectToMqtt();
|
|
|
|
void onWifiConnect(const WiFiEventStationModeGotIP& event);
|
|
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
|
|
void onMqttConnect(bool sessionPresent);
|
|
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
|
|
void onMqttSubscribe(uint16_t packetId, uint8_t qos);
|
|
void onMqttUnsubscribe(uint16_t packetId);
|
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
|
|
void onMqttPublish(uint16_t packetId);
|
|
|
|
void sendData();
|