config backup wip

This commit is contained in:
Your Name 2021-05-26 22:25:12 +02:00
parent 98799bd2d5
commit 3d45a3fca3
2 changed files with 49 additions and 4 deletions

View File

@ -18,7 +18,10 @@
"string": "cpp", "string": "cpp",
"typeinfo": "cpp", "typeinfo": "cpp",
"cmath": "cpp", "cmath": "cpp",
"iterator": "cpp" "iterator": "cpp",
"array": "cpp",
"tuple": "cpp",
"utility": "cpp"
} }
} }
} }

View File

@ -281,12 +281,49 @@ void readPowerSwitchedSensors()
digitalWrite(OUTPUT_ENABLE_SENSOR, LOW); digitalWrite(OUTPUT_ENABLE_SENSOR, LOW);
} }
void copyFile(const char *source, const char *target)
{
byte buffer[512];
File file = SPIFFS.open(source, FILE_READ);
File file2 = SPIFFS.open(target, FILE_WRITE);
if (!file)
{
Serial << "There was an error opening " << source << " for reading" << endl;
return;
}
if (!file2)
{
Serial << "There was an error opening " << target << " for reading" << endl;
return;
}
while (file.available())
{
int read = file.read(buffer, 512);
if (read < 0)
{
Serial << "copy file is fucked" << endl;
}
else
{
file.write(buffer, read);
}
}
file2.flush();
Serial << "copy finished " << source << " -> " << target << endl;
file.close();
file2.close();
}
void onMessage(char *incoming, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) void onMessage(char *incoming, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
{ {
getTopic if (strcmp(incoming, topic) == 0) getTopic if (strcmp(incoming, topic) == 0)
{ {
mAliveWasRead = true; mAliveWasRead = true;
} }
if (strstr(incoming, "$implementation/config/set") > 0)
{
copyFile("/homie/config.json", "/homie/config.old");
}
}; };
void onHomieEvent(const HomieEvent &event) void onHomieEvent(const HomieEvent &event)
@ -610,17 +647,22 @@ void loop()
} }
else else
{ {
nextBlink = millis() + 5000;
if (lastPumpRunning >= 0 && lastPumpRunning < MAX_PLANTS) if (lastPumpRunning >= 0 && lastPumpRunning < MAX_PLANTS)
{ {
mPlants[lastPumpRunning].deactivatePump(); mPlants[lastPumpRunning].deactivatePump();
} }
if (lastPumpRunning > MAX_PLANTS) if (lastPumpRunning >= MAX_PLANTS)
{ {
digitalWrite(OUTPUT_ENABLE_PUMP, LOW); digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
nextBlink = millis() + 500;
} }
if (lastPumpRunning < MAX_PLANTS){ else
{
lastPumpRunning++; lastPumpRunning++;
nextBlink = millis() + 5000;
}
if (lastPumpRunning < MAX_PLANTS)
{
mPlants[lastPumpRunning].activatePump(); mPlants[lastPumpRunning].activatePump();
} }
} }