Added BOX Balkon, LightTBL D1-Mini
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include <WebSerial.h>
|
#include <WebSerial.h>
|
||||||
#include <ESP_EEPROM.h>
|
#include <ESP_EEPROM.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
#include "OneButton.h"
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
//#include "LedController.hpp"
|
//#include "LedController.hpp"
|
||||||
@@ -19,7 +20,12 @@ Disp7219<1> disp(DIO_PIN, CLK_PIN, LAT_PIN);
|
|||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
#include <PID_v1.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 ONE_WIRE_BUS 2
|
||||||
|
|
||||||
@@ -30,7 +36,11 @@ Disp7219<1> disp(DIO_PIN, CLK_PIN, LAT_PIN);
|
|||||||
|
|
||||||
#define TOPIC "home/box/"
|
#define TOPIC "home/box/"
|
||||||
|
|
||||||
#define TRIAC_PIN 4
|
|
||||||
|
#define PLUS_BUT 16
|
||||||
|
#define MINUS_BUT 0
|
||||||
|
OneButton plusBut(PLUS_BUT, true, true);
|
||||||
|
OneButton minusBut(MINUS_BUT, true, true);
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
@@ -40,8 +50,6 @@ Ticker wifiReconnectTimer;
|
|||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
//LedController lc;
|
|
||||||
|
|
||||||
OneWire oneWire(ONE_WIRE_BUS);
|
OneWire oneWire(ONE_WIRE_BUS);
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
|
|
||||||
@@ -50,9 +58,9 @@ float temp_sp, temp1, temp2;
|
|||||||
float kp = 0, ki = 0, kd = 0;
|
float kp = 0, ki = 0, kd = 0;
|
||||||
double Output = 0, Setpoint = 0, Input = 0;
|
double Output = 0, Setpoint = 0, Input = 0;
|
||||||
|
|
||||||
PID myPID(&Input, &Output, &Setpoint, kp, ki, kd, DIRECT);
|
// PID myPID(&Input, &Output, &Setpoint, kp, ki, kd, DIRECT);
|
||||||
unsigned long WindowSize = 5000;
|
// unsigned long WindowSize = 5000;
|
||||||
unsigned long windowStartTime;
|
// unsigned long windowStartTime;
|
||||||
|
|
||||||
long lastReconnectAttempt = 0;
|
long lastReconnectAttempt = 0;
|
||||||
|
|
||||||
@@ -64,4 +72,9 @@ void onWifiConnect(const WiFiEventStationModeGotIP& event);
|
|||||||
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
|
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
|
||||||
void callback(char* topic, byte* payload, unsigned int length);
|
void callback(char* topic, byte* payload, unsigned int length);
|
||||||
boolean reconnect();
|
boolean reconnect();
|
||||||
void out_value(byte digit, float val);
|
void PlusButPress();
|
||||||
|
void PlusButLongPress();
|
||||||
|
void MinusButPress();
|
||||||
|
void MinusButLongPress();
|
||||||
|
void display();
|
||||||
|
void pubData(const char* topic, float val);
|
||||||
@@ -21,7 +21,9 @@ lib_deps =
|
|||||||
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
||||||
ayushsharma82/WebSerial @ ^1.3.0
|
ayushsharma82/WebSerial @ ^1.3.0
|
||||||
jwrw/ESP_EEPROM @ ^2.0.0
|
jwrw/ESP_EEPROM @ ^2.0.0
|
||||||
br3ttb/PID @ ^1.2.1
|
;br3ttb/PID @ ^1.2.1
|
||||||
milesburton/DallasTemperature @ ^3.11.0
|
milesburton/DallasTemperature @ ^3.11.0
|
||||||
thomasfredericks/Bounce2 @ ^2.72
|
|
||||||
gyverlibs/GyverSegment @ ^1.4.7
|
gyverlibs/GyverSegment @ ^1.4.7
|
||||||
|
mathertel/OneButton @ ^2.6.1
|
||||||
|
gyverlibs/PWMrelay @ ^1.2
|
||||||
|
gyverlibs/GyverPID @ ^3.3.2
|
||||||
|
|||||||
@@ -37,50 +37,72 @@ void setup() {
|
|||||||
temp1 = sensors.getTempCByIndex(0);
|
temp1 = sensors.getTempCByIndex(0);
|
||||||
if(temp1 < -100) temp1 = -99;
|
if(temp1 < -100) temp1 = -99;
|
||||||
|
|
||||||
EEPROM.begin(8);
|
EEPROM.begin(16);
|
||||||
|
|
||||||
EEPROM.get(0, temp_sp);
|
EEPROM.get(0, temp_sp);
|
||||||
//if(isnan(temp_sp) || temp_sp == 0) temp_sp = 4.0f;
|
//if(isnan(temp_sp) || temp_sp == 0) temp_sp = 4.0f;
|
||||||
//out_value(1, temp_sp);
|
//out_value(1, temp_sp);
|
||||||
|
|
||||||
EEPROM.get(2, kp);
|
EEPROM.get(4, kp);
|
||||||
//if(isnan(kp) || kp == 0) kp = 2.0f;
|
//if(isnan(kp) || kp == 0) kp = 2.0f;
|
||||||
EEPROM.get(4, ki);
|
EEPROM.get(8, ki);
|
||||||
//if(isnan(ki) || ki == 0) ki = 2.0f;
|
//if(isnan(ki) || ki == 0) ki = 2.0f;
|
||||||
EEPROM.get(6, kd);
|
EEPROM.get(12, kd);
|
||||||
//if(isnan(kd)) kd = 0.0f;
|
//if(isnan(kd)) kd = 0.0f;
|
||||||
|
|
||||||
// // myPID.SetTunings(kp, ki, kd);
|
Setpoint = temp_sp;
|
||||||
// // Setpoint = temp_sp;
|
// windowStartTime = millis();
|
||||||
// // windowStartTime = millis();
|
// myPID.SetOutputLimits(0, WindowSize);
|
||||||
// // myPID.SetOutputLimits(0, WindowSize);
|
// myPID.SetMode(AUTOMATIC);
|
||||||
// // myPID.SetMode(AUTOMATIC);
|
// myPID.SetTunings(kp, ki, kd);
|
||||||
// lastReconnectAttempt = 0;
|
// // lastReconnectAttempt = 0;
|
||||||
|
regulator.setDirection(NORMAL); // направление регулирования (NORMAL/REVERSE). ПО УМОЛЧАНИЮ СТОИТ NORMAL
|
||||||
|
regulator.setLimits(0, 255); // пределы (ставим для 8 битного ШИМ). ПО УМОЛЧАНИЮ СТОЯТ 0 И 255
|
||||||
|
regulator.Kp = kp;
|
||||||
|
regulator.Ki = ki;
|
||||||
|
regulator.Kd = kd;
|
||||||
|
regulator.setpoint = temp_sp;
|
||||||
|
|
||||||
|
plusBut.attachClick(PlusButPress);
|
||||||
|
plusBut.attachDuringLongPress(PlusButLongPress);
|
||||||
|
plusBut.setLongPressIntervalMs(1000);
|
||||||
|
minusBut.attachClick(MinusButPress);
|
||||||
|
minusBut.attachDuringLongPress(MinusButLongPress);
|
||||||
|
minusBut.setLongPressIntervalMs(1000);
|
||||||
|
pinMode(TRIAC_PIN, OUTPUT);
|
||||||
Serial.println("setup end");
|
Serial.println("setup end");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
static unsigned long cRun = millis();
|
static unsigned long cRun = millis();
|
||||||
static bool measTemp = false;
|
static bool measTemp = false;
|
||||||
|
static int secs = 0;
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
|
plusBut.tick();
|
||||||
|
minusBut.tick();
|
||||||
|
|
||||||
if(cRun + 1000 <= millis()){
|
if(cRun + 1000 <= millis()){
|
||||||
cRun = millis();
|
cRun = millis();
|
||||||
Serial.print("WiFi: ");Serial.print(wifi);
|
Serial.print("WiFi: ");Serial.print(wifi);
|
||||||
Serial.print(", MQTT: ");Serial.println(client.connected());
|
Serial.print(", MQTT: ");Serial.println(client.connected());
|
||||||
|
|
||||||
if(measTemp) {
|
if(measTemp) {
|
||||||
temp1 = sensors.getTempCByIndex(0);
|
temp1 = sensors.getTempCByIndex(0);
|
||||||
if(temp1 < -100) temp1 = -99.0;
|
if(temp1 < -100) temp1 = -99.0;
|
||||||
//out_value(0, temp1);
|
regulator.input = temp1;
|
||||||
Input = temp1;
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
sensors.requestTemperatures();
|
sensors.requestTemperatures();
|
||||||
}
|
}
|
||||||
|
Serial.print("Input: ");Serial.println(temp1);
|
||||||
|
Serial.print("SetPoint: ");Serial.println(temp_sp);
|
||||||
|
Serial.print("Regulator: ");Serial.println(regulator.getResultTimer());
|
||||||
measTemp = !measTemp;
|
measTemp = !measTemp;
|
||||||
disp.setCursor(1);
|
display();
|
||||||
disp.printf("%4.1f%5.1f", temp_sp, temp1);
|
if(++secs == 10){
|
||||||
disp.update();
|
secs = 0;
|
||||||
|
pubData(TOPIC"temp1", temp1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (wifi && !client.connected()) {
|
if (wifi && !client.connected()) {
|
||||||
long now = millis();
|
long now = millis();
|
||||||
@@ -96,18 +118,12 @@ void loop() {
|
|||||||
// Client connected
|
// Client connected
|
||||||
client.loop();
|
client.loop();
|
||||||
}
|
}
|
||||||
Input = temp1;
|
if(temp1 > -99){
|
||||||
if(Input > -99){
|
relay.setPWM(regulator.getResultTimer());
|
||||||
myPID.Compute();
|
relay.tick();
|
||||||
|
|
||||||
if (millis() - windowStartTime > WindowSize)
|
|
||||||
{ //time to shift the Relay Window
|
|
||||||
windowStartTime += WindowSize;
|
|
||||||
}
|
|
||||||
if (Output < millis() - windowStartTime) digitalWrite(TRIAC_PIN, HIGH);
|
|
||||||
else digitalWrite(TRIAC_PIN, LOW);
|
|
||||||
}
|
}
|
||||||
else digitalWrite(TRIAC_PIN, LOW);
|
else
|
||||||
|
digitalWrite(TRIAC_PIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void connectToWifi() {
|
void connectToWifi() {
|
||||||
@@ -155,22 +171,25 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
temp_sp = atof(val);
|
temp_sp = atof(val);
|
||||||
EEPROM.put(0, temp_sp);
|
EEPROM.put(0, temp_sp);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
out_value(1, temp_sp);
|
regulator.setpoint = temp_sp;
|
||||||
}
|
}
|
||||||
if(strcmp(topic, TOPIC"kp") == 0){
|
if(strcmp(topic, TOPIC"kp") == 0){
|
||||||
kp = atof(val);
|
kp = atof(val);
|
||||||
EEPROM.put(2, kp);
|
EEPROM.put(4, kp);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
regulator.Kp = kp;
|
||||||
}
|
}
|
||||||
if(strcmp(topic, TOPIC"ki") == 0){
|
if(strcmp(topic, TOPIC"ki") == 0){
|
||||||
ki = atof(val);
|
ki = atof(val);
|
||||||
EEPROM.put(4, ki);
|
EEPROM.put(8, ki);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
regulator.Ki = ki;
|
||||||
}
|
}
|
||||||
if(strcmp(topic, TOPIC"kd") == 0){
|
if(strcmp(topic, TOPIC"kd") == 0){
|
||||||
kd = atof(val);
|
kd = atof(val);
|
||||||
EEPROM.put(6, kd);
|
EEPROM.put(12, kd);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
regulator.Kd = kd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,20 +236,48 @@ boolean reconnect() {
|
|||||||
//digitalWrite(LED_MQ, HIGH);
|
//digitalWrite(LED_MQ, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out_value(byte digit, float val){
|
void PlusButPress(){
|
||||||
// if(!isnan(val)){
|
temp_sp += 0.1f;
|
||||||
// int value = (val * 100.0) + 0.5;
|
EEPROM.put(0, temp_sp);
|
||||||
// char ch = '0' + ((value / 100) % 10);
|
EEPROM.commit();
|
||||||
// lc.setChar(0, 2 + digit * 4, ch, false);
|
display();
|
||||||
// ch = '0' + ((value / 10) % 10);
|
regulator.setpoint = temp_sp;
|
||||||
// lc.setChar(0 , 1 + digit * 4, ch, true);
|
}
|
||||||
// ch = '0' + (value % 10);
|
|
||||||
// lc.setChar(0 , 0 + digit * 4, ch, false);
|
void PlusButLongPress(){
|
||||||
// }
|
temp_sp += 1.0f;
|
||||||
// else{
|
EEPROM.put(0, temp_sp);
|
||||||
// lc.setChar(0, 2 + digit * 4, 'E', false);
|
EEPROM.commit();
|
||||||
// lc.setRow(0, 1 + digit * 4, 0);
|
regulator.setpoint = temp_sp;
|
||||||
// lc.setRow(0, 0 + digit * 4, 0);
|
}
|
||||||
|
|
||||||
// }
|
void MinusButPress(){
|
||||||
|
temp_sp -= 0.1f;
|
||||||
|
EEPROM.put(0, temp_sp);
|
||||||
|
EEPROM.commit();
|
||||||
|
display();
|
||||||
|
regulator.setpoint = temp_sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinusButLongPress(){
|
||||||
|
temp_sp -= 1.0f;
|
||||||
|
EEPROM.put(0, temp_sp);
|
||||||
|
EEPROM.commit();
|
||||||
|
regulator.setpoint = temp_sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
disp.setCursor(1);
|
||||||
|
disp.printf("%4.1f%5.1f", temp_sp, temp1);
|
||||||
|
disp.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSP(){
|
||||||
|
regulator.setpoint = temp_sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pubData(const char* topic, float val){
|
||||||
|
char vout[7];
|
||||||
|
sprintf(vout, "%.1f", val);
|
||||||
|
client.publish(topic, vout);
|
||||||
}
|
}
|
||||||
3
KuhLight_ESP/.vscode/extensions.json
vendored
3
KuhLight_ESP/.vscode/extensions.json
vendored
@@ -3,5 +3,8 @@
|
|||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"platformio.platformio-ide"
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
;
|
;
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
[platformio]
|
||||||
|
default_envs = wemos-d1
|
||||||
|
|
||||||
[env:esp07]
|
[env:esp07]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
@@ -16,3 +18,14 @@ board_build.f_cpu = 26000000L
|
|||||||
board_build.ldscript = eagle.flash.1m.ld
|
board_build.ldscript = eagle.flash.1m.ld
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.1.135
|
upload_port = 192.168.1.135
|
||||||
|
[env:wemos-d1]
|
||||||
|
framework = arduino
|
||||||
|
platform = espressif8266
|
||||||
|
board = d1_mini
|
||||||
|
upload_protocol = espota
|
||||||
|
upload_port = 192.168.1.135
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
|
# RECOMMENDED
|
||||||
|
# Accept new functionality in a backwards compatible manner and patches
|
||||||
|
heman/AsyncMqttClient-esphome @ ^2.1.0
|
||||||
@@ -110,13 +110,14 @@ void loop() {
|
|||||||
nSec++;
|
nSec++;
|
||||||
//led_wrk = !led_wrk;
|
//led_wrk = !led_wrk;
|
||||||
//digitalWrite(LED_WRK, led_wrk);
|
//digitalWrite(LED_WRK, led_wrk);
|
||||||
if(nSec > 59){
|
if(nSec > 29){
|
||||||
if(mqttClient.connected()){
|
if(mqttClient.connected()){
|
||||||
char v[11];
|
char v[11];
|
||||||
ultoa(millis(), v, 10);
|
dtostrf(millis() / 60000.0, 7, 1, v);
|
||||||
|
//ultoa(millis(), v, 10);
|
||||||
digitalWrite(LED_WRK, LOW);
|
digitalWrite(LED_WRK, LOW);
|
||||||
led_ms = millis();
|
led_ms = millis();
|
||||||
mqttClient.publish(TOPIC"kuh/ltblmillis", 0, false, v);
|
mqttClient.publish(TOPIC"kuh/ltblminuts", 0, false, v);
|
||||||
}
|
}
|
||||||
nSec = 0;
|
nSec = 0;
|
||||||
}
|
}
|
||||||
@@ -141,6 +142,7 @@ void connectToWifi() {
|
|||||||
|
|
||||||
void connectToMqtt() {
|
void connectToMqtt() {
|
||||||
mqttClient.connect();
|
mqttClient.connect();
|
||||||
|
mqttClient.setWill(TOPIC"kuh/lighttblOnline", 1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
|
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user