80 lines
1.9 KiB
C
80 lines
1.9 KiB
C
#include <Arduino.h>
|
|
#include <Ticker.h>
|
|
#include <ESP8266WiFi.h>
|
|
#include <ArduinoOTA.h>
|
|
#include <ESPAsyncTCP.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include <WebSerial.h>
|
|
#include <ESP_EEPROM.h>
|
|
#include <PubSubClient.h>
|
|
#include "OneButton.h"
|
|
|
|
#include <SPI.h>
|
|
//#include "LedController.hpp"
|
|
#include <GyverSegment.h>
|
|
#define DIO_PIN 13
|
|
#define CLK_PIN 14
|
|
#define LAT_PIN 12
|
|
Disp7219<1> disp(DIO_PIN, CLK_PIN, LAT_PIN);
|
|
|
|
#include <OneWire.h>
|
|
#include <DallasTemperature.h>
|
|
|
|
//#include <PID_v1.h>
|
|
#include "GyverPID.h"
|
|
GyverPID regulator;
|
|
#include "PWMrelay.h"
|
|
#define TRIAC_PIN 15
|
|
PWMrelay relay(TRIAC_PIN, true); // реле на 15 пине
|
|
|
|
#define ONE_WIRE_BUS 2
|
|
|
|
#define WIFI_SSID "wf-home"
|
|
#define WIFI_PASSWORD "0ndthnrf"
|
|
#define MQTT_SERV "192.168.1.111"
|
|
#define HOSTNAME "Box-balkon"
|
|
|
|
#define TOPIC "home/box/"
|
|
|
|
|
|
#define PLUS_BUT 16
|
|
#define MINUS_BUT 0
|
|
OneButton plusBut(PLUS_BUT, true, true);
|
|
OneButton minusBut(MINUS_BUT, true, true);
|
|
|
|
WiFiClient espClient;
|
|
PubSubClient client(espClient);
|
|
WiFiEventHandler wifiConnectHandler;
|
|
WiFiEventHandler wifiDisconnectHandler;
|
|
Ticker wifiReconnectTimer;
|
|
|
|
AsyncWebServer server(80);
|
|
|
|
OneWire oneWire(ONE_WIRE_BUS);
|
|
DallasTemperature sensors(&oneWire);
|
|
|
|
|
|
float temp_sp, temp1, temp2;
|
|
float kp = 0, ki = 0, kd = 0;
|
|
double Output = 0, Setpoint = 0, Input = 0;
|
|
|
|
// PID myPID(&Input, &Output, &Setpoint, kp, ki, kd, DIRECT);
|
|
// unsigned long WindowSize = 5000;
|
|
// unsigned long windowStartTime;
|
|
|
|
long lastReconnectAttempt = 0;
|
|
|
|
boolean wifi = false;
|
|
|
|
void connectToWifi();
|
|
void connectToMqtt();
|
|
void onWifiConnect(const WiFiEventStationModeGotIP& event);
|
|
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
|
|
void callback(char* topic, byte* payload, unsigned int length);
|
|
boolean reconnect();
|
|
void PlusButPress();
|
|
void PlusButLongPress();
|
|
void MinusButPress();
|
|
void MinusButLongPress();
|
|
void display();
|
|
void pubData(const char* topic, float val); |