Search code examples
javascripttizengatewaytizen-native-app

Gateway check using Javascript


How to perform gateway check in Tizen ? Or is there any way to know the IP address of the default router using Javascript ?


Solution

  • In your question you ask for a JavaScript solution. But you've tagged this question as being for Tizen native. Unless you are making a hybrid application asking for one usually means excluding the other. If JavaScript is what you are using the following is the answer.

    Sounds like you would have interest in SystemInfoWifiNetwork. It has the following interface.

     interface SystemInfoWifiNetwork : SystemInfoProperty {
        readonly attribute DOMString status;
        readonly attribute DOMString ssid;
        readonly attribute DOMString ipAddress;
        readonly attribute DOMString ipv6Address;
        readonly attribute DOMString macAddress;
        readonly attribute double signalStrength;
        readonly attribute SystemInfoWifiSecurityMode securityMode;
        readonly attribute SystemInfoWifiEncryptionType encryptionType;
        readonly attribute SystemInfoNetworkIpMode ipMode;
        readonly attribute DOMString subnetMask;
        readonly attribute DOMString gateway;
       readonly attribute DOMString dns;
     };
    

    The gateway holds the information that you are asking for. Something to take into consideration though is that in the interest of preserving power the watch may have WiFi turned off if the phone is around.

    There's already a code sample for retrieving this information on the Tizen developer site. Take a look at https://developer.tizen.org/community/tip-tech/system-information-api-guide

     function onSuccessCallback(wifi) {
          alert("Status: " + wifi.status +  "    SSID: " + wifi.ssid
          + "\nIP Address: " + wifi.ipAddress + "\nIPV6 Address: " + 
          wifi.ipv6Address + "    Signal Strength: " + wifi.signalStrength);
     }
    
     function onErrorCallback(error) {
          alert("Not supported: " + error.message);
     }
     tizen.systeminfo.getPropertyValue("WIFI_NETWORK", onSuccessCallback, onErrorCallback);