Trying to understand the best approach to check the Blynk connection and re-establish it if need. I am building a weather app that has a TX and RX unit. The TX unit is outside and can loose connection to WiFi at times. I want to ensure that it can recover and re-connect. I also don’t want to inundate Blynk with request. Is the below code the best way to do this?
Edit: just tested this and it does not seem to enter if (!Blynk.connected()) even though I know it looses the WiFi connection.
void setup()
{
//connect to Blynk.
Blynk.begin(auth, ssid, password);
while (Blynk.connect() == false) {
//Wait until connected
//Serial.print("x");
}
}
void loop()
{
Blynk.run();
//If Blynk is not connected, re-establish connection
if (!Blynk.connected())
{
//Serial.print("Lost connection. Re-connecting");
Blynk.begin(auth, ssid, password);
while (Blynk.connect() == false) {
//do nothing but wait
//Serial.print(".");
}
}
}
Code snippets should be formatted. Edit your post.
Wrap the code by adding 3 Backtick: ``` symbols:
Example:
``` cpp <--put 3 backticks BEFORE your code starts (cpp means C++ language)
//Put your code here
//..................
//..................
``` <--insert 3 backticks AFTER your code
**This makes your code readable and with highlighted syntax, like this:**
Did that and got the above result Even see 3 ``` when editing. Not sure how I will ever remember that given every forum is different and most provide an easy way to do it from the menu bar. How about making it easy for us to post with a code tag? Back to my question. Surely there must be a way to check the connection and re-initiate when it fails. I’ve tested the above and it does not work on an Adafruit Huzzah (ESP8266)
@deejayspinz we are using Discourse community platform, which supports regular markup language, nothing fancy. It’s the same as GitHub and many many other websites.
Tried the one on the menu bar already… guess it just doesn’t like the code I pasted in. Anyway… looks like I may have to seek assistance elsewhere given the focus on how I pasted my code. It’s not like its completely unreadable… Seems there is more concern about being the formatting police than assisting with the issue. Cant say I didn’t try…