Question about Blynk.connected()?

Hi

I write some code to send some information to Blynk , like

void update()
{
if (Blynk.connected())
{
send to Blynk;
}
}

But from the begin, when hardware bootup, before reach line Blynk.begin(), I see hardware send data to Blynk via that function, is this normal? I think from begining, value of Blynk.connected() must be false?

Once you have the basic setup correct like so:

void setup()
{
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.
  while (Blynk.connect() == false) {
    // do nothing but wait
  }
}

void loop()
{
  Blynk.run(); // All the Blynk Magic happens here...
}

then you just need to make a Blynk.virtualWrite(); call to “send data” to blynk.

1 Like

Hi

I know that, but in my case, that function used to send data to Blynk called inside another function, something like

{
  do sth;
  update();
}```

function() called from setup(), before Blynk.connect(), normal logic in this time, hardware is not connected to server yet, but hardware still send data to Blynk, it's not a big problem, but I think that maybe an some kind of error

Why are you putting functions in setup? That’s not a good practice unless you are making a battery operated sensor.

You would be best to connect the hardware, then perform functions using SimpleTimer WHILE connected.

Refer to the getting Started Blynk examples.

I store last value of some variable to SDcard, when hardware boot up, it get back last value from sdcard

you can send variable to Blynk and retrieve variable from Blynk on startup with Sync command

Some value created when hardware offline or in case of can not connect to internet

Ok, I see, sorry I couldn’t help more…

So does it return true even Blynk not started?

I think yes, it does. Let’s me check again

You may try also == false to be sure.

I checked, that’s all my mistake, Blynk.connectd() work correctly, I found out there are some wrong in my code

1 Like