페이지 선택

 

 

1. The main features of the EasyLink SDK

♦  Send the Wi-Fi network parameters set on the mobile terminal to the device side

– Support EasyLink mode

– Support Soft AP mode

– Support EasyLink – AWS mode

♦  Go to new networked devices and interact. Implement parameter settings, OTA and other functions

Note: EasyLink mode only supports operations on IPv4 networks.

 

 

 

2. Easylink Android SDK sample

Provides a simple UI that shows how to use the EasyLink SDK. The main functions are distribution network and device discovery.

 

♦ Resources introduced by Android Studio

Dependencies {

// only broadcast version

Compile ‘io.fogcloud.sdk:easylinkv3:0.1.4’

// Broadcast multicast version at the same time

Compile ‘io.fogcloud.sdk:easylinkv3:0.1.5’

// AWS distribution version

Compile ‘io.fogcloud.sdk:easylinkv3:0.2.6’

 

In general, you can use the broadcast-only version.

Special requirements, such as the case where the broadcast cannot be received, can be used in version 0.1.5, and broadcast multicast is sent together.

 

♦ Opening the service

Need to open the service in manifest.xml now.

xml

<uses-permission android:name=”android.permission.INTERNET” />

<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />

<uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” />

<uses-permission android:name=”android.permission.CHANGE_WIFI_MULTICAST_STATE” />

<uses-permission android:name=”android.permission.CHANGE_WIFI_STATE” />

 

 

 

3. Function List

  • Get SSID
  • Start distribution network
  • Stop Distribution Network
  • Device Discovery Information

 

♦ getSSID

Get the name of the WIFI connected to the current mobile phone, ie ssid

String getSSID()

 

callback

ssid

Type:String

Description:name of Wi-Fi.

 

Sample Code

java

EasylinkP2P elp2p = new EasylinkP2P(mContext);

elink.getSSID()

 

 

♦ startEasyLink

Send the data packet (including ssid and password) to the device, send 10s continuously, then stop for 3s, then continue to send, and so on.

startEasyLink(EasyLinkParams easylinkPara, EasyLinkCallBack easylinkcb)

 

params

Parameters Type Description
easylinkPara EasyLinkParams EasyLinkParams

 

EasyLinkParams

Parameters Type default Description
ssid String no default, not null current wifi name
password String No default value, can be empty Current wifi password (8-64 bytes, the longer the distribution network speed is slower)
isSendIP Boolean The default value is false, can be empty whether to send the phone’s IP, not sent by default, if this parameter is false, then extraData is not available
runSecond int default value 60000, can be empty send continuous time, stop sending when it is up, unit ms
sleeptime int default value 50, can be empty interval between each packet of data, recommended 20-200, unit ms
extraData String No default, nullable Additional information to send to the device
rc4key String No default, nullable If you need RC4 encryption, enter the string key here

 

 

callback

easylinkcb

Type:EasyLinkCallBack

Description:Callback function after successful interface call

 

Sample Code

EasylinkP2P elp2p = new EasylinkP2P(mContext);

EasyLinkParams easylinkPara = new EasyLinkParams();

easylinkPara.ssid = “mxchip”;

easylinkPara.password = “12345678”;

easylinkPara.runSecond = 60000;

easylinkPara.sleeptime = 20;

elp2p.startEasyLink(easylinkPara, new EasyLinkCallBack() {
@Override
public void onSuccess(int code, String message) {
Log.d(TAG, code + message);
}
@Override
public void onFailure(int code, String message) {
Log.d(TAG, code + message);
}
});

 

 

 

♦ stopEasyLink

Stop sending data package.

stopEasyLink(EasyLinkCallBack easylinkcb)

 

callback

easylinkcb

type:EasyLinkCallBack

description:接口调用成功后的回调函数

 

Sample Code

elp2p.stopEasyLink(new EasyLinkCallBack() {

@Override

public void onSuccess(int code, String message) {

Log.d(TAG, code + message);

}

@Override

public void onFailure(int code, String message) {

Log.d(TAG, code + message);

}

});

 

 

 

♦ Update SSID in real time

@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {

listenwifichange();

}

private void listenwifichange() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
registerReceiver(broadcastReceiver, intentFilter);
}

BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
Log.d(TAG, “—heiheihei—“);
wifissid.setText(elp2p.getSSID());
}
}
}
};

@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(broadcastReceiver);
}

 

 

 

♦ Device discovery

The device will notify the mobile phone by broadcast after connecting to the router, which can be used in easylink success callback.Get the corresponding information inside, in the message.

elp2p.startEasyLink(elp, new EasyLinkCallBack() {

@Override

public void onSuccess(int code, String message) {

Log.d(TAG, message);

}

@Override
public void onFailure(int code, String message) {
Log.d(TAG, message);
}
});

Viewed Page List