1

I am developing Hybrid mobile app using Ionic to support both iOS and Android. Just wanted to determine network strength like Poor connection. Using cordova-plugin-network-information

I am able to find network connection type like WiFi, 2G,3G etc. But not sure how to determine connection speed to ensure whether it has poor connection. Can anyone please help me to get this? Thank you in Advance.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Nirmal Pandey
  • 21
  • 1
  • 5
  • Using this plugin cordova-wifiinfo-plugin I am able to get LinkSpeed. Any suggestion on what scale will determine poor connection for 2G,3G,4G and WiFi – Nirmal Pandey Apr 09 '18 at 19:46
  • Using Cordova-wifiinfo-plugin I am able to track linkspeed in android but not in iOS. Someone can please help for iOS – Nirmal Pandey Apr 11 '18 at 17:38

1 Answers1

1

I was having the same problem days ago. While I could not find best solution. I have created a new cordova plugin that you can use to get most of the basic network informations you need.

All you have to do is to run this command

cordova plugin add cordova-plugin-network-signal-strength

Usage The API has only one method window["networkSignalStrength"].networkInfo(infoType, callback).

infoType parameter could either be:

null : to get all the network details including signal strength, network type and connection state

CONNECTION_STATE : to get only the connection state which will return 0 or 1. 0 : disconnected 1 : connected

SIGNAL_STRENGTH : to get only the signal strength information. This return an object which include rssi, rssq, rssnr, rsrp, signal level and lte level

signal type range:

  • RSSI: [-113, -51, "dBm"]
  • RSSNR: [-20, +30, "dB"]
  • RSRQ: [-34, 3, "dB"]
  • RSRP: [-140, -43, "dBm"]

NETWORK_TYPE : to get type of connected network. Return integer -1 to 5

  • -1 : unknown
  • 0 : disconnected
  • 1 : wifi
  • 2 : 2g
  • 3 : 3g
  • 4 : 4g
  • 5 : roaming

code snippet

// to get full network information

window['networkSignalStrength'] ? .networkInfo(null, (networkInfoData) => {
  console.log('network signal data :', networkInfoData)
});

/**
  You receive -1 as a result if the device is unable to get a known network 
  type and 0 for offline or disconnected state.
*/
// to get only signal strength
window['networkSignalStrength'] ? .networkInfo("SIGNAL_STRENGTH",
  (networkInfoData) => {
    console.log('network signal data :', networkInfoData)
  });

/**
  You should call the window.SignalStrength.dbm only after cordova platform is 
  ready. Example in Ionic framework:
 */

// ensure platform is ready before calling the plugin method
$ionicPlatform.ready().then(() => {
  // Platform now ready, execute any required native code
  setInterval(() => {
    window['networkSignalStrength'] ? .networkInfo(null, (networkInfoData) => {
      console.log('network signal data :', networkInfoData)
    });
  }, 5000)
});

cordova-plugin-network-signal-strength