programuji ESP8266 D1 mini pro ovládání fotovoltaiky. Potřebuji, aby při dovršení daného napětí baterie (52.6) se barák přepl na FV. Pro přepínání mezi sítí a FV používám stykače 4NO a 4NC. Pokud baterie dosáhne 52.6V , tak stykač sepne inverter, protože trvá cca 7s než se na výstupu objeví napětí, delay 7s (čeká se na inverter), potom odepne stykač distribuční síť, delay 40ms a sepne stykač FV pro připojení FV do baraku. Toto se odehrává v sekci "void batteryvoltagerele()". Problém ale nastává s delay ve formě millis(). Při dovršení napětí 52.6V se čeká 8s a potom se sepne inverter s prvním stykačem a vzápětí druhý stykač. Potřebuji, aby po dosažení napětí sepl stykač inverteru, delay 8s, odepl stykač sítě, 40ms delay a jako poslední sepl stykač FV. Můžete mi prosím poradit, kde ve funkci millis dělám chybu?
Díky všem za rady!
Kód: Vybrat vše
#include <ESP8266WiFi.h>
float analog_voltage;   
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxx";
const char *ssid     = "xxxx";
const char *password = "xxxx";
BlynkTimer timer;
long last_sensor_reading = 0;
long bojlerpower = 0;
const int numReadings = 30;
float readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
float total = 0;                  // the running total
float average = 0;                // the average
unsigned long lastExecutedMillis = 0;
void setup() {
 Serial.begin(115200);
 for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
   Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
      }
  pinMode(13,OUTPUT); //13 D7 (distribution line contactor)
  pinMode(14,OUTPUT); //14 je D5 (PV contactor)
  pinMode(12,OUTPUT); //12 je D6 (inverter)
  pinMode(16,OUTPUT); //16 je D0 (water heater)
  Blynk.begin(auth, ssid, password);
}
void batteryvoltagerele(){
  total = total - readings[readIndex];
  readings[readIndex] = analogRead(A0)* 3.3 / 1023*18.86;
  total = total + readings[readIndex];
  readIndex = readIndex + 1;
  if (readIndex >= numReadings) {
    readIndex = 0;
  }
  average = total / numReadings; // battery voltage measurement with sampling of 30
  if (average>52.6) {
  digitalWrite(12,LOW); // inverter turns on if battery voltage reaches certain point
  unsigned long currentMillis = millis();
  if (currentMillis-lastExecutedMillis>=8000){  //8s delay and then switch two contactors
    lastExecutedMillis = currentMillis;
  digitalWrite(13,LOW); // disconnect distribution line
  delay(40);
  digitalWrite(14,LOW); //connect PV system
 }}
  else if (average<51.5){ // if voltage does not need meet requirements then contactors switch from PV to Distribution line
  digitalWrite(14,HIGH);
  delay(40);
  digitalWrite(13 ,HIGH);
  digitalWrite(12 ,HIGH);
  }
  Blynk.virtualWrite(V5, average);
  Blynk.run();
}
void bojlerssr(){ //if battery is full and house does not need much power then electic water heater is turned on.
if (average>52.8) {
digitalWrite(16,HIGH);}
//if(millis() - bojlerpower >= 120000) {
else if (analog_voltage<52.5) {
digitalWrite(16,LOW);
//bojlerpower = millis();
//digitalWrite(15,LOW);
//if(millis() - bojlerpower >= 120000) {
//digitalWrite(15,HIGH);
//bojlerpower = millis(); }
}}
 
void loop() {
  batteryvoltagerele();
  bojlerssr();
   }
   
