BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Run program without wifi connection

Hello there!

I have a device that turn something on/off and has a hardware button.

The problem is, that I want to use this device sometimes in areas where I have no wifi and it should still work by pressing the botton to turn on/off.

With Blynk.begin the program stucks at the setup, waiting for the wifi connection.
Its the same with Blynk.connectWiFi and Blynk.config how can I bypass these blocking functions with a timeout or similar?

Thanks in advance!

Not sure, but I think he wants to use blynk app without internet. :rofl:

I don’t think so. He talks about a physical switch that should work without an internet connection, so just needs to get to grips with Blynk.config and Blynk.connect

Pete.

2 Likes

@ IBK Thanks a lot.
That was exactly what I was looking for.

Is there a common way of updating the changed states of the Blynk variables (Virtual Pins), that changed while the device beeing offline, to the server after reconnection?

Or should I save the state of each pin and actively push them to server on reconnect?

Because I suspect that a simple Blynk.syncAll(); will just load the values from the server and not push the actual values to the server.

@Blynk_Coeur: Pretty smart comment…
And by the way. Everyone can use the blynk app without internet. It just wont do anything.
So clarify your sacastic reply next time better in writing “he wants to use blynk without internet”.

My intension was clearly to let the device work without internet connection by reacting on pushing a HARDWARE button.
I dont know if you can imagine this, but microcontrollers can also work without blynk… even more they can also work offline.

1 Like

I think @Blynk_Coeur comment was a genuine mistake rather than an attempt to be smart/sarcastic.
From personal experience, it’s very easy to flick through a couple of similar threads and get them mixed-up; or to half-read a post and answer the wrong question.

Even if you didn’t like the tone of a response from a regular contributor, it’s not good form to have a rant about it, as it tends to piss-off the other regulars.

Yes, that’s the way to do it, using virtualWrites. As you correctly assumed, sync works the other way.

The best point at which to push the values to the server is on connection to the server. Look at the Blynk.connected command.

Pete.

1 Like

Yes, that’s the way to do it, using virtualWrites. As you correctly assumed, sync works the other way.

Great. As I have the some other functions inside the BLYNK_WRITE() functions I will set the Virtual Pin to the wanted value Blynk.virtualWrite(V1, 0); and then sync it with Blynk.syncVirtual(V1);

This should behave like I have pressed the button on the app right?

As there is a function that gets called after a connection has established, I can use this and sync everything… to my logic, it should work like this:

BLYNK_CONNECTED() {
  if (status == 1)
  {
    Blynk.virtualWrite(V1, 1);
  }
  else
  {
    Blynk.virtualWrite(V1, 0);
  }
  Blynk.syncAll();
}

I appreciate your comment about Blynk_Coeurs comment, but I would say making fun of someone isnt a good form either - also if he is a well known member and has therefore a higher status.

I dont like this sort of replys in forums in general (in this case he was even wrong with his assumtion) as it can frustrate newbees and doesnt help at all.
So I see no point in posting this.
I normally tend to comment these kind of posts in a similar way to show how it feels.
I know this is living on the edge, but I think Blynk_Coeur can take it and knows how it was meant.
If not @Blynk_Coeur: I’m sorry and all the best :slight_smile:

1 Like

There’s really no need to do that bit.
You’re in effect saying “okay, Blynk is now connected again. Blynk, the value of V1 is x. Now tell me what the value of V1 is”

Pete.

1 Like

I may be off on this (or misunderstanding you), but I do not think this would work.
Blynk.virtualWrite(V1, 0); would write the value to the server, Blynk.syncVirtual(V1); would retrieve/read the value from the server. If you are not connected to the server, then it cannot write/read the value from it.

I think your approach with the BLYNK_CONNECTED would work, provided the status variable is being updated with the physical button press and the virtual button press (when BLYNK is connected).

I guess it is just a matter of which one you want to take precedence upon connection to the BLYNK server. You can either update the state of the virtual button to match the state of the device being controlled, or update the device being controlled to the state of the virtual button.

Take a look at the Sync Physical Button Example on the Sketch Builder. In the BLYNK_CONNECTED function it gives you the option to choose.

Yes I thought @Phil333 was a beginner, and I did not realize he had physical switches, sorry !

1 Like