How to check for "connection" and save data on or offline



So this is my first time posting a tutorial so go easy :stuck_out_tongue:

One thing that my users have to do is upload data they collect (date,time,materials used,etc.) to my fusion table or WebDB. However, they may not always have an internet connection which would give an error message when they would go to upload, which is a major issue. I didn't want the data lost, and I didn't want the data just to sit in a tinyDB for ever, so I needed to have a way for the app to realize there was no connection BEFORE the error and save the data but then know when it HAD internet to complete the data upload. So below is my fix.
Here is what you WILL need on the DESIGNER side:

  1. A Web component from the ‘Connectivity’ drawer.

  2. A Clock component from the ‘Sensors’ drawer.

Label(s), Notifier(s), storage location(s)

On the BLOCKS side I will try my best to make this easy to follow. Sorry in advance.

Note: I was saving to a webdb, you can remove or modify however you want…but you should get the basics.

Once the screen starts, it will call the procedure "test data".

The clock block is there to continuously check the data connection (note I set the clock to 10 seconds but you can use any time frame you want).

All the “test connection” procedure does is call a web address (in this case

After we call the Web URL, it will do 1 of two things, either we have an internet connection, or we don’t. If the app can connect to the URL and get a return code of 200 (that is in the Web1GotText block) then it will set the ‘STAUS’ variable to true, otherwise the app will trigger an error code.

If there is an error code (you won’t see the error code unless you add a notifier block in the 'ErrorsOccured block) then it will set the ‘STATUS’ variable to false. That is how you check for internet connection.

Using the timer, it will do this check every X milliseconds you have it set for.

(If you are not going to do any data saving, ignore the ‘Check Data’ procedure, it does not apply.


Now that we have our "internet status" we can add some triggers for our "save button" (button 1).
When we click button 1, we want the app to check a few variables to make sure we aren't accidentally overwriting or re-saving data. We also want to make sure that if we are uploading data to a web based database, we have an internet connection.

These two variables are to make sure we don’t overwrite or re-upload over our data.

If the ‘STATUS’ variable is set to true (set after each call to the “test data” procedure) then we need to check to make sure we haven’t already uploaded data.

If we have uploaded data, then the ‘data uploaded’ variable will be set to true. If we haven’t uploaded data, then the app will upload or save your data your database.

If ‘STATUS’ is set to false, then the app will save the data to the tinyDB.

Now, lets say we didn’t have an internet connection (‘STATUS’ was false) when we clicked save so we stored the data to the tinyDB, but now we have an internet connection (using the timer it changed ‘STATUS’ to true). This is were the “check data” procedure comes into play.

You’ll remember that after the “test data” procedure there was the “call check data” block in both the screenError and WebGotText blocks.
The reason that is there is to tell the app "hey we have a connection again, check to see if we have any saved data that needs uploaded."

If the ‘STATUS’ is true, the “check data” procedure then calls the “upload offline data” procedure.

In this procedure we want to check to make sure that there is data stored to the tinyDB AND that the data was not uploaded already.
If both of those arguments are met then we call the stored data from the tinyDB and then upload it to our database, clear the saved files from the tinyDB and set the ‘data stored’ variable to false (since there is no longer data stored).

You'll notice that there are a few other blocks in the aia...they should be easy to understand how and why they are there, but if you need help please let me know.
Again, this is a quick and easy way to check for an internet connection since I know of no other way for the app to check internet/data connection status. If you have an easier solution I am eager to hear it.
If anyone ever needs help or ideas, I am willing to try and help with most any issue.
Also, not going for glory here but if you copy this to use for any other publication or tutorial all I ask is please add an *bySomethingClever in the credits :)


connectivitytest.aia (6.6 KB)

Internet connection check ؟
Webview > check if User have internet connection
No internet connection on the screen when there is no internet connection
How can I auto save offline data?
How to create a reward app?
How to view Firebase Logs
Adding and retrieving values to a TinyDB list in the background for webhook posting

@Somethingclever This is super amazing!!! Thank you so much for sharing this.


Very nice exsample! :slight_smile: @Somethingclever

You can do check only internet connection well as in my example below

You can find the complete snippet here:

best regards

Frequently Asked Questions (FAQ)

Woah, very impressive work :slight_smile:


Thanks everyone! Glad it seems useful :slight_smile:


A post was split to a new topic: Download fusion table data to tiny db


Hi I need To Help…Plz… Help me my fb:


what about asking your question here in the forum?
isn’t that why a forum exists?