Поменял конфиг айтемов. Попробуем сделать защиту от сброса таргета в 0

This commit is contained in:
ftc
2024-10-20 10:55:57 +03:00
parent 437ea74c17
commit 00797e913a
2 changed files with 35 additions and 19 deletions
+34 -18
View File
@@ -4,6 +4,7 @@
#include "config.h"
#include "LittleFS.h"
//////////////////////////
// network
IPAddress my_ip(MY_IP);
@@ -11,32 +12,33 @@ IPAddress gateway(MY_GW);
IPAddress subnet(MY_NET);
IPAddress sensor_ip(SENSOR_IP);
// After how much time without connection we will
// reboot (in millis)
#define NON_CONNECTED_REBOOT_TIMEOUT 60000
//////////////////////////
// Base config
// dht sensor
#define DHTPIN D6
#define DHTTYPE AM2301
DHT dht(DHTPIN, DHTTYPE);
#define DHT_UPDATE_INTERVAL 500
// relay
#define RELAY_PIN D1
#define T_UPDATE_INTERVAL 500
// external t
#define EXTERNAL_UPDATE_INTERVAL 1000
//////////////////////////
// logic consts
// After how much time without connection we will
// reboot (in millis)
#define NON_CONNECTED_REBOOT_TIMEOUT 60000
// deviation from target t allowed (in degrees multiplied by 100)
#define T_HYSTERESIS 150
// relay cooldown temperature (after what t we allow to turn on relay again) (in degrees multiplied by 100)
#define RELAY_COOLDOWN_T 500
// timeout to switch from external to internal temperature data (in milliseconds)
#define SWITCH_TO_INTERNAL_TIMEOUT 50000
// interval for updating internal temperature
#define T_UPDATE_INTERVAL 500
// interval for updating external t
#define EXTERNAL_UPDATE_INTERVAL 1000
//////////////////////////
// modbus consts and works
#define TCP_PORT 15000
@@ -52,7 +54,7 @@ DHT dht(DHTPIN, DHTTYPE);
#define REGISTER_TARGET_T 5
// temperature from internal sensor
#define REGISTER_INTERNAL_T 6
// temperatur from external sensor (received via modbus-tcp)
// temperature from external sensor (received via modbus-tcp)
#define REGISTER_EXTERNAL_T 7
// critical relay temp (degrees multiplied by 100)
@@ -72,21 +74,35 @@ int target_t = 0;
int internal_t = 0;
int external_t = 0;
void LoadState()
bool TryLoad(char *filename)
{
File f = LittleFS.open("/target_t.txt", "r");
if (!f) return;
File f = LittleFS.open(filename, "r");
if (!f) return false;
String s = f.readStringUntil('\n');
target_t = atoi(s.c_str());
f.close();
if (target_t == 0) return false;
return true;
}
void LoadState()
{
if (TryLoad("/target_t.txt")) return;
TryLoad("/target_t.txt.bak");
}
void SaveTo(char *filename)
{
File f = LittleFS.open(filename, "w");
if (!f) return;
f.println(target_t);
f.close();
}
void SaveState()
{
File f = LittleFS.open("/target_t.txt", "w");
if (!f) return;
f.println(target_t);
f.close();
SaveTo("/target_t.txt");
SaveTo("/target_t.txt.bak");
}
void setup()