[SOLVED] RTC widget and Local Server

Dear Blynk Team,
I’ve used RTC widget with Blynk Server and all has worked fine. No problem at all.

This morning I’ve installed the RTC widget on a project that is based on a local server. The compilation is ok but when I run the program the internet connection starts and falls continously.
In the serial monitor I see the auth token and after it the command AT+CIPCLOSE. At this point the system send an AT+CIPSTART=“TCP”,“188.213.175.207”,8442 followed by the auth token and the loop begin again …

I use an iOS device, the last version of Blynk app and local server server-0.17.2.

I confirm that the same program (just with Blynk server instead of local server) works fine. Of course the local server works fine too, with other widgets, from a lot of time.

Can you, please, give me a help?
Thanks indeed,
Giancarlo

This is the code:

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

#include <SimpleTimer.h>

#include <TimeLib.h>
#include <WidgetRTC.h>

#define LIVE_TIMER 5000                    // Period = 5 sec

ESP8266 wifi(&Serial);

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V3);

char auth[] = "be8f04d5d86f40cf864b319012f7a89c";
char ssid[] = "xxx";
char pass[] = "xxx";

char Date[16];
char Time[16];

void setup()
{
  Serial.begin(9600);

  Blynk.begin(auth, wifi, ssid, pass);                     // Blynk Server => OK !
//  Blynk.begin(auth, wifi, ssid, pass, "188.213.175.207");  // Local Server => KO !!!!

  rtc.begin();

  timer.setInterval(LIVE_TIMER, Live);
}

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

void Live()
{
  // Live LED code
  
  Blynk.virtualWrite(V0, 255);             // Live LED On
  delay(500);
  Blynk.virtualWrite(V0, 0);               // Live LED Off

  // RTC code

  sprintf(Date, "%04d/%02d/%02d", year(), month(), day());
  sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());

  Blynk.virtualWrite(V1, Date);
  Blynk.virtualWrite(V2, Time);
}

i am on local server 0.17.0 and my RTC works fine.

this is my local server call though:

 Blynk.begin(authBlynk, SSID, pass, IPAddress(192, 168, 0, 7));

with commas?

@Dave Hi Dave, from the IP address I deduce that your local server is inside your home / office. My local server, instead, is located on a cloud (it is an Aruba cloud service). Could be this the difference? I’m in trouble … :sweat:

no idea mate, i just looked for differences, and you have dots and i have commas!

sorry i am such a n00b!!!

wait for @Lichtsignaal perhaps? he is server-king…

@Dmitriy Hi Dmitriy, could you, please, take in consideration my request ?
Thanks a lot,
Giancarlo

@Gianca Please try @Dave1829 suggestion.

@Gianca “188.213.175.207” is fine or IPAddress(188,213,175,207) as they are both different data types.

Your problem is that you are trying to use a Blynk Cloud token on an Aruba Cloud server.

@Costas Hi Costas, yes I confirm that “188.213.175.207” is fine because my programs are working well from many months on this Aruba Clous server. And, for this reason, I don’t think that it is a problem of token. The problem arose only yesterday when I decided to use the RTC widget. If I comment the instruction relevant to RTC data retrieving:

  sprintf(Date, "%04d/%02d/%02d", year(), month(), day());
  sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());

the program works again.

But if I put even a simple instruction as

int yy = year();

the program stops (I see AT+CIPCLOSE commands).

I’ve made a lot of test today and the strange thing is that if I simplify the program at the minimum terms it works well !! I realized this situation: the program writes a lot of data ONTO the server (data coming from sensors) and the ONLY data asked FROM the server are date and time. In other words I’ve experienced that writing a lot of data on the server and asking RTC data is a problem. Instead, if the amount of data written on the server is reduced, the program works (RTC date and time are visualized together with other data). Of course I have tried to put the code that writes data onto the server in a timer function different from the timer function of RTC but nothing to do !!!
I’m very frustrated … What can I do ??
Ciao,
Giancarlo

@Gianca use the RTC example provided that doesn’t include sprintf.

Edit: sprintf is ok and formats the time better than the example sketch because it fails to use the following function (it is in the sletch but is never called):

// Utility function for digital clock display: prints preceding colon and leading 0
void printDigits(int digits)
{
  Serial.print(":");
  if (digits < 10) {
    Serial.print('0');
  }
  Serial.print(digits);
}

If you don’t want to wait for the time to synchronise (up to 5 minutes) you should ensure you are connected to the server before calling rtc.begin() by proceeding it with:

while (Blynk.connect() == false) {
// Wait until connected
}

Alternatively if you don’t want to wait for the connection to the server you can play around with the setSyncInterval( interval) method (https://github.com/PaulStoffregen/Time).

@Gianca Hello. Not sure this is exactly your case. But maybe tuning this param will help you?

#define BLYNK_MSG_LIMIT 20

in BlynkConfig.h file of Blynk library?

Your OP of token presentation, reset, token presentation, reset is caused by incorrect tokens. If you check “be8…9c” is a valid Blynk cloud token.

You may have other problems too but the sketch you provided isn’t a strain on any server.

@Dmitriy @Costas SOLVED !!! It was a problem of memory limit of the ATmega328.
I got this understatement because, desperated, I loaded the program onto an Arduino Mega and everything worked fine !! So I came back to my ATmega328 and moved variables from global area to local area. Now all is working correctly :sweat_smile: :sweat_smile: :sweat_smile: !!

@Costas why do you think that the token is not valid ? I just use the token that Blynk gives me when I create a project. Of course I mark that I will be using a local server.

Thank you for your attention and your time. (By the way, which is the procedure to tag a post as [SOLVED] ) ?

Ciao,
Giancarlo

Nice! Glad it is working now.

Just edit text header.

Tokens are specific to each server, they are not interchangeable.
If you do http://blynk-cloud.com:8080/token/project it shows all your project details on the Blynk server. If you do the same but change blynk-cloud.com to your Aruba IP you will see it is an invalid token.