BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

digitalWrite problem after Blynk resume

Hi! After pressing pause in blynk app to make changes and than pressing play, I cannot get valve1 in the following code to change states:

BLYNK_WRITE(V11)
{
  manuel1 = param.asInt();
  if (mode == 2 || mode == 3)
  //Blynk.virtualWrite(V100, manuel1);
  {
    if (manuel1 == 1)
    {
      digitalWrite(valve1, LOW);
      led1.on();
      led1.setColor(GREEN);
      Blynk.virtualWrite(V100, manuel1);
    }
    else
    {
      digitalWrite(valve1, HIGH);
      led1.on();
      led1.setColor(RED);
      Blynk.virtualWrite(V100, manuel1);
    }
  }
  if (mode == 1)
  {
      Blynk.virtualWrite(V11, 0);
      Blynk.notify("Select Manual or Auto Mode");
  }
}

The only way I’ve been able to get valve1 to start working again is the reset this particle argon. Which is ok while its sitting here on my desk, but I plan to go install this in an underground pit.
When valve1 quits I can still get led1 to change from red to green and I get 1 and 0 on V100.

@lsfarm please edit the post where you posted your sketch and use triple backticks at the beginning and end of your code rather than the characters that you have used.
Triple backticks look like this:
```

Pete.

Ahha. Thanks! First time I’ve post here.

Complete code:

#include <blynk.h>
char auth[] = "****"; 
BlynkTimer timer;
char currentTime[9];
bool clockSync = false;
WidgetTerminal terminal(V30);

// Zone valves
#define valve1 7
#define valve2 3
#define valve3 4
#define valve4 5
#define valve5 6
#define valve6 7
#define valve7 8
int mode = 999;
int manuel1 = 0;
int lastmanuel1 = 3;
int auto1 = 0;
int lastauto1 = 3;
//int counts = 0;

#define GREEN     "#008000"//#23C48E"
#define BLUE      "#04C0F8"
#define YELLOW    "#ED9D00"
#define RED       "#FF033E" // "#D3435C"
#define DARK_BLUE "#5F7CD8"

WidgetLED led1(V1);

BLYNK_WRITE(V0) {
  switch (param.asInt())
  {
    case 1: // OFF
      //Serial.println("Item 1 selected");
      mode = 1;
      Blynk.virtualWrite(V25, mode);
      shutoffall();
      //led1.setColor(BLYNK_RED);
      break;
    case 2: // Manual Mode
      Serial.println("Item 2 selected");
      mode = 2;
      Blynk.virtualWrite(V25, mode);
      //led1.setColor(BLYNK_GREEN);
      break;
    case 3: // Automatic Mode
      Serial.println("Item 3 selected");
      mode = 3;
      Blynk.virtualWrite(V25, mode);
      break;
    default:
      Serial.println("Unknown item selected");
  }
}

BLYNK_WRITE(V11)
{
  manuel1 = param.asInt();
  if (mode == 2 || mode == 3)
  //Blynk.virtualWrite(V100, manuel1);
  {
    if (manuel1 == 1)
    {
      digitalWrite(valve1, LOW);
      led1.on();
      led1.setColor(GREEN);
      Blynk.virtualWrite(V100, manuel1);
    }
    else
    {
      digitalWrite(valve1, HIGH);
      led1.on();
      led1.setColor(RED);
      Blynk.virtualWrite(V100, manuel1);
    }
  }
  if (mode == 1)
  {
      Blynk.virtualWrite(V11, 0);
      Blynk.notify("Select Manual or Auto Mode");
  }
}

BLYNK_WRITE(V21) {   // Scheduler #1 Time Input widget  
  TimeInputParam t(param);
  //unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
  unsigned int nowseconds = Time.local() % 86400;
  nowseconds = nowseconds - 9000;
  Blynk.virtualWrite(V25, nowseconds);
  unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);  
  unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
  Blynk.virtualWrite(V26, startseconds);
  int dayadjustment = -1;  
  if(Time.weekday() == 1){
    dayadjustment = 6; // needed for Sunday Time library is day 1 and Blynk is day 7
  }
  if(t.isWeekdaySelected((Time.weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday  
    //Schedule is ACTIVE today 
    if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){    // 62s on 60s timer ensures 1 trigger command is sent
      led1.setColor(BLUE);
      digitalWrite(valve1, LOW);
      Blynk.virtualWrite(V9, 255);  // turn on virtual LED
      Blynk.notify("Schedule 1 started");
    }                  
    if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
      led1.setColor(YELLOW);
      digitalWrite(valve1, HIGH);
      Blynk.virtualWrite(V9, 0);   // turn OFF virtual LED
      Blynk.notify("Schedule 1 finished");
    }               
  }
}

/*BLYNK_WRITE(V21) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);
  int SThour = t.getStartHour();
  int STmin = t.getStartMinute();
  int STsec = t.getStartSecond();
  int SPhour = t.getStopHour();
  int SPmin = t.getStopMinute();
  int SPsec = t.getStopSecond();
  int now = millis();
  Blynk.virtualWrite(V25, now);
  terminal.println(SThour);
}*/


void setup() 
{
    Blynk.begin(auth);
    Time.zone(-2.5);   //-2.5
    timer.setInterval(60000L, activetoday);  // check every 60s if ON / OFF trigger time has been reached
    timer.setInterval(1000L, clockDisplay);  // check every second if time has been obtained from the server
    timer.setInterval(5000L, sendinfo);
    pinMode(valve1, OUTPUT);
    pinMode(valve2, OUTPUT);
    pinMode(valve3, OUTPUT);
    pinMode(valve4, OUTPUT);
    pinMode(valve5, OUTPUT);
    pinMode(valve6, OUTPUT);
    pinMode(valve7, OUTPUT);
    //pinMode(valve8, OUTPUT);
    digitalWrite(valve1, HIGH);
    digitalWrite(valve2, HIGH);
    digitalWrite(valve3, HIGH);
    digitalWrite(valve4, HIGH);
    digitalWrite(valve5, HIGH);
    digitalWrite(valve6, HIGH);
    digitalWrite(valve7, HIGH);
    //digitalWrite(valve8, HIGH);

}

void loop()
{
  Blynk.run();
  timer.run();
  
}

void sendinfo()
{
    Blynk.virtualWrite(V100, Time.format(Time.local(), "%r - %a %D"));
    //int pin3 = digitalRead(valve1);
    //Blynk.virtualWrite(V101, pin3);
}

void shutoffall()
{
    //shut it all down
}


void activetoday(){         // check if schedule #1 should run today
  if(Time.year() != 1970){
    Blynk.syncVirtual(V21);  // sync scheduler #1  
  }
}

void clockDisplay(){  // only needs to be done once after time sync
  if((Time.year() != 1970) && (clockSync == false)){ 
    sprintf(currentTime, "%02d:%02d:%02d", Time.hour(), Time.minute(), Time.second());
    Serial.println(currentTime);
    clockSync = true;
  } 
}

What hardware (which type of board) are you using?

Pete.

Particle’s Argon board

Could this have something to do with it?

Pete.

I’ve been working with valve1 in my code and it had quit working after a resume, so i threw valve1 onto pin 7 as it has an LED on the board so I could do some troubleshooting.
I’ve got this now:

// Zone valves
#define valve1 7
#define valve2 3
#define valve3 4
#define valve4 5
#define valve5 6
#define valve6 1
#define valve7 8

And digitalWrite to valve1 after resuming blynk still fails to do anything…
Reboot board and works just fine… Until I pause and resume blynk app

Adding some serial print statements to give you the value of mode and manuel1 early in your BLYNK_WRITE(V11) callback function might be useful, although you don’t have a Serial.begin statement anywhere that I can see.

Pete.

Ok! I may have to try that yet. Whats got me confused is why led1 changes color correctly and V100 returns expected results, but no state change on valve1 after resume.
Thanks for the ideas @PeteKnight!!

To be honest, I’m not familiar with this hardware and the whole Particle Cloud thing, so have no idea what is happening either.
Maybe try replacing your relays with a physical LED to see if there is some issue there?

Pete.

Cracked it!
If anyone ever digs this thread back up here’s the fix:
My device particle argon. Use ESP32 Dev board (WiFi) under device settings in Blynk app.

I had particle photon selected as I thought that would be the closest match to my argon.
With particles dead simple over the air updates, hopefully argon shows up on Blynk supported devices.