为外部硬件设置一键连接WiFi HF-SmartLink V7的使用

SmartLink V7 配合新固件(AT+VER V1.0.08 及以上版本,SDK 版本

1.50,汉枫官网可下载最新固件和 SDK),成功率和配网速度有提高。

1  安装完毕后,在智能终端桌面中有以下图标:
2  智能终端 Wi-Fi 连接上路由器(必须是 2.4G 频段)后点击图标进入程序主页面,
点击如下的任意选项进入设置界面。
HF-SmartLink 使用简介
上海汉枫电子科技有限公司  4/9
3  设置界面如下说明
3.1 SSID: 默认为手机所连接的路由器 SSID。
3.2 Password: 路由器的连接密码。
HF-SmartLink 使用简介
上海汉枫电子科技有限公司  5/9
4  点击模组【nReload】按键启动 SmartLink 配置功能,模组自动重启后
【nLink】灯快闪提示 SmartLink 配置模式启动,需要尽快执行步骤 4。输入
密码后点击 APP【start】按钮,推送配置信息给模组,APP 提示正在配置,
如下图:
HF-SmartLink 使用简介
上海汉枫电子科技有限公司  6/9
5  配置完成后,模组自动重启切换到 STA 模式去连接路由器。
a) nLink 灯慢闪校验配置信息是否正确,正确情况下,模块 nLink 灯常亮提
示已连接到此路由器,APP 提示配置成功,如下图左。
b) 错误情况下 nLink 灯一直慢闪,需要重新按以上流程配置
c) 整个配置时间持续 30 秒,一次可配置多个设备,有设备配置成功则最后提
示配置成功,如下图中,否则提示超时,如下图右
HF-SmartLink 使用简介
上海汉枫电子科技有限公司  7/9
附录:
1、汉枫 Wi-Fi 模组推荐硬件连接。
a)  nReload:SmartLink 启动按键
b)  nLink:SmartLink 状态指示。
2、IOS APP 另有【配置单个设备】选项,选中后有配置一个设备成功后就立即停
止返回结果,配置流程与 Android 一致。

package com.hiflying.smartlink.demo;


import com.hiflying.smartlink.ISmartLinker;
import com.hiflying.smartlink.OnSmartLinkListener;
import com.hiflying.smartlink.SmartLinkedModule;
import com.hiflying.smartlink.v3.SnifferSmartLinker;
import com.hiflying.smartlink.v7.MulticastSmartLinker;


import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class CustomizedActivity extends Activity implements OnSmartLinkListener{

public static final String EXTRA_SMARTLINK_VERSION = "EXTRA_SMARTLINK_VERSION";

private static final String TAG = "CustomizedActivity";


protected EditText mSsidEditText;
protected EditText mPasswordEditText;
protected Button mStartButton;
protected ISmartLinker mSnifferSmartLinker;
private boolean mIsConncting = false;
protected Handler mViewHandler = new Handler();
protected ProgressDialog mWaitingDialog;
private BroadcastReceiver mWifiChangedReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

int smartLinkVersion = getIntent().getIntExtra(EXTRA_SMARTLINK_VERSION, 3);
if(smartLinkVersion == 7) {
mSnifferSmartLinker = MulticastSmartLinker.getInstance();
}else {
mSnifferSmartLinker = SnifferSmartLinker.getInstance();
}

mWaitingDialog = new ProgressDialog(this);
mWaitingDialog.setMessage(getString(R.string.hiflying_smartlinker_waiting));
mWaitingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
}
});
mWaitingDialog.setOnDismissListener(new OnDismissListener() {

@Override
public void onDismiss(DialogInterface dialog) {


mSnifferSmartLinker.setOnSmartLinkListener(null);
mSnifferSmartLinker.stop();
mIsConncting = false;
}
});

setContentView(R.layout.activity_customized);
mSsidEditText = (EditText) findViewById(R.id.editText_hiflying_smartlinker_ssid);
mPasswordEditText = (EditText) findViewById(R.id.editText_hiflying_smartlinker_password);
mStartButton = (Button) findViewById(R.id.button_hiflying_smartlinker_start);
mSsidEditText.setText(getSSid());


mStartButton.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(!mIsConncting){


//设置要配置的ssid 和pswd
try {
mSnifferSmartLinker.setOnSmartLinkListener(CustomizedActivity.this);
//开始 smartLink
mSnifferSmartLinker.start(getApplicationContext(), mPasswordEditText.getText().toString().trim(), 
mSsidEditText.getText().toString().trim());
mIsConncting = true;
mWaitingDialog.show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});

mWifiChangedReceiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo != null && networkInfo.isConnected()) {
mSsidEditText.setText(getSSid());
mPasswordEditText.requestFocus();
mStartButton.setEnabled(true);
}else {
mSsidEditText.setText(getString(R.string.hiflying_smartlinker_no_wifi_connectivity));
mSsidEditText.requestFocus();
mStartButton.setEnabled(false);
if (mWaitingDialog.isShowing()) {
mWaitingDialog.dismiss();
}
}
}
};
registerReceiver(mWifiChangedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mSnifferSmartLinker.setOnSmartLinkListener(null);
try {
unregisterReceiver(mWifiChangedReceiver);
} catch (Exception e) {
e.printStackTrace();
}
}




@Override
public void onLinked(final SmartLinkedModule module) {
// TODO Auto-generated method stub

Log.w(TAG, "onLinked");
mViewHandler.post(new Runnable() {


@Override
public void run() {
Toast.makeText(getApplicationContext(), getString(R.string.hiflying_smartlinker_new_module_found, module.getMac(), module.getModuleIP()), 
Toast.LENGTH_SHORT).show();
}
});
}




@Override
public void onCompleted() {

Log.w(TAG, "onCompleted");
mViewHandler.post(new Runnable() {


@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), getString(R.string.hiflying_smartlinker_completed), 
Toast.LENGTH_SHORT).show();
mWaitingDialog.dismiss();
mIsConncting = false;
}
});
}




@Override
public void onTimeOut() {

Log.w(TAG, "onTimeOut");
mViewHandler.post(new Runnable() {


@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), getString(R.string.hiflying_smartlinker_timeout), 
Toast.LENGTH_SHORT).show();
mWaitingDialog.dismiss();
mIsConncting = false;
}
});
}


private String getSSid(){


WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
if(wm != null){
WifiInfo wi = wm.getConnectionInfo();
if(wi != null){
String ssid = wi.getSSID();
if(ssid.length()>2 && ssid.startsWith("\"") && ssid.endsWith("\"")){
return ssid.substring(1,ssid.length()-1);
}else{
return ssid;
}
}
}


return "";
}
}

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f0f0f0"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:padding="20dp" >


<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Customized Text" 
   android:gravity="center"/>


    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp">


        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hiflying_smartlinker_ssid" 
                android:gravity="center"/>


            <EditText
                android:id="@+id/editText_hiflying_smartlinker_ssid"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:editable="false"/>
        </TableRow>


        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hiflying_smartlinker_password" 
                android:gravity="center"/>


            <EditText
                android:id="@+id/editText_hiflying_smartlinker_password"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"/>
        </TableRow>
    </TableLayout>


    <Button
        android:id="@+id/button_hiflying_smartlinker_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="10dp"
        android:text="@string/hiflying_smartlinker_start" />


</LinearLayout>

strings

<resources>


    <string name="hiflying_smartlinker_ssid">SSID:</string>
    <string name="hiflying_smartlinker_password">密码:</string>
    <string name="hiflying_smartlinker_start">开始</string>
    <string name="hiflying_smartlinker_waiting">请稍后&#8230;</string>
    <string name="hiflying_smartlinker_timeout">配置超时!</string>
    <string name="hiflying_smartlinker_completed">SmartLink 完成</string>
    <string name="hiflying_smartlinker_new_module_found" formatted="false">发现新模块: Mac-%s Ip-%s</string>
    <string name="hiflying_smartlinker_no_wifi_connectivity">没有Wifi连接</string>
</resources>

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的小巨兽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值