I know there are many posts about this. I think I have read most (all?) of them. However still confused.
I use unixtime to time the Blynk connection (in the Setup function).
//Blynk////////////////////////////// using config
blynkstart=rtc.getUnixTime(rtc.getTime());
Serial.println(rtc.getUnixTime(rtc.getTime()) );// I use Unix time to time the Blynk connection
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
if (digitalRead(A9) == HIGH) {//switch to chose whether or not to try connecting
Blynk.begin(auth, "blynk-cloud.com", 8442);
// Blynk.config(auth, "blynk-cloud.com", 8442);
// Blynk.connect();
Serial.println("Blynk End");Serial.println(rtc.getUnixTime(rtc.getTime()) );Serial.println(rtc.getUnixTime(rtc.getTime())-blynkstart);
}
It generally connects between the 14 and 35 seconds.
However if I use Blynk.connect() instead of Blynk.config() it will never connect:
//Blynk////////////////////////////// using connect
blynkstart=rtc.getUnixTime(rtc.getTime());
Serial.println(rtc.getUnixTime(rtc.getTime()) );// I use Unix time to time the Blynk connection
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
if (digitalRead(A9) == HIGH) {//switch to chose whether or not to try connecting
// Blynk.begin(auth, "blynk-cloud.com", 8442);
Blynk.config(auth, "blynk-cloud.com", 8442);
Blynk.connect();
Serial.println("Blynk End");Serial.println(rtc.getUnixTime(rtc.getTime()) );Serial.println(rtc.getUnixTime(rtc.getTime())-blynkstart);
}
I understand defaut timeout for connect is 30 sec but I have tried several value for Blynk.connect(t). t up to1800000. Always with the same result just more failed attempts to connect.
(Indeed with t at 180000 it times out after 180 sec)
So I don’t see any reason it can’t work, except the port you are using. For “blynk-cloud.com” it is port 80 now.
Can’t you just leave defaults by using Blynk.config(auth)?
EDIT:
OK, not the only one:
if (!Ethernet.begin(SelectMacAddress(auth, mac))) {
BLYNK_FATAL(BLYNK_F("DHCP Failed!"));
}
The Ethernet.begin(..) but it seems it requires correct arguments. I suppose this entry just initialises network connection, and you may look at some non Blynk related connection example for your connection method. Currently I’m away and can’t look at any code.
You are comparing two disimular commands. There is no “one or other”, they do different things.
Blynk.config() is just that, it sets up your required configuration like AUTH, Server, Port…etc. It is only used once in your setup()
Blynk.connect() does just what it says and trys to take your configured sketch and connect it… this command can be ran whenever needed in your sketch… for example as part of a “keep running when no internet available, but reconnect when able” routine.
@Gunner, look at his code. There is nothing wrong with command’s understanding (I think). It’s just the network connection initialization, that is missing here
This Is understand. I indeed want to use Blynk.connect for a ‘reconnection’ routine.
I think the problem is with the network init which I did not realize was necessary with Blynk.config and Blynk.connect. (from there my comment about a more detailed doc but it might be obvious for better programmers than me )
I’m just guessing, but I stand for “less than optimal way” the connection is handled by Blynk.begin(). Do You remember the not that old @Nixon 's issue? I’m left with his modifications and I’m quite happy with that