This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF-LAUNCHXL: Simplelink WiFi Provisioning Android Source 2.2.17

Part Number: CC3220SF-LAUNCHXL

Hi Guys,

I am using a CC3220SF-LAUNCHXL board running the OOB app.

If I use the SimpleLink Starter Pro Android app I am able to do the provisioning successfully.

I have downloaded the Android source code ( Simplelink WiFi Provisioning Android Source 2.2.17 ) but I could not make it run in the latest Android Studio 2.33

So I started reading the source code to figure out how to use the smartconfiglib2.jar.

I have created a test android app that use the smartconfiglib2.jar as dependency. ( Code below)

When ReadWiFiCredentials is executed the wifi SSID and wifi password are read from user inputs on editboxes.

Then the app check if Wifi is available and get the ip address of the gateway (Wifi router ip).

Then the app try to create an instance of SmartConfig but I always get :

SocketExcention and Log.e(TAG, "Failed to create instance of smart config") 

The phone which runs the app in connected to the WiFi Router.

I think I am missing something before I create an instance of SmartConfig but I could not figure out what.

Any help will be higly appreciated.

Thanks

( See code below )

package com.mycompany;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.integrity_project.smartconfiglib.SmartConfig;
import com.integrity_project.smartconfiglib.SmartConfigListener;

import java.net.SocketException;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "TAG";
SmartConfig smartConfig;
SmartConfigListener smartConfigListener;
byte[] freeData;
byte[] paddedEncryptionKey;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ConnectivityManager conMan = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMan.getActiveNetworkInfo();

TextView log = (TextView) findViewById(R.id.log_text);
if (netInfo.getType() == ConnectivityManager.TYPE_WIFI)
{
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
final String ssid = connectionInfo.getSSID();
log.append("Connected to Internet via WiFi using : " + ssid + "\n");
log.append("WiFi AP IP Address : " + getGatewayIP() + "\n\n");
}
else
{
if(netInfo.getType() == ConnectivityManager.TYPE_MOBILE)
{
log.append("Connected to Internet via : " + netInfo.getTypeName() + "\n\n");
}
}

}

public void ReadWiFiCredentials(View view) {
EditText ssid_str = (EditText) findViewById(R.id.ssid_text);
EditText password_str = (EditText) findViewById(R.id.password_text);
TextView log = (TextView) findViewById(R.id.log_text);

String wifi_ssid = ssid_str.getText().toString();
String wifi_password = password_str.getText().toString();

log.append("WiFi SSID entered : " + wifi_ssid + "\n");
log.append("WiFi Password entered : " + wifi_password + "\n");

smartConfig = null;
String gateway = getGatewayIP();
freeData = null;
paddedEncryptionKey = null;

smartConfigListener = new SmartConfigListener() {
@Override
public void onSmartConfigEvent(SmtCfgEvent event, Exception e) {
}
};

try {
try {
smartConfig = new SmartConfig(smartConfigListener, freeData, wifi_password, paddedEncryptionKey, gateway, wifi_ssid, (byte) 0, "");
} catch (SocketException e) {
log.append("Failed to create instance of smart config \n");
Log.e(TAG, "Failed to create instance of smart config");
} catch (Exception e) {
e.printStackTrace();
}

try {
smartConfig.transmitSettings();
Log.i(TAG, "Broadcasting information to network");
log.append("Broadcasting information to network \n");
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "smartConfig failed to broadcast.");
log.append("smartConfig failed to broadcast. \n");
}
}
catch (Exception e) {
Log.e(TAG, "Failed to start smart config " + e.getMessage());
log.append("Failed to start smart config " + e.getMessage() + "\n");
}

}

public String getGatewayIP() {
WifiManager manager = (WifiManager) super.getApplicationContext().getSystemService(WIFI_SERVICE);
DhcpInfo dhcp = manager.getDhcpInfo();
int ip = dhcp.gateway;
return int2IP(ip);
}

public String int2IP(int addr) {
return ((addr & 0xFF) + "." +
((addr >>>= 8) & 0xFF) + "." +
((addr >>>= 8) & 0xFF) + "." +
((addr >>>= 8) & 0xFF));
}
}