Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XuXiangJun committed Sep 10, 2021
1 parent 95e4e77 commit 105c9a6
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The devices need run smart config: [esp-idf](https://github.com/espressif/esp-id
implementation 'com.github.EspressifApp:lib-esptouch-android:1.0.0'
```
```
implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.0.0'
implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.1.0'
```

## Lib Source Code
Expand Down
18 changes: 8 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.espressif.esptouch.android"
minSdkVersion 21
targetSdkVersion 30
versionCode 26
versionName "v2.0.0"
versionCode 29
versionName "v2.3.0"
}

signingConfigs {
Expand All @@ -32,19 +32,17 @@ android {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}

dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'

implementation 'com.github.EspressifApp:lib-esptouch-android:1.0.0'
implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.0.0'
// implementation project(':esptouch')
// implementation project(':esptouch-v2')
implementation 'com.github.EspressifApp:lib-esptouch-v2-android:2.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class EspProvisioningActivity extends AppCompatActivity {

public static final String KEY_PROVISION = "provision";
public static final String KEY_PROVISION_REQUEST = "provision_request";
public static final String KEY_DEVICE_COUNT = "device_count";

private List<EspProvisioningResult> mStations;
private StationAdapter mStationAdapter;
Expand All @@ -51,6 +52,8 @@ public class EspProvisioningActivity extends AppCompatActivity {

private long mTime;

private int mWillProvisioningCount = -1;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -62,6 +65,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}

EspProvisioningRequest request = getIntent().getParcelableExtra(KEY_PROVISION_REQUEST);
mWillProvisioningCount = getIntent().getIntExtra(KEY_DEVICE_COUNT, -1);
assert request != null;
mProvisioner = new EspProvisioner(getApplicationContext());

Expand Down Expand Up @@ -171,6 +175,10 @@ public void onResponse(EspProvisioningResult result) {
runOnUiThread(() -> {
mStations.add(result);
mStationAdapter.notifyItemInserted(mStations.size() - 1);

if (mWillProvisioningCount > 0 && mStations.size() >= mWillProvisioningCount) {
mProvisioner.stopProvisioning();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
Expand All @@ -29,7 +30,6 @@ public class EspTouch2Activity extends EspTouchActivityAbs {
private static final String TAG = EspTouch2Activity.class.getSimpleName();

private static final int REQUEST_PERMISSION = 0x01;
private static final int REQUEST_PROVISIONING = 0x02;

private EspProvisioner mProvisioner;

Expand All @@ -43,25 +43,25 @@ public class EspTouch2Activity extends EspTouchActivityAbs {
private int mMessageVisible;
private int mControlVisible;

private ActivityResultLauncher<Intent> mProvisionLauncher;

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

mBinding = ActivityEsptouch2Binding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());

mProvisionLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> mBinding.confirmBtn.setEnabled(true)
);

mBinding.controlGroup.setVisibility(View.INVISIBLE);
mBinding.confirmBtn.setOnClickListener(v -> {
EspProvisioningRequest request = genRequest();
if (request == null) {
return;
if (launchProvisioning()) {
mBinding.confirmBtn.setEnabled(false);
}
if (mProvisioner != null) {
mProvisioner.close();
}
Intent intent = new Intent(EspTouch2Activity.this, EspProvisioningActivity.class);
intent.putExtra(EspProvisioningActivity.KEY_PROVISION_REQUEST, request);
startActivityForResult(intent, REQUEST_PROVISIONING);
mBinding.confirmBtn.setEnabled(false);
});

ActionBar actionBar = getSupportActionBar();
Expand Down Expand Up @@ -110,18 +110,25 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_PROVISIONING) {
mBinding.confirmBtn.setEnabled(true);
return;
protected String getEspTouchVersion() {
return getString(R.string.esptouch2_about_version, IEspProvisioner.ESPTOUCH_VERSION);
}

private boolean launchProvisioning() {
EspProvisioningRequest request = genRequest();
if (request == null) {
return false;
}
if (mProvisioner != null) {
mProvisioner.close();
}

super.onActivityResult(requestCode, resultCode, data);
}
Intent intent = new Intent(EspTouch2Activity.this, EspProvisioningActivity.class);
intent.putExtra(EspProvisioningActivity.KEY_PROVISION_REQUEST, request);
intent.putExtra(EspProvisioningActivity.KEY_DEVICE_COUNT, getDeviceCount());
mProvisionLauncher.launch(intent);

@Override
protected String getEspTouchVersion() {
return getString(R.string.esptouch2_about_version, IEspProvisioner.ESPTOUCH_VERSION);
return true;
}

private boolean checkState() {
Expand Down Expand Up @@ -190,7 +197,7 @@ private EspProvisioningRequest genRequest() {

CharSequence aesKeyChars = mBinding.aesKeyEdit.getText();
byte[] aesKey = null;
if (!TextUtils.isEmpty(aesKeyChars)) {
if (aesKeyChars != null && aesKeyChars.length() > 0) {
aesKey = aesKeyChars.toString().getBytes();
}
if (aesKey != null && aesKey.length != 16) {
Expand All @@ -200,11 +207,12 @@ private EspProvisioningRequest genRequest() {

CharSequence customDataChars = mBinding.customDataEdit.getText();
byte[] customData = null;
if (!TextUtils.isEmpty(customDataChars)) {
if (customDataChars != null && customDataChars.length() > 0) {
customData = customDataChars.toString().getBytes();
}
if (customData != null && customDataChars.length() > 127) {
mBinding.customDataEdit.setError(getString(R.string.esptouch2_custom_data_error));
int customDataMaxLen = EspProvisioningRequest.RESERVED_LENGTH_MAX;
if (customData != null && customData.length > customDataMaxLen) {
mBinding.customDataEdit.setError(getString(R.string.esptouch2_custom_data_error, customDataMaxLen));
return null;
}

Expand All @@ -218,8 +226,21 @@ private EspProvisioningRequest genRequest() {
.build();
}

private int getDeviceCount() {
CharSequence deviceCountStr = mBinding.deviceCountEdit.getText();
int deviceCount = -1;
if (deviceCountStr != null && deviceCountStr.length() > 0) {
try {
deviceCount = Integer.parseInt(deviceCountStr.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
return deviceCount;
}

private static class SyncListener implements EspSyncListener {
private WeakReference<EspProvisioner> provisioner;
private final WeakReference<EspProvisioner> provisioner;

SyncListener(EspProvisioner provisioner) {
this.provisioner = new WeakReference<>(provisioner);
Expand Down
21 changes: 19 additions & 2 deletions app/src/main/res/layout/activity_esptouch2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/controlGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="apSsidLabel,apSsidText,apBssidLabel,apBssidText,ipLabel,ipText,apPasswordLayout,aesKeyLayout,customDataLayout,confirmBtn" />
app:constraint_referenced_ids="apSsidLabel,apSsidText,apBssidLabel,apBssidText,ipLabel,ipText,apPasswordLayout,aesKeyLayout,customDataLayout,confirmBtn,deviceCountLayout" />

<TextView
android:id="@+id/apSsidLabel"
Expand Down Expand Up @@ -102,14 +102,31 @@
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/deviceCountLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/esptouch2_device_count"
app:layout_constraintTop_toBottomOf="@id/apPasswordLayout">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/deviceCountEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/aesKeyLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/esptouch2_aes_key"
app:layout_constraintTop_toBottomOf="@id/apPasswordLayout"
app:layout_constraintTop_toBottomOf="@id/deviceCountLayout"
app:passwordToggleEnabled="true">

<com.google.android.material.textfield.TextInputEditText
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<string name="esptouch2_aes_key">AES 密钥</string>
<string name="esptouch2_aes_key_error">AES 密钥必须为空或者16字节数据</string>
<string name="esptouch2_custom_data">自定义数据</string>
<string name="esptouch2_custom_data_error">自定义数据不能超过127字节</string>
<string name="esptouch2_custom_data_error">自定义数据不能超过%d字节</string>
<string name="esptouch2_device_count">需要配网的设备数量</string>

<string name="esptouch2_provisioning_title">配网</string>
<string name="esptouch2_provisioning_stop">停止</string>
Expand All @@ -48,4 +49,4 @@
<string name="esptouch2_provisioning_wifi_disconnect">Wi-Fi 连接已断开</string>
<string name="esptouch2_provisioning_result_bssid">BSSID: %1$s</string>
<string name="esptouch2_provisioning_result_address">地址: %1$s</string>
</resources>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<string name="esptouch2_aes_key">AES Key</string>
<string name="esptouch2_aes_key_error">AES Key must be null or 16 bytes data</string>
<string name="esptouch2_custom_data">Custom Data</string>
<string name="esptouch2_custom_data_error">Custom data can\'t be more than 127 bytes</string>
<string name="esptouch2_custom_data_error">Custom data can\'t be more than %d bytes</string>
<string name="esptouch2_device_count">Device Count for Provisioning</string>

<string name="esptouch2_provisioning_title">Provision</string>
<string name="esptouch2_provisioning_stop">Stop</string>
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ buildscript {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.0.2'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk11
6 changes: 6 additions & 0 deletions log/log-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Update Log

## v2.3.0
- EspTouchV2
- Support set device count for provisioning
- Change custom data max length to 64 bytes
- Update esptouch-v2 lib to 2.1.0

## v2.0.0
- Support EspTouchV2
- EspTouchV2 is not compatible with EspTouch
Expand Down
6 changes: 6 additions & 0 deletions log/log-zh-rCN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Update Log

## v2.3.0
- EspTouchV2
- 增加设置配网设备个数
- 自定义数据最大长度改为 64 字节
- 更新 esptouch-v2 lib 到 2.1.0

## v2.0.0
- 支持 EspTouchV2 协议
- 注: EspTouchV2 与 EspTouch 不能兼容
Expand Down

0 comments on commit 105c9a6

Please sign in to comment.