pxt-common-packages 9.4.7 → 9.4.11

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.
Files changed (85) hide show
  1. package/built/common-sim.d.ts +1 -0
  2. package/built/common-sim.js +3 -0
  3. package/libs/accelerometer/built/debug/binary.js +8 -8
  4. package/libs/azureiot/built/debug/binary.js +485 -485
  5. package/libs/base/fixed.ts +6 -0
  6. package/libs/color/built/debug/binary.js +8 -8
  7. package/libs/color-sensor/built/debug/binary.js +8 -8
  8. package/libs/controller/built/debug/binary.js +8460 -7857
  9. package/libs/controller---none/built/debug/binary.js +8439 -7836
  10. package/libs/core/built/debug/binary.js +2 -2
  11. package/libs/core---samd/built/debug/binary.js +8 -8
  12. package/libs/datalogger/built/debug/binary.js +63 -63
  13. package/libs/edge-connector/built/debug/binary.js +8 -8
  14. package/libs/esp32/built/debug/binary.js +486 -486
  15. package/libs/game/_locales/game-jsdoc-strings.json +6 -0
  16. package/libs/game/built/debug/binary.js +8401 -7798
  17. package/libs/game/controllerbutton.ts +98 -1
  18. package/libs/game/docs/reference/scene/get-neighboring-location.md +123 -0
  19. package/libs/game/docs/reference/scene/get-tile-location.md +1 -5
  20. package/libs/game/docs/reference/scene/location.md +246 -0
  21. package/libs/game/docs/reference/scene/tile-at-location-equals.md +1 -1
  22. package/libs/game/docs/reference/scene/tile-at-location-is-wall.md +98 -0
  23. package/libs/game/docs/reference/scene/tile-image-at-location.md +65 -0
  24. package/libs/game/docs/reference/scene/tilemap-location.md +83 -0
  25. package/libs/game/docs/reference/sprites/destroy-all-sprites-of-kind.md +74 -0
  26. package/libs/game/docs/reference/sprites/sprite/change-scale.md +65 -0
  27. package/libs/game/docs/reference/sprites/sprite/fx.md +25 -25
  28. package/libs/game/docs/reference/sprites/sprite/fy.md +24 -24
  29. package/libs/game/docs/reference/sprites/sprite/scale.md +80 -0
  30. package/libs/game/docs/reference/sprites/sprite/set-scale.md +79 -0
  31. package/libs/game/docs/reference/sprites/sprite/sx.md +80 -0
  32. package/libs/game/docs/reference/sprites/sprite/sy.md +80 -0
  33. package/libs/game/docs/reference/sprites.md +12 -2
  34. package/libs/game/hitbox.ts +5 -5
  35. package/libs/game/scene.ts +2 -0
  36. package/libs/game/sprite.ts +7 -7
  37. package/libs/game/sprites.ts +1 -1
  38. package/libs/game/tilemap.ts +88 -4
  39. package/libs/gamepad/built/debug/binary.js +8 -8
  40. package/libs/keyboard/built/debug/binary.js +8 -8
  41. package/libs/lcd/built/debug/binary.js +8 -8
  42. package/libs/light/built/debug/binary.js +8 -8
  43. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  44. package/libs/lora/built/debug/binary.js +8 -8
  45. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  46. package/libs/microphone/built/debug/binary.js +8 -8
  47. package/libs/mouse/built/debug/binary.js +8 -8
  48. package/libs/mqtt/built/debug/binary.js +200 -200
  49. package/libs/music/built/debug/binary.js +8 -8
  50. package/libs/net/built/debug/binary.js +200 -200
  51. package/libs/net/controller.ts +10 -1
  52. package/libs/net-game/built/debug/binary.js +10125 -9522
  53. package/libs/palette/built/debug/binary.js +8400 -7797
  54. package/libs/pixel/built/debug/binary.js +8 -8
  55. package/libs/power/built/debug/binary.js +8 -8
  56. package/libs/proximity/built/debug/binary.js +8 -8
  57. package/libs/pulse/built/debug/binary.js +8 -8
  58. package/libs/radio/built/debug/binary.js +8 -8
  59. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  60. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  61. package/libs/screen/built/debug/binary.js +50 -50
  62. package/libs/servo/built/debug/binary.js +8 -8
  63. package/libs/sprite-scaling/_locales/sprite-scaling-strings.json +5 -7
  64. package/libs/sprite-scaling/built/debug/binary.js +8400 -7797
  65. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-by-percent.md +77 -0
  66. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-by-pixels.md +144 -0
  67. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-to-percent.md +83 -0
  68. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-to-pixels.md +140 -0
  69. package/libs/sprite-scaling/scaling.ts +51 -50
  70. package/libs/storyboard/built/debug/binary.js +8400 -7797
  71. package/libs/tests/built/debug/binary.js +15 -15
  72. package/libs/thermometer/built/debug/binary.js +8 -8
  73. package/libs/wifi---esp32/README.md +12 -0
  74. package/libs/wifi---esp32/buildlogin.sh +1 -0
  75. package/libs/wifi---esp32/controller.ts +27 -1
  76. package/libs/wifi---esp32/enums.d.ts +4 -0
  77. package/libs/wifi---esp32/httpserver.cpp +168 -0
  78. package/libs/wifi---esp32/login.full.html +37 -0
  79. package/libs/wifi---esp32/login.html +1 -0
  80. package/libs/wifi---esp32/pxt.json +1 -0
  81. package/libs/wifi---esp32/shims.d.ts +8 -0
  82. package/libs/wifi---esp32/sim/wifisockets.ts +3 -0
  83. package/libs/wifi---esp32/wifi.cpp +24 -15
  84. package/libs/wifi---esp32/wifi.h +15 -1
  85. package/package.json +1 -1
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P26173(s) {
59
+ function _main___P26203(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,25 +66,25 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___26414 = (undefined);
70
- globals._pollEventQueue___26427 = (undefined);
71
- globals._tests___26614 = (undefined);
72
- globals._currentTest___26616 = (undefined);
73
- globals._runSetup___26618 = (undefined);
74
- globals._runTearDown___26620 = (undefined);
75
- globals._testSetUp___26622 = (undefined);
76
- globals._testTearDown___26624 = (undefined);
69
+ globals._intervals___26446 = (undefined);
70
+ globals._pollEventQueue___26459 = (undefined);
71
+ globals._tests___26646 = (undefined);
72
+ globals._currentTest___26648 = (undefined);
73
+ globals._runSetup___26650 = (undefined);
74
+ globals._runTearDown___26652 = (undefined);
75
+ globals._testSetUp___26654 = (undefined);
76
+ globals._testTearDown___26656 = (undefined);
77
77
  r0 = undefined;
78
78
  return leave(s, r0)
79
79
  default: oops()
80
80
  } } }
81
- _main___P26173.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"targetoverrides.ts","functionName":"<main>","argumentNames":[]}
82
- _main___P26173.continuations = [ ]
81
+ _main___P26203.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"targetoverrides.ts","functionName":"<main>","argumentNames":[]}
82
+ _main___P26203.continuations = [ ]
83
83
 
84
- function _main___P26173_mk(s) {
84
+ function _main___P26203_mk(s) {
85
85
  checkStack(s.depth);
86
86
  return {
87
- parent: s, fn: _main___P26173, depth: s.depth + 1,
87
+ parent: s, fn: _main___P26203, depth: s.depth + 1,
88
88
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
89
89
  } }
90
90
 
@@ -92,7 +92,7 @@ function _main___P26173_mk(s) {
92
92
 
93
93
 
94
94
 
95
- const breakpoints = setupDebugger(1, ["_tests___26614","_currentTest___26616","_runSetup___26618","_runTearDown___26620","_testSetUp___26622","_testTearDown___26624"])
95
+ const breakpoints = setupDebugger(1, ["_tests___26646","_currentTest___26648","_runSetup___26650","_runTearDown___26652","_testSetUp___26654","_testTearDown___26656"])
96
96
 
97
- return _main___P26173
97
+ return _main___P26203
98
98
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P14338(s) {
59
+ function _main___P14354(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___14579 = (undefined);
70
- globals._pollEventQueue___14592 = (undefined);
69
+ globals._intervals___14597 = (undefined);
70
+ globals._pollEventQueue___14610 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P14338.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"pxt_modules/base/ns.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P14338.continuations = [ ]
75
+ _main___P14354.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"pxt_modules/base/ns.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P14354.continuations = [ ]
77
77
 
78
- function _main___P14338_mk(s) {
78
+ function _main___P14354_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P14338, depth: s.depth + 1,
81
+ parent: s, fn: _main___P14354, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P14338_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P14338
91
+ return _main___P14354
92
92
  })
@@ -0,0 +1,12 @@
1
+ # Wifi ESP32
2
+
3
+
4
+ ## Developer
5
+
6
+ Build instructions
7
+ * install ESP IDF 4.3.1
8
+ * clone https://github.com/microsoft/pxt-common-packages, link to .
9
+ * clone https://github.com/microsoft/pxt-maker, link pxt-common-packages
10
+ * create projects/... in maker, clone https://github.com/microsoft/pxt-jacdac
11
+ * open wifi--esp32
12
+ * sh run.sh
@@ -0,0 +1 @@
1
+ npx html-minifier --removeAttributeQuotes --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --quoteCharacter "'" --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true --html5 true -o login.html login.full.html
@@ -1,4 +1,7 @@
1
1
  namespace net {
2
+ //% shim=_wifi::_readLastAccessPointCredentials
3
+ declare function _readLastAccessPointCredentials(): string[];
4
+
2
5
  const EV_ScanCompleted = 1000
3
6
 
4
7
  export class WifiController extends net.Controller {
@@ -31,7 +34,6 @@ namespace net {
31
34
  this.networks.push(ap)
32
35
  i += entrySize
33
36
  }
34
- control.dmesg(`scan completed`)
35
37
  control.raiseEvent(_wifi.eventID(), EV_ScanCompleted)
36
38
  }
37
39
 
@@ -44,6 +46,30 @@ namespace net {
44
46
  return this.networks
45
47
  }
46
48
 
49
+ public startLoginServer(hostName: string): void {
50
+ if (_wifi.isLoginServerEnabled())
51
+ return
52
+
53
+ this.disconnect()
54
+ _wifi.startLoginServer(hostName);
55
+ control.onEvent(_wifi.eventID(), WifiEvent.AccessPointCredentialsAvailable, () => {
56
+ const credentials = _readLastAccessPointCredentials()
57
+ if (!!credentials && credentials.length == 2) {
58
+ const ssid = credentials[0]
59
+ const pwd = credentials[1]
60
+ net.updateAccessPoint(ssid, pwd)
61
+ console.debug(`restarting...`);
62
+ pause(100);
63
+ control.reset();
64
+ }
65
+ })
66
+ this.emitEvent(ControllerEvent.LoginServerStarted);
67
+ }
68
+
69
+ public isLoginServerEnabled(): boolean {
70
+ return _wifi.isLoginServerEnabled()
71
+ }
72
+
47
73
  public disconnectAP() {
48
74
  _wifi.disconnect()
49
75
  }
@@ -8,6 +8,10 @@
8
8
  GotIP = 2,
9
9
  //%
10
10
  Disconnected = 3,
11
+ //%
12
+ AccessPointCredentialsAvailable = 4,
13
+ //%
14
+ LoginServerStarted = 5,
11
15
  }
12
16
 
13
17
  // Auto-generated. Do not edit. Really.
@@ -0,0 +1,168 @@
1
+ #include "wifi.h"
2
+ #include "esp_netif.h"
3
+ #include "esp_wifi.h"
4
+ #include <esp_http_server.h>
5
+ #include <mdns.h>
6
+
7
+ #define TAG "http"
8
+ #define LOG(...) ESP_LOGI(TAG, __VA_ARGS__)
9
+
10
+ namespace _wifi {
11
+
12
+ static httpd_handle_t _server = NULL;
13
+ static const char* _lastApBuffer = NULL;
14
+ static wifi_config_t wifi_config;
15
+
16
+ esp_err_t login_handler(httpd_req_t *req)
17
+ {
18
+ LOG("login");
19
+ const char resp[] = "<style>html{background:#aaa}*{font-size:xx-large;font-family:monospace}form{min-height:100vh;display:flex;justify-content:center;align-items:center;flex-direction:column;gap:.5rem}</style><meta name='viewport'content='width=device-width,initial-scale=1'><form action='/add-ap'><label for='ssid'>WiFi:</label> <input name='name'id='ssid'placeholder='WiFi'required> <label for='password'>Password:</label> <input type='password'name='password'id='password'placeholder='Password'required> <input id='submit'type='submit'value='connect'></form>";
20
+ httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
21
+ return ESP_OK;
22
+ }
23
+
24
+ esp_err_t add_ap_handler(httpd_req_t *req)
25
+ {
26
+ LOG("add_ap");
27
+
28
+ /* Read URL query string length and allocate memory for length + 1,
29
+ * extra byte for null termination */
30
+ size_t buf_len = httpd_req_get_url_query_len(req) + 1;
31
+ if (buf_len > 1 && buf_len < 256) {
32
+ char* buf = (char*)malloc(buf_len);
33
+ if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
34
+ char name[64];
35
+ char password[64];
36
+ /* Get value of expected key from query string */
37
+ if ((httpd_query_key_value(buf, "name", name, sizeof(name)) == ESP_OK) &&
38
+ (httpd_query_key_value(buf, "password", password, sizeof(password)) == ESP_OK)) {
39
+ // save ap info, let TS handle it
40
+ if (NULL == _lastApBuffer) {
41
+ _lastApBuffer = buf;
42
+ pxt::raiseEvent(_wifi::eventID(), (int)_wifi::WifiEvent::AccessPointCredentialsAvailable);
43
+ const char resp[] = "Restarting...";
44
+ httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
45
+ return ESP_OK;
46
+ }
47
+ }
48
+ }
49
+ free(buf);
50
+ return ESP_OK;
51
+ }
52
+
53
+ httpd_resp_send_500(req);
54
+ return ESP_OK;
55
+ }
56
+
57
+ //%
58
+ RefCollection *_readLastAccessPointCredentials() {
59
+ auto res = Array_::mk();
60
+ registerGCObj(res);
61
+
62
+ char name[64];
63
+ char password[64];
64
+ /* Get value of expected key from query string */
65
+ if (NULL != _lastApBuffer &&
66
+ (httpd_query_key_value(_lastApBuffer, "name", name, sizeof(name)) == ESP_OK) &&
67
+ (httpd_query_key_value(_lastApBuffer, "password", password, sizeof(password)) == ESP_OK)) {
68
+
69
+ {
70
+ auto str = mkString(name, -1);
71
+ registerGCObj(str);
72
+ res->head.push((TValue)str);
73
+ unregisterGCObj(str);
74
+ }
75
+ {
76
+ auto str = mkString(password, -1);
77
+ registerGCObj(str);
78
+ res->head.push((TValue)str);
79
+ unregisterGCObj(str);
80
+ }
81
+ }
82
+
83
+ unregisterGCObj(res);
84
+ return res;
85
+ }
86
+
87
+ // HTTP Error (404) Handler - Redirects all requests to the root page
88
+ esp_err_t http_404_error_handler(httpd_req_t *req, httpd_err_code_t err)
89
+ {
90
+ // Set status
91
+ httpd_resp_set_status(req, "302 Temporary Redirect");
92
+ // Redirect to the "/" root directory
93
+ httpd_resp_set_hdr(req, "Location", "/");
94
+ // iOS requires content in the response to detect a captive portal, simply redirecting is not sufficient.
95
+ httpd_resp_send(req, "Redirect to the captive portal", HTTPD_RESP_USE_STRLEN);
96
+
97
+ ESP_LOGI(TAG, "Redirecting to root");
98
+ return ESP_OK;
99
+ }
100
+
101
+ /* URI handler structure for GET / */
102
+ httpd_uri_t login_get = {
103
+ .uri = "/",
104
+ .method = HTTP_GET,
105
+ .handler = login_handler,
106
+ .user_ctx = NULL
107
+ };
108
+
109
+ /* URI handler structure for POST /uri */
110
+ httpd_uri_t add_ap_get = {
111
+ .uri = "/add-ap",
112
+ .method = HTTP_GET,
113
+ .handler = add_ap_handler,
114
+ .user_ctx = NULL
115
+ };
116
+
117
+ /* Function for starting the webserver */
118
+ static void init(const char* hostName)
119
+ {
120
+ LOG("starting login server %s", hostName);
121
+ const char* ssid = hostName;
122
+
123
+ esp_netif_create_default_wifi_ap();
124
+
125
+ wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
126
+ ESP_ERROR_CHECK(esp_wifi_init(&cfg));
127
+
128
+ memcpy(wifi_config.ap.ssid, ssid, strlen(ssid));
129
+ wifi_config.ap.ssid_len = static_cast<uint8_t>(strlen(ssid));
130
+ wifi_config.ap.channel = 11;
131
+ wifi_config.ap.max_connection = 1;
132
+ wifi_config.ap.authmode = WIFI_AUTH_OPEN;
133
+
134
+ ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
135
+ ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
136
+ ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
137
+
138
+ /* Generate default configuration */
139
+ httpd_config_t config = HTTPD_DEFAULT_CONFIG();
140
+
141
+ /* Empty handle to esp_http_server */
142
+ httpd_handle_t server = NULL;
143
+
144
+ ESP_ERROR_CHECK(httpd_start(&server, &config));
145
+
146
+ httpd_register_uri_handler(server, &login_get);
147
+ httpd_register_uri_handler(server, &add_ap_get);
148
+ httpd_register_err_handler(server, HTTPD_404_NOT_FOUND, http_404_error_handler);
149
+
150
+ esp_netif_ip_info_t ip_info;
151
+ esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"), &ip_info);
152
+ LOG("SoftAP ip: " IPSTR, IP2STR(&ip_info.ip));
153
+
154
+ LOG("start mDNS service %s", hostName);
155
+ ESP_ERROR_CHECK(mdns_init());
156
+ ESP_ERROR_CHECK(mdns_hostname_set(hostName));
157
+ ESP_ERROR_CHECK(mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0));
158
+
159
+ _server = server;
160
+ }
161
+
162
+ void startHttpServer(const char* hostName) {
163
+ if (NULL == _server) {
164
+ init(hostName);
165
+ }
166
+ }
167
+
168
+ }
@@ -0,0 +1,37 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ html {
5
+ background: #aaa;
6
+ }
7
+ * {
8
+ font-size: xx-large;
9
+ font-family: monospace;
10
+ }
11
+ form {
12
+ min-height: 100vh;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ flex-direction: column;
17
+ gap: 0.5rem;
18
+ }
19
+ </style>
20
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
21
+ </head>
22
+ <body>
23
+ <form action="/add-ap">
24
+ <label for="ssid">WiFi:</label>
25
+ <input type="text" name="name" id="ssid" required autocomplete="username" />
26
+ <label for="password">Password:</label>
27
+ <input
28
+ type="password"
29
+ name="password"
30
+ id="password"
31
+ required
32
+ autocomplete="current-password"
33
+ />
34
+ <input id="submit" type="submit" value="connect" />
35
+ </form>
36
+ </body>
37
+ </html>
@@ -0,0 +1 @@
1
+ <style>html{background:#aaa}*{font-size:xx-large;font-family:monospace}form{min-height:100vh;display:flex;justify-content:center;align-items:center;flex-direction:column;gap:.5rem}</style><meta name='viewport'content='width=device-width,initial-scale=1'><form action='/add-ap'><label for='ssid'>WiFi:</label> <input name='name'id='ssid'required autocomplete='username'> <label for='password'>Password:</label> <input type='password'name='password'id='password'required autocomplete='current-password'> <input id='submit'type='submit'value='connect'></form>
@@ -7,6 +7,7 @@
7
7
  "enums.d.ts",
8
8
  "controller.ts",
9
9
  "wifi.h",
10
+ "httpserver.cpp",
10
11
  "socket.cpp",
11
12
  "wifi.cpp"
12
13
  ],
@@ -35,6 +35,10 @@ declare namespace _wifi {
35
35
  //% shim=_wifi::scanStart
36
36
  function scanStart(): void;
37
37
 
38
+ /** Starts an HTTP server with a login dialog route */
39
+ //% shim=_wifi::startLoginServer
40
+ function startLoginServer(hostName: string): void;
41
+
38
42
  /** Get the results of the scan if any. */
39
43
  //% shim=_wifi::scanResults
40
44
  function scanResults(): Buffer;
@@ -51,6 +55,10 @@ declare namespace _wifi {
51
55
  //% shim=_wifi::isConnected
52
56
  function isConnected(): boolean;
53
57
 
58
+ /** Check if login server is running */
59
+ //% shim=_wifi::isLoginServerEnabled
60
+ function isLoginServerEnabled(): boolean;
61
+
54
62
  /** Return ipv4 address, netmask, and gateway. */
55
63
  //% shim=_wifi::ipInfo
56
64
  function ipInfo(): Buffer;
@@ -248,6 +248,9 @@ namespace pxsim._wifi {
248
248
  _raiseEvent(WifiEvent.ScanDone)
249
249
  }
250
250
 
251
+ export function startLoginServer(): void {
252
+ }
253
+
251
254
  export function scanResults(): RefBuffer {
252
255
  const b = new Uint8Array(7)
253
256
  b[0] = -20 // rssi
@@ -1,5 +1,4 @@
1
1
  #include "wifi.h"
2
-
3
2
  #include "freertos/event_groups.h"
4
3
  #include "esp_wifi.h"
5
4
  #include "esp_netif.h"
@@ -12,22 +11,13 @@ void settings_init(void);
12
11
 
13
12
  namespace _wifi {
14
13
 
15
- enum class WifiEvent {
16
- //%
17
- ScanDone = 1,
18
- //%
19
- GotIP = 2,
20
- //%
21
- Disconnected = 3,
22
- };
23
-
24
14
  /** Get ID used in events. */
25
15
  //%
26
16
  int eventID() {
27
17
  return WIFI_ID;
28
18
  }
29
19
 
30
- static bool scan_done, is_connected;
20
+ static bool scan_done, is_connected, login_server;
31
21
  static esp_netif_ip_info_t ip_info;
32
22
 
33
23
  static void raiseWifiEvent(WifiEvent e) {
@@ -65,16 +55,17 @@ static void init() {
65
55
 
66
56
  settings_init();
67
57
 
58
+ ESP_ERROR_CHECK(esp_netif_init());
68
59
  ESP_ERROR_CHECK(esp_event_loop_create_default());
60
+
69
61
  wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
70
62
  ESP_ERROR_CHECK(esp_wifi_init(&cfg));
71
63
 
72
- esp_netif_init();
73
64
  esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_WIFI_STA();
74
65
  esp_netif_t *netif = esp_netif_new(&netif_config);
75
66
  assert(netif);
76
- esp_netif_attach_wifi_station(netif);
77
- esp_wifi_set_default_wifi_sta_handlers();
67
+ ESP_ERROR_CHECK(esp_netif_attach_wifi_station(netif));
68
+ ESP_ERROR_CHECK(esp_wifi_set_default_wifi_sta_handlers());
78
69
 
79
70
  ESP_ERROR_CHECK(
80
71
  esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_SCAN_DONE, &scan_done_handler, NULL));
@@ -84,8 +75,8 @@ static void init() {
84
75
  esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &got_ip_handler, NULL));
85
76
  ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
86
77
  ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
87
- // ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
88
78
  ESP_ERROR_CHECK(esp_wifi_start());
79
+
89
80
  initialized = true;
90
81
  }
91
82
 
@@ -93,6 +84,7 @@ static void init() {
93
84
  //%
94
85
  void scanStart() {
95
86
  init();
87
+
96
88
  scan_done = false;
97
89
  wifi_scan_config_t scan_config;
98
90
  memset(&scan_config, 0, sizeof(scan_config));
@@ -101,6 +93,17 @@ void scanStart() {
101
93
  LOG("scan start: %d", err);
102
94
  }
103
95
 
96
+ /** Starts an HTTP server with a login dialog route */
97
+ //%
98
+ void startLoginServer(String hostName) {
99
+ if (!login_server) {
100
+ login_server = true;
101
+ init();
102
+ _wifi::startHttpServer(hostName->getUTF8Data());
103
+ }
104
+ raiseWifiEvent(WifiEvent::LoginServerStarted);
105
+ }
106
+
104
107
  #define JD_WIFI_APFLAGS_HAS_PASSWORD 0x1
105
108
  #define JD_WIFI_APFLAGS_WPS 0x2
106
109
  #define JD_WIFI_APFLAGS_HAS_SECONDARY_CHANNEL_ABOVE 0x4
@@ -227,6 +230,12 @@ bool isConnected() {
227
230
  return is_connected;
228
231
  }
229
232
 
233
+ /** Check if login server is running */
234
+ //%
235
+ bool isLoginServerEnabled() {
236
+ return login_server;
237
+ }
238
+
230
239
  /** Return ipv4 address, netmask, and gateway. */
231
240
  //%
232
241
  Buffer ipInfo() {
@@ -8,5 +8,19 @@ namespace pxt {
8
8
  } // namespace pxt
9
9
 
10
10
  namespace _wifi {
11
- int eventID();
11
+ enum class WifiEvent {
12
+ //%
13
+ ScanDone = 1,
14
+ //%
15
+ GotIP = 2,
16
+ //%
17
+ Disconnected = 3,
18
+ //%
19
+ AccessPointCredentialsAvailable = 4,
20
+ //%
21
+ LoginServerStarted = 5,
22
+ };
23
+
24
+ int eventID();
25
+ void startHttpServer(const char* hostName);
12
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pxt-common-packages",
3
- "version": "9.4.7",
3
+ "version": "9.4.11",
4
4
  "description": "Microsoft MakeCode (PXT) common packages",
5
5
  "keywords": [
6
6
  "MakeCode",