I am building a new project with Blynk and external NTP Server.
Basically the problem is very simple to explain.
The sketch first call the Blynk.beguin and after NTP Server NTP.begin (libray NtpClientLib) is started for syncronization.
The problem NTP never get syncronized.
If I used the opposite sequence first call NTP server NTP.begin and then call the Blynk.beguin, the sketch freezes during the Blynk.beguin
When I use separated sketch, like only Blynk, it works ok.
And only NTP sync, it also work ok.
Also I noticed that by using WiFi.begin(ssid, pwd) and WiFi.status with Blynk, the status never get connected, however WiFi.localIP() can bring the IP address.
The question here by using Blynk and external NTP server NtpClientLib, is there any compatibility problem ?
I had no problem with NTPClient and Blynk lib version 0.4.0 (the previous one). Not tested with current, but there should be no problem too as NTP is started and time is acquired before blynk even starts. If you will not make it, tomorrow can share my experience. (Or possibly someone else will make it)
Good night (at least in EE )
I didn’t try to wait for NTP time response, before calling Blynk. (It should be a trial tomorrow).
They are just in sequence for execution.
And in this case Blynk.beguin freezes on that line.
@marvin7, it was difficult for me to adapt your code with some compilation problem. Also, at beguining I want avoid usage of RTC widget, then I tried once again with external NTP.
I have adapted part of your code, how you handled the Blynk and NTP.
So, finally I got it.
Basically, I will explain some parts of the code.
The main changes was the Blynk.beguin. I am not using it in this way anymore.
The new lines (taken from your code) :
Blynk.config(auth); Blynk.disconnect();
After that : delay(30000); ( not sure if this is relevant )
Then the Blynk connection starts here.
if (!Blynk.connected()) {
Blynk.connect();
while (!Blynk.connected()) {
Serial.print(".");
delay(2000);
}
if (Blynk.connected()) {
Serial.print("Blynk connected");
}
else {
Serial.print("Could not connect to Blynk");
Blynk.disconnect();
}
}
After that, Blynk got connected and the NTP got syncronization.
As a rule, such a long delays should be avoided, after all you have to wait for 30 seconds! Better check some condition and use timeout (you can see an example in my code too):
uint32_t startTime = millis();
while (millis() - startTime < 30000UL && !Blynk.connected()) {
someCode or empty loop;
}
where loop is repeated as long as Blynk is NOT connected (hence the ‘!’) OR passed time is greater than 30 thosands miliseconds (30s)
but I’m sure You will slowly get into this (as I did )
Yes. That was my first attempt.
Unfortunatelly, for unknown reasons it fails.
I am using ESP8266 NodeMCU.
When I use that code While with such time parameters, I get Flash Read Error in serial terminal.
And some hexa dump printouts.
Never mind.
This is only executed during the startup.