30
30
import com .espressif .provisioning .DeviceConnectionEvent ;
31
31
import com .espressif .provisioning .ESPConstants ;
32
32
import com .espressif .provisioning .ESPProvisionManager ;
33
+ import com .espressif .provisioning .listeners .ResponseListener ;
33
34
import com .espressif .wifi_provisioning .R ;
34
35
35
36
import org .greenrobot .eventbus .EventBus ;
@@ -47,7 +48,7 @@ public class ProofOfPossessionActivity extends AppCompatActivity {
47
48
private TextView txtNextBtn ;
48
49
49
50
private String deviceName ;
50
- private TextView tvPopInstruction ;
51
+ private TextView tvPopInstruction , tvPopError ;
51
52
private EditText etPop ;
52
53
private ESPProvisionManager provisionManager ;
53
54
@@ -111,14 +112,36 @@ public void onClick(View v) {
111
112
112
113
final String pop = etPop .getText ().toString ();
113
114
Log .d (TAG , "POP : " + pop );
115
+ tvPopError .setVisibility (View .INVISIBLE );
114
116
provisionManager .getEspDevice ().setProofOfPossession (pop );
115
- ArrayList <String > deviceCaps = provisionManager .getEspDevice ().getDeviceCapabilities ();
116
117
117
- if (deviceCaps .contains ("wifi_scan" )) {
118
- goToWiFiScanListActivity ();
119
- } else {
120
- goToWiFiConfigActivity ();
121
- }
118
+ provisionManager .getEspDevice ().initSession (new ResponseListener () {
119
+ @ Override
120
+ public void onSuccess (byte [] returnData ) {
121
+ runOnUiThread (new Runnable () {
122
+ @ Override
123
+ public void run () {
124
+ ArrayList <String > deviceCaps = provisionManager .getEspDevice ().getDeviceCapabilities ();
125
+ if (deviceCaps .contains ("wifi_scan" )) {
126
+ goToWiFiScanListActivity ();
127
+ } else {
128
+ goToWiFiConfigActivity ();
129
+ }
130
+ }
131
+ });
132
+ }
133
+
134
+ @ Override
135
+ public void onFailure (Exception e ) {
136
+ e .printStackTrace ();
137
+ runOnUiThread (new Runnable () {
138
+ @ Override
139
+ public void run () {
140
+ tvPopError .setVisibility (View .VISIBLE );
141
+ }
142
+ });
143
+ }
144
+ });
122
145
}
123
146
};
124
147
@@ -137,6 +160,7 @@ private void initViews() {
137
160
tvBack = findViewById (R .id .btn_back );
138
161
tvCancel = findViewById (R .id .btn_cancel );
139
162
tvPopInstruction = findViewById (R .id .tv_pop );
163
+ tvPopError = findViewById (R .id .tv_error_pop );
140
164
etPop = findViewById (R .id .et_pop );
141
165
142
166
tvTitle .setText (R .string .title_activity_pop );
0 commit comments