Problem with WidgetRTC library in Project

Hi Blynkers,
I´m trying to control a relay with a time input so i can control my heating by going on and off at a time i give with blynk.
i created a code with the base of the advanced time input example with a little transformation but i get the same error all the time…
my windows is win 10
my blynk version is latest 0.5.4 just installed because i wanted a fresh version
arduino version is 1.8.7 also just new installed because i thought old version may is the fault

first of all the code:

#include <SPI.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <WidgetTimeInput.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "*****************************";
char ssid[] = "*****************";
char pass[] = "**********";
String currentDate;
String currentTime;
String startTime;
String stopTime;
SimpleTimer timer;
WidgetRTC rtc;

BLYNK_WRITE(V100) {
  TimeInputParam t(param);

  // Process start time

  if (t.hasStartTime())
  {
    startTime = String(t.getStartHour())  + ":" + t.getStartMinute()  + ":" + t.getStartSecond();
    Serial.println("Start: " + startTime);

  }
  else if (t.isStartSunrise())
  {
    Serial.println("Start at sunrise");
  }
  else if (t.isStartSunset())
  {
    Serial.println("Start at sunset");
  }
  else
  {
    // Do nothing
  }

  // Process stop time

  if (t.hasStopTime())
  {
    stopTime = String(t.getStopHour()) + ":" + t.getStopMinute() + ":" + t.getStopSecond();

    Serial.println("Start: " + stopTime);
  }
  else if (t.isStopSunrise())
  {
    Serial.println("Stop at sunrise");
  }
  else if (t.isStopSunset())
  {
    Serial.println("Stop at sunset");
  }
  else
  {
    // Do nothing: no stop time was set
  }

  // Process timezone
  // Timezone is already added to start/stop time

  Serial.println(String("Time zone: ") + t.getTZ());

  // Get timezone offset (in seconds)
  Serial.println(String("Time zone offset: ") + t.getTZ_Offset());

  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)

  for (int i = 1; i <= 7; i++) {
    if (t.isWeekdaySelected(i)) {
      Serial.println(String("Day ") + i + " is selected");
    }
  }


  Serial.println();
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  rtc.begin();

}

void loop()
{
  Blynk.run();
  timer.run();
 
  //TEMPO
  currentTime = String(hour()) + ":" + minute() + ":" + second();
  currentDate = String(day()) + " " + month() + " " + year();

  // Send time to the App
  Blynk.virtualWrite(V101, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V102, currentDate);

  //TEMPO

  
  delay(1000);
if (currentTime == startTime){
    const byte RelayON[] = {0xA0, 0x01, 0x01, 0xA2};
    Serial.write(RelayON, sizeof(RelayON));
}
else if (currentTime == stopTime){
    const byte RelayOFF[] = {0xA0, 0x01, 0x00, 0xA1};
    Serial.write(RelayOFF, sizeof(RelayOFF));
}
} 

now the error

In file included from C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/WidgetRTC.h:18:0,

                 from C:\Users\Lukas\Documents\Arduino\AdvancedTimeInput\AdvancedTimeInput.ino:5:

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h: In member function 'void BlynkWidgetBase::setLabel(Args ...)':

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h:27:9: error: 'Blynk' was not declared in this scope

         Blynk.setProperty(mPin, "label", args...);

         ^

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h: In member function 'void BlynkWidgetBase::setColor(Args ...)':

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h:32:9: error: 'Blynk' was not declared in this scope

         Blynk.setProperty(mPin, "color", args...);

         ^

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h: In member function 'void BlynkWidgetBase::setMin(Args ...)':

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h:37:9: error: 'Blynk' was not declared in this scope

         Blynk.setProperty(mPin, "min", args...);

         ^

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h: In member function 'void BlynkWidgetBase::setMax(Args ...)':

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkWidgetBase.h:42:9: error: 'Blynk' was not declared in this scope

         Blynk.setProperty(mPin, "max", args...);

         ^

In file included from C:\Users\Lukas\Documents\Arduino\AdvancedTimeInput\AdvancedTimeInput.ino:5:0:

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/WidgetRTC.h: In static member function 'static time_t WidgetRTC::requestTimeSync()':

C:\Users\Lukas\Documents\Arduino\libraries\Blynk\src/WidgetRTC.h:37:5: error: 'Blynk' was not declared in this scope

     Blynk.sendInternal("rtc", "sync");

     ^

exit status 1

can anyone help me ? i am sitting here for maybe three evenings searching for the problem …

thanks

sincerely Lukas

PS: yes I used the search at first :smiley:

I don’t see any includes like:

...
#include <WidgetRTC.h>
#include <WidgetTimeInput.h>
...

in the example:

Also:

void setup()
{
...
  rtc.begin();
}

is not in the example.
This is why YOUR code does not compile.

I think those #includes and line of code came from the RTC example in Sketch Builder. The two sketches have been mashed together with some interesting additions in the void loop.

Can’t imagine why it’s not working!

Pete.

as I just wrote down, i did a little transformation in the code so it isn´t the original one.
and as

wrote, the code isnt the problem, anything went wrong with the libraries.

sincerely
Lukas

And that’s where your problems lie, rather than a bug in the libraries.

You’ll find that if you include the libraries in a different sequence (following the Sketch Builder examples rather than simply mashing them together) it will compile correctly…

#include <SPI.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WidgetRTC.h>
#include <WidgetTimeInput.h>

However, although your code will then compile correctly, it won’t work properly.

Your RTC widget in your app is linked to pin V1, not V100. An easy fix, but one that’s necessary.
Later in your code you are also trying to write data to pins V101 and V102, but you have no widgets attached to those pins. Once again that’s an easy fix.

More difficult to fix is what you’ve done with your void loop.
You’re breaking two of the golden rules of Blynk - doing virtual writes in void loop, and using delays in void loop.

You need to read this article:
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Also, you should use the built-in Blynk Timer rather than the original simpleTimer.

It’s also not a good idea to share your Auth code in a public forum. In this case it was handy for me to be able to see how you’d set up your widgets, but if I wanted to I could easily write a sketch to write my own data to your project,

Happy Blynking.

Pete.

1 Like

Hi Blynkers! Read this topic and remove BlynkTimers (Simpletimers work alone) from sketch and add #include <WidgetTimeInput.h> as Pete give the suggestions. AND complings finished without errors!

Thank you for posting this information. I never considered that my includes needed to be in a specific order but it makes sense and solved my problem.

1 Like