pxt-common-packages 9.3.12 → 9.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,17 @@ namespace net {
3
3
  NewScan = 1,
4
4
  GotIP = 2,
5
5
  LostIP = 3,
6
+ NoScannedNetworks = 4,
7
+ NoKnownNetworks = 5,
8
+ Connecting = 6,
9
+ ConnectionFailed = 7
6
10
  }
7
11
  export class Controller {
8
12
  eventID: number
9
13
  private _isConnected = false
10
14
 
15
+ onConnectSSIDFailed: (ssid: string) => void;
16
+
11
17
  constructor() {
12
18
  this.eventID = control.allocateEventSource()
13
19
  }
@@ -75,6 +81,7 @@ namespace net {
75
81
  return
76
82
  const myReconn = {}
77
83
  this.reconnectRunning = myReconn
84
+ this.emitEvent(ControllerEvent.Connecting)
78
85
  control.runInParallel(() => {
79
86
  while (this.reconnectRunning == myReconn) {
80
87
  if (this.isConnected) {
@@ -101,6 +108,7 @@ namespace net {
101
108
  this.scanNetworks()
102
109
  if (!this.lastScanResults || this.lastScanResults.length == 0) {
103
110
  net.log(`no networks detected`)
111
+ this.emitEvent(ControllerEvent.NoScannedNetworks)
104
112
  return false
105
113
  }
106
114
 
@@ -114,6 +122,7 @@ namespace net {
114
122
 
115
123
  if (!networks.length) {
116
124
  net.log(`no known networks`)
125
+ this.emitEvent(ControllerEvent.NoKnownNetworks)
117
126
  return false
118
127
  }
119
128
 
@@ -127,15 +136,20 @@ namespace net {
127
136
  // try connecting to known networks
128
137
  for (const network of networks) {
129
138
  net.log(`connecting to ${network.ssid}...`)
130
- if (this.connectAP(network.ssid, wifis[network.ssid])) {
139
+ const pwd = wifis[network.ssid]
140
+ if (this.connectAP(network.ssid, pwd)) {
131
141
  net.log(`connected to ${network.ssid}`)
132
142
  return true
133
143
  }
134
144
  if (!this.reconnectRunning)
135
145
  return false
146
+
147
+ if (this.onConnectSSIDFailed)
148
+ this.onConnectSSIDFailed(network.ssid)
136
149
  }
137
150
 
138
151
  net.log(`connection failed`)
152
+ this.emitEvent(ControllerEvent.ConnectionFailed)
139
153
  return false
140
154
  }
141
155