How to detect if the conection is 2G, 3G, 4G or WIFI?


#1

As title says… is it possible?


#2

Hi,

I’m not sure if this is possible. It may be possible with an extension - so you could contact Taifun to see if they could add it to their Telephony Manager Extension.


#3

@Conor, thanks for information. In fact, I’m seeking another way to take this info, because all Taifun’s extensions has some strange behavior in some cases. Because of it, I am asking if there is some way to get this. If not, there’s no problem.


#4

IDK if there is a block method, but you can make it using a PHP script (everything is possible with PHP xD) and get the response with the WebComponent

Later I will make one and share it here and upload to my server so anyone could use it


#5

@barreeeiroo, thanks for the input. I’ll wait for your example.


#6

#Connection Type Detector

It is not a perfect system, but will help you to difference between WiFi Connection and Data Connection ONLY IN SMARTPHONES (including Android and iOS)

First of all, I think that I talked too much in my first post.
It’s not possible using PHP. The unique method using PHP is getting the ISP (Internet Service Providers) list of public IPs, so if their remote address matches it, it’s a wifi connection. But this method has two problems:

  • You need to install an extension to PHP, and lots of hostings services doesn’t allow you to do that
  • You need a database where all IPs are hosted, and this is a very hard work, because there are lots ISP arround the world with lots of IPs

So, after a research, I think that the easiest method is using JavaScript. JavaScripts has a library that allows you to get the type of connection that a mobile is using (if you are on a laptop or PC or whatever, you will get an unknow error). Also this method has a problem: it can’t difference between 2G, 3G and 4G connection, you will get only wifi connection or cellular connection.
But, I made a small trick, because the difference between 2G, 3G and 4G is the velocity, so I made a PHP script to clasify internet speed between those types of connections.


### Requests - https://scripts.thunkable.ga/connection/type/?mode=type - Will get only cellular or wifi connection - https://scripts.thunkable.ga/connection/type/?mode=speed - Will get your speed connection - https://scripts.thunkable.ga/connection/type/?mode=auto - Will get any type of connection **in smartphones**

###The script
The script is not fully in PHP as I said above. It uses some JavaScript for getting the connection type.

If you request the method type, a Mozilla Client will handle your request and say if you are on cellular data or wifi.
If you requested the method speed, your request will send a 1MB package to the server and see how many time has it taken to reach the final destination.
If you requested tthe method auto, it will mix the two requests and if you are on cellular data, it will compare your speed with speed standars, and say on what are you. If you aren’t in cellular data, it will output just wifi or unknown if you it couldn’t determinate the connection type

###How to use it

  • You can deploy your own script in your server. The script is avaliable on my Gist of GitHub (Open Source Coding, als always xD)
  • Or you can use my server for making requests: https://scripts.thunkable.ga/connection/type/ (add this if you want to get only the type: ?mode=type, this if you want the speed ?mode=speed or this if you want to get a full type analysis ?mode=auto

###How to manage the response
You will have to use a WebComponent with the WhenWeb1ReceivesText block. The responses that you will recevie depends on the request that you made:

  • If you had use the request type, you will get unknown, wifi or cellular only. But you can use speed request if you are on cellular to compare the speed with the standars of 2G, 3G or 4G

  • If you used the request speed, you will get an integer number that you can use to compare your speed with standars of the cellular data

  • Recommended method
    If you use the request auto, you will get a response between those ones: unknown, wifi, 2g, 3g, 3g+, 4g or even 5g. This method offers a full network identifier method

###Errors?
Please, report me any errors that you get with the script, I will try to fix it the better as I can


I also must say that there is not a perfect method to determinate if you are on WiFi or Cellular Data using external browser. The unique perfect method that exists is having access to network interface directly from Android, so maybe Taifun could do an extension as @Conor sais


How To Detect İnternet Download/Upload Speed?
Frequently Asked Questions (FAQ)
#7

Fantastic, @barreeeiroo !!! I’ll try it and tell you my results!!!
Even there’s no a solution in Thunkable, maybe this is a suggestion for Thunkable team!!!


#8

Thanks :thumbsup:

I noticed that the values for comparing the speed in the auto mode are innaccurate and always show 5G
Maybe I have to try with lower connections, adjust better those values or even increase the package to get the Internet speed


#9

Another method to check if the device is connected to wifi is to use the WiFi Manager Extension by Taifun and use getSSID() method .It returns an empty string if not connected or returns the SSID of connected network if connected.



#10

Connecting to a Wifi network doesn’t necessarily mean the device is connected to internet.


#11

To check if the device is connected to the internet this guide can be used :

http://www.imagnity.com/tutorials/app-inventor/check-internet-connection-in-app-inventor/


Webview > check if User have internet connection
#12

To know if you are in 2g 3g 4g you need allcellinfo , and parse the network type - Gsm Wcdma or Lte
Ask Taifun