Hello, I have two Arduino Mega panels running Blynk on the same network. When one of them disconnects, it does not reconnect by itself. The other one works 100%. Both are different templates but on the same account. I have even changed the one that disconnects to communicate on port 8080, but nothing has changed. In both, I have routines outside of Blynk, so I use the following functions in the setup: “Blynk.config(); and Blynk.connect();”, and in my infinite loop I use the function that checks if Blynk is connected: if(Blynk_connected()), where if the connection drops, it waits 5 minutes and tries to reconnect with Blynk.connect() and then Blynk.run();. It works on one panel and not on the other. Does anyone have any tips?
More information required.
Pete.
Here is part of the code that connects, monitors and reconnects blynk:
/*
* configurações blynk
*/
char auth [] = BLYNK_AUTH_TOKEN;
char server [] = "ny3.blynk.cloud";
byte mac [ ] = { 0xDE , 0xAD , 0xBE , 0xEF , 0x0C , 0x1A } ;
unsigned long timer = 0;
boolean setflagblynk;
void configureBlynk(){
setDisplay(PAGE_INTERNET);
delay(10);
Ethernet.init(10);
Ethernet.begin(mac);
if(Ethernet.hardwareStatus() == EthernetNoHardware){
Serial.println("placa internet falha");
}
Serial.println("ip:");
Serial.println(Ethernet.localIP());
Blynk.config(auth, server, 8080);
Blynk.connect();
prepareTimer();
debug = false;
reload();
setDisplay(PAGE_RELOGIO);
}
void iniciarBlynk(){
if(Blynk.connected() == true){
Blynk.run();
reconnectBlynk(false);
}else{
reconnectBlynk(true);
}
runTimer();
}
void reconnectBlynk(boolean falha){
if(falha){
if(setflagblynk == false){
timer = millis() + 300000;
setflagblynk = true;
}
if(temporizador(timer)){
delay(50);
setDisplay(PAGE_INTERNET);
Ethernet.maintain();
Blynk.connect();
timer = 0;
setflagblynk = false;
delay(50);
reload();
setDisplay(PAGE_RELOGIO);
}
}else{
timer = 0;
setflagblynk = false;
}
}
/*
* funcção que atualiza o aplicativo
*/
void reload(){
Blynk.syncVirtual(V20, V21, V22, V17, V18, V19, V23, V24, V25, V27, V28, V29, V30, V31, V32, V33, V34, V35, V37, V38, V39);
Blynk.virtualWrite(V0, luzcama);
Blynk.virtualWrite(V1, luzpista);
Blynk.virtualWrite(V2, vent1);
Blynk.virtualWrite(V3, vent2);
Blynk.virtualWrite(V4, vent3);
Blynk.virtualWrite(V5, vent4);
Blynk.virtualWrite(V6, vent5);
Blynk.virtualWrite(V7, vent6);
Blynk.virtualWrite(V8, vent7);
Blynk.virtualWrite(V9, vent8);
Blynk.virtualWrite(V10, vent9);
Blynk.virtualWrite(V11, bomba2);
Blynk.virtualWrite(V12, bomba1);
}
Code snippets don’t help, especially when you don’t say if this is from the working or non-working board, and when you don’t show which libraries are being used, or show your void setup and void loop.
Your reload
function rings alarm bells with me.
I would have expected you to post details of your hardware and Blynk library version, along with both your working and non-working code, and serial output fro: both boards when one successfully re-connects and the other fails to reconnect.
Looking at the information you’ve provided so far, do you really expect that a community member will be able to give you advice on how to resolve your problem based just on this?
If you want us to help you then you need to start by helping us to help you.
Pete.
My code is divided into 16 tabs, totaling more than 5000 lines of code, it is difficult to publish everything, the version of the library I use is 1.3.2, my hardware is an Arduino Mega, connected via an internet cable with the W5100 shield, when I try to reconnect the following appears on the serial output:
conneting to ny3.blynk.cloud:8080
conneting to ny3.blynk.cloud:8080
conneting to ny3.blynk.cloud:8080
conneting to ny3.blynk.cloud:8080
On the panel that works, the serial appears:
conneting to ny3.blynk.cloud:80
ready: (ping: 132ms)
I also have defined on the panel that does not reconnect:
#define BLYNK_FIRMWARE_VERSION “1.0.0”
#define BLYNK_HEARTBEAT 60
Are you using a different MAC address for each device?
I’d suggest that you simplify the code and do more tests. Maybe swap the ethernet shields from one device to another.
Pete.
Yes, in what works well I use the mac: 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF
and in what does not reconnect I use: 0xDE, 0xAD, 0xBE, 0xEF, 0x0C, 0x1A
I’m going to change the shield, but I can’t switch from one to the other because one uses the w5500 chip and the other the w5100.
I have a question, if a disconnection is requested and then a reconnection would it work? With the commands Blynk.disconnect() and after Blynk.connect(), or do I need to call Blynk.config() again?
No.
Pete.
OK, I’ll test the disconnection and then the reconnection!
Another question: if the server blocks communication due to a flood of requests, how do you reconnect? I know that restarting the card will work, but what is the request made to the server, Blynk.config()?
I don’t know. I suspect that terminating the session, then creating a new one (maybe via a disconnect/connect) is what is needed.
However, the best solution is to avoid flooding the server in the first place.
BlynkTimer has built-in throttling tgat will avoid flooding, which is one Eason why it’s best to use it as opposed to doing millis comparisons in your code.
Pete.
This timer that I use is a boolean function that tells me if the time I pass as a parameter has already expired, something very similar to the Blynk timer but more dynamic, but I have already followed the code and in principle no location causes the flooding, except in the synchronization in the reload function, however this function is also called in the first connection and works very well.
The ideal would be to follow through the #define BLYNK_DEBUG Serial, however it is something that I cannot do 100% of the time, is there any way to request these debugs in my code and send them to a virtual pin that I can store in a terminal in the app?
If that’s the case tge. Why did you ask your previous question about server flooding?
No.
BLYNK_DEBUG places a massive overhead on the Blynk library, and you’re more likely to get disconnections and other performance related issues as a result of using it.
Pete.
or I can send what comes out of the #define BLYNK_PRINT serial, send it to a virtual pin and save it in a terminal, as there is no symmetry in the disconnection, so it is difficult to follow an entire day to see what may appear about the disconnection, because if I am not mistaken when there is a disconnection by the server in the serial something is printed about “heartbet timeout”, I am not sure about that.
How do you imagine that the data from BLYNK_DEBUG will make its way to the terminal widget if the device is disconnected from the Blynk server?
Pete.
well thought, I think that before disconnection there is no warning, it would perhaps be to send it to an mqtt topic on node red, however I have already tested connecting blynk and nodered together and I couldn’t make it work, blynk always disconnected
You’ve suddenly thrown MQTT and Node-Red into the mix, without any explanation about whether this is using direct MQTT or the Blynk IoT contrib for Node-Red, or any detail about what you’re trying to do.
If you’re using the same Auth token in the Blynk C++ library and in Node-Red then the Blynk server will disconnect the earlier connection.
This topic has become a jumble of random concepts, with no real info about the code you’re tuning, what is appearing in the serial monitor, or any real detail about anything.
I’ve never had reliable results with Arduino Ethernet shields, and I stoped using them about 6 years ago because they are too unreliable for my use case.
I have no idea, based on the information you’ve provided, whether there is a more appropriate hardware solution available. But, I’d suggest that you start by reviewing your hardware platform then simplify your code base to perform some tests to ensure that your platform is reliable.
I’m going to step away from the randomness of this topic, as it’s far too vague for my liking.
Pete.