Connect and disconnect continuously

Hello!

Looks like I have a “task” what i cannot solve alone :slight_smile:

Hardware: Arduino Uno and ESP 8266 connected with hardware Serial.
I’m using local server!
Wemos d1 minis and another arduino esp8266 combo can connect to the server!
This spinkler controller getin crazy and now don’t want to connect!
I tried to put extra capacitor to 3.3 volt help to stabilized ESP… nothing…
I removed all timer function from code… nothing…
I using android, and the app just showing: “Spinkler connect… (2 sec) Spinkler disconnected”
I changed the arduino board also to new one… nothing :frowning:
I don’t know what’s wrong…

Debug window:

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Arduino Uno

[689] Connecting to Matrix
[3907] WIFI CONNECTED
AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
compile time:May 20 2016 15:08:19
OK
[9269]
[9278] Connected to WiFi
[19475] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD
[19677] >[00|00|01|00|C8]
[19705] Ready (ping: 57ms).
[19736] Free RAM: 465
[19781] <[11|00|02|00]fver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]256[00]dev
[24875] Cmd error
[35045] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD
[45308] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD
[55575] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD
[65838] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD
[76101] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD
[86362] <[1D|00|01|00] CfPzmcC0ivud-szaWy0OY7U2hox17NQD

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);



  for (int x = 3; x != 10; x++) {
    pinMode(x, OUTPUT);
    digitalWrite(x, LOW);
  }

  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  delay(10);

  while (!Serial) {} 

  Wire.begin();
  while (!bme.begin())
  {
    delay(1000);
  }

  settings.tempOSR = BME280::OSR_X4;

  bme.setSettings(settings);
  for (int x = 1; x <= 7; x++) {
    Sp[x] = EEPROM.read(x);
  }
  for (int x = 1; x <= 7; x++) {
    weekDays[x] = EEPROM.read(x + 7);
  }
  prog1Hour = EEPROM.read(15);
  prog1Minute = EEPROM.read(16);

  delay(10);
  Blynk.begin(auth, wifi, ssid, pass, "192.168.1.99", 8080);
  timer.setInterval(60000L, sendBME280);
  timer.setInterval(10000L, levelCheck);
  timer.setInterval(20000L, startSignal);
  timer.setInterval(1000L, spinklerCheck);
  //  timer.setInterval(8000L, flowRateCheck);



}

/////////////////////////////////////////////////////////////////////////////////////////////////////////LOOP
void loop()
{
  Blynk.run();
  timer.run();


}

Thank advance

Seeing the entire code would help.
Do you have a hardware RTC attached? If so, what type and to which pins?

What other hardware connections do you have?

Pete.

Hello Pete,

One BME280 and one DS3231 paralell on A4,A5 pins.
Analogread on A0,A1,A2 (water level check)
7 digital output to Pump and valves…
One hall sensor on D2 (Int0) for flowcheck.

My code could be “simple or ugly” and not so professional.
I’m not a “programmer” I learning from tutorials, and from google :slight_smile:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 12);
#define BLYNK_PRINT mySerial 
#define BLYNK_DEBUG 


#include <Wire.h>
#include <SPI.h>
#include <BME280I2C.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "RTClib.h"
#include <EEPROM.h>
RTC_DS3231 rtc;

unsigned long tempMillis;
byte sensorInterrupt = 0;  // 0 = digital pin 2
float calibrationFactor = 4.5;
byte sensorPin       = 2;
volatile byte pulseCount;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
int spHead[] = {0, 3, 4, 5, 6, 7, 8, 9};
int weekDays[] = {0, 0, 0, 0, 0, 0, 0, 0};
int Sp[] = {0, 0, 0, 0, 0, 0, 0, 0};
int spEn = 1;
int spStart = 0;
int spNum = 1;
int pumpEn = 0;
int pumpOverLock = 0;



char auth[] = "CfPzmcC0ivud-szaWy0OY7U2hox17NQD";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
#define ESP8266_BAUD 9600
ESP8266 wifi(&Serial);

WidgetLED led1(V3);
WidgetLED led2(V4);
WidgetLED led3(V5);
//WidgetLCD lcd(V31);
BlynkTimer timer;




int prog1Hour;
int prog1Minute;
BLYNK_WRITE(V15) {
  TimeInputParam t(param);
  prog1Hour = t.getStartHour();
  prog1Minute = t.getStartMinute();
  for (int i = 1; i <= 7; i++) {
    weekDays[i] = 0;
    if (t.isWeekdaySelected(i)) {
      weekDays[i] = 1;
    }
  }
}

BME280I2C::Settings settings(
  BME280::OSR_X1,
  BME280::OSR_X1,
  BME280::OSR_X1,
  BME280::Mode_Forced,
  BME280::StandbyTime_1000ms,
  BME280::Filter_Off,
  BME280::SpiEnable_False,
  0x76 // I2C address. I2C specific.
);

BME280I2C bme(settings);





////////////////////////////////////////////////////////////////////SETUP
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);



  for (int x = 3; x != 10; x++) {
    pinMode(x, OUTPUT);
    digitalWrite(x, LOW);
  }

  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  delay(10);

  while (!Serial) {} 

  Wire.begin();
  while (!bme.begin())
  {
    delay(1000);
  }

  // Change some settings before using.
  settings.tempOSR = BME280::OSR_X4;

  bme.setSettings(settings);
  for (int x = 1; x <= 7; x++) {
    Sp[x] = EEPROM.read(x);
  }
  for (int x = 1; x <= 7; x++) {
    weekDays[x] = EEPROM.read(x + 7);
  }
  prog1Hour = EEPROM.read(15);
  prog1Minute = EEPROM.read(16);

  delay(10);
  Blynk.begin(auth, wifi, ssid, pass, "192.168.1.99", 8080);
  //delay(200);
  timer.setInterval(60000L, sendBME280);
  timer.setInterval(10000L, levelCheck);
  timer.setInterval(20000L, startSignal);
  timer.setInterval(1000L, spinklerCheck);
  //  timer.setInterval(8000L, flowRateCheck);



}

/////////////////////////////////////////////////////////////////////////////////////////////////////////LOOP
void loop()
{
  Blynk.run();
  timer.run();


}
//////////////////////////////////////////////////////////////////////////////////////////////////Blynk
BLYNK_WRITE(V6) {
  int sp1 = param.asInt(); 
  if (sp1 == 1 ) {
    digitalWrite(3, HIGH);
  }
  else {
    digitalWrite(3, LOW);
  }
}

BLYNK_WRITE(V7) {
  int sp2 = param.asInt(); 
  if (sp2 == 1 ) {
    digitalWrite(4, HIGH);
  }
  else {
    digitalWrite(4, LOW);
  }
}

BLYNK_WRITE(V8) {
  int sp3 = param.asInt(); 
  if (sp3 == 1 ) {
    digitalWrite(5, HIGH);
  }
  else {
    digitalWrite(5, LOW);
  }
}

BLYNK_WRITE(V9) {
  int sp4 = param.asInt(); 
  if (sp4 == 1 ) {
    digitalWrite(6, HIGH);
  }
  else {
    digitalWrite(6, LOW);
  }
}

BLYNK_WRITE(V10) {
  int sp5 = param.asInt(); 
  if (sp5 == 1 ) {
    digitalWrite(7, HIGH);
  }
  else {
    digitalWrite(7, LOW);
  }
}

BLYNK_WRITE(V11) {
  int sp6 = param.asInt(); 
  if (sp6 == 1 ) {
    digitalWrite(8, HIGH);
  }
  else {
    digitalWrite(8, LOW);
  }
}

BLYNK_WRITE(V12) {
  int sp7 = param.asInt(); 
  if (sp7 == 1 ) {
    digitalWrite(9, HIGH);
  }
  else {
    digitalWrite(9, LOW);
  }
}

BLYNK_WRITE(V13) {
  int sziv = param.asInt(); 
  if (sziv == 1 ) {
    digitalWrite(10, LOW);
  }
  else {
    digitalWrite(10, HIGH);
  }
}

BLYNK_WRITE(V18) {
  int sziv = param.asInt(); 
  if (sziv == 1 ) {
    digitalWrite(10, LOW);
  }
  else {
    digitalWrite(10, HIGH);
  }
}

BLYNK_WRITE(V20) {
  Sp[1] = param.asInt() * 10; 
  EEPROM.write(1, Sp[1]);
}

BLYNK_WRITE(V21) {
  Sp[2] = param.asInt() * 10; 
  EEPROM.write(2, Sp[2]);
}

BLYNK_WRITE(V22) {
  Sp[3] = param.asInt() * 10; 
  EEPROM.write(3, Sp[3]);
}

BLYNK_WRITE(V23) {
  Sp[4] = param.asInt() * 10; 
  EEPROM.write(4, Sp[4]);
}

BLYNK_WRITE(V24) {
  Sp[5] = param.asInt() * 10; 
  EEPROM.write(5, Sp[5]);
}

BLYNK_WRITE(V25) {
  Sp[6] = param.asInt() * 10; 
  EEPROM.write(6, Sp[6]);
}

BLYNK_WRITE(V26) {
  Sp[7] = param.asInt() * 10; 
  EEPROM.write(7, Sp[7]);
}

BLYNK_WRITE(V27) {
  spEn = param.asInt(); 
}

BLYNK_WRITE(V28) {
  int eprom = param.asInt(); 

  for (int x = 7; x <= 14; x++) {
    EEPROM.write(x, weekDays[x]);
  }
  EEPROM.write(15, prog1Hour);
  EEPROM.write(16, prog1Minute);

}
BLYNK_WRITE(V30) {
  pumpOverLock = param.asInt(); 
}




////////////////////////////////////////////////////////////////////////////////////////////////////////VOID
void sendBME280() {
  // Serial.println (humidity);

  digitalWrite(3, LOW);
  float temp(NAN), hum(NAN), pres(NAN);

  bme.read(pres, temp, hum);
  pres /= 100;

  Blynk.virtualWrite(V0, temp );

  Blynk.virtualWrite(V1, hum);

  Blynk.virtualWrite(V2, pres);
}



void levelCheck() {

  if (pumpEn == 1 && pumpOverLock == 0) {
    flowRateCheck();
  }
  if (analogRead(0) > 600) {
    led1.on();
  }
  else {
    led1.off();
  }
  if (analogRead(1) > 600) {
    led2.on();
    pumpEn = 0;
    digitalWrite(10, HIGH);
  }
  else {
    led2.off();
    if (pumpOverLock == 0 ) {
      digitalWrite(10, LOW);
      pumpEn = 1;
    }

  }
  if (analogRead(2) > 600) {
    led3.on();
  }
  else {
    led3.off();
  }

}

/////////////////////////////////////////////////////////////////////////////////////////////flow control
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}


void flowRateCheck()    // Only process counters once per second
{


  detachInterrupt(sensorInterrupt);

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);


  Blynk.virtualWrite(V14 , int(pulseCount)); // Print the integer part of the variable
  if (pulseCount < 50 ) {
    pumpOverLock = 1;

    Blynk.virtualWrite(V30 , pumpOverLock);
    digitalWrite(10, HIGH);
    pumpEn = 0;
  }
  pulseCount = 0;
}

//////////////////////////////////////////////////////////////////////////////////////startsignal
void startSignal() {
  Blynk.virtualWrite(V27 , spEn);
  DateTime now = rtc.now();
 // delay(100);
  if (weekDays[now.dayOfTheWeek()] == 1 && spEn == 1 && spStart == 0) {
    if (prog1Hour == now.hour() && prog1Minute == now.minute()) {
      spStart = 1;
      spNum = 1;
      for (int x = 1; x <= 7; x++) {
        Sp[x] = EEPROM.read(x);
      }
      for (int x = 1; x <= 7; x++) {
        weekDays[x] = EEPROM.read(x + 7);
      }
      prog1Hour = EEPROM.read(15);
      prog1Minute = EEPROM.read(16);
    }
  }
}
/////////////////////////////////////////////////////////////////////////////////////////spinkler check
void spinklerCheck() {
  if (spStart == 1) {
    if (Sp[spNum] > 0) {
      digitalWrite( spHead[spNum], HIGH);
      Sp[spNum]--;
      switch (spNum) {
        case 1 : Blynk.virtualWrite(V6, 1 );
          break;
        case 2 : Blynk.virtualWrite(V7, 1 );
          break;
        case 3 : Blynk.virtualWrite(V8, 1 );
          break;
        case 4 : Blynk.virtualWrite(V9, 1 );
          break;
        case 5 : Blynk.virtualWrite(V10, 1 );
          break;
        case 6 : Blynk.virtualWrite(V11, 1 );
          break;
        case 7 : Blynk.virtualWrite(V12, 1 );
          break;
      }

    }
    if (Sp[spNum] == 0) {
      switch (spNum) {
        case 1 : Blynk.virtualWrite(V6, 0 );
          break;
        case 2 : Blynk.virtualWrite(V7, 0 );
          break;
        case 3 : Blynk.virtualWrite(V8, 0 );
          break;
        case 4 : Blynk.virtualWrite(V9, 0 );
          break;
        case 5 : Blynk.virtualWrite(V10, 0 );
          break;
        case 6 : Blynk.virtualWrite(V11, 0 );
          break;
        case 7 : Blynk.virtualWrite(V12, 0 );
          break;
      }

      digitalWrite( spHead[spNum], LOW);
      spNum++;
    }
    if (spNum == 8) {
      spStart = 0;
    }



  }
}

Peter