/
jswrap_wifi.c
675 lines (581 loc) · 24.6 KB
/
jswrap_wifi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/*
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
*
* Copyright (C) 2017 Gordon Williams <gw@pur3.co.uk>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* ----------------------------------------------------------------------------
* This file is designed to be parsed during the build process
*
* Contains WiFi functions
* ----------------------------------------------------------------------------
*/
/*JSON{
"type": "library",
"class": "Wifi"
}
The Wifi library is designed to control the Wifi interface. It supports
functionality such as connecting to wifi networks, getting network information,
starting an access point, etc.
It is available on these devices:
* [Espruino WiFi](http://www.espruino.com/WiFi#using-wifi)
* [ESP8266](http://www.espruino.com/EspruinoESP8266)
* [ESP32](http://www.espruino.com/ESP32)
**Certain features may or may not be implemented on your device** however we
have documented what is available and what isn't.
If you're not using one of the devices above, a separate WiFi library is
provided. For instance:
* An [ESP8266 connected to an Espruino
board](http://www.espruino.com/ESP8266#software)
* An [CC3000 WiFi Module](http://www.espruino.com/CC3000)
[Other ways of connecting to the
net](http://www.espruino.com/Internet#related-pages) such as GSM, Ethernet and
LTE have their own libraries.
You can use the WiFi library as follows:
```
var wifi = require("Wifi");
wifi.connect("my-ssid", {password:"my-pwd"}, function(ap){ console.log("connected:", ap); });
```
On ESP32/ESP8266 if you want the connection to happen automatically at boot, add
`wifi.save();`. On other platforms, place `wifi.connect` in a function called
`onInit`.
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "associated",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'associated' event is called when an association with an access point has
succeeded, i.e., a connection to the AP's network has been established.
On ESP32/ESP8266 there is a `details` parameter which includes:
* ssid - The SSID of the access point to which the association was established
* mac - The BSSID/mac address of the access point
* channel - The wifi channel used (an integer, typ 1..14)
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "disconnected",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'disconnected' event is called when an association with an access point has
been lost.
On ESP32/ESP8266 there is a `details` parameter which includes:
* ssid - The SSID of the access point from which the association was lost
* mac - The BSSID/mac address of the access point
* reason - The reason for the disconnection (string)
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "auth_change",
"#if" : "defined(ESP32) || defined(ESP8266)",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'auth_change' event is called when the authentication mode with the
associated access point changes. The details include:
* oldMode - The old auth mode (string: open, wep, wpa, wpa2, wpa_wpa2)
* newMode - The new auth mode (string: open, wep, wpa, wpa2, wpa_wpa2)
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "dhcp_timeout",
"#if" : "defined(ESP32) || defined(ESP8266)"
}
The 'dhcp_timeout' event is called when a DHCP request to the connected access
point fails and thus no IP address could be acquired (or renewed).
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "connected",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'connected' event is called when the connection with an access point is
ready for traffic. In the case of a dynamic IP address configuration this is
when an IP address is obtained, in the case of static IP address allocation this
happens when an association is formed (in that case the 'associated' and
'connected' events are fired in rapid succession).
On ESP32/ESP8266 there is a `details` parameter which includes:
* ip - The IP address obtained as string
* netmask - The network's IP range mask as string
* gw - The network's default gateway as string
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "sta_joined",
"#if" : "defined(ESP32) || defined(ESP8266)",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'sta_joined' event is called when a station establishes an association (i.e.
connects) with the esp8266's access point. The details include:
* mac - The MAC address of the station in string format (00:00:00:00:00:00)
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "sta_left",
"#if" : "defined(ESP32) || defined(ESP8266)",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'sta_left' event is called when a station disconnects from the esp8266's
access point (or its association times out?). The details include:
* mac - The MAC address of the station in string format (00:00:00:00:00:00)
*/
/*JSON{
"type" : "event",
"class" : "Wifi",
"name" : "probe_recv",
"#if" : "defined(ESP32) || defined(ESP8266)",
"params" : [
["details","JsVar","An object with event details"]
]
}
The 'probe_recv' event is called when a probe request is received from some
station by the esp8266's access point. The details include:
* mac - The MAC address of the station in string format (00:00:00:00:00:00)
* rssi - The signal strength in dB of the probe request
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "disconnect",
"generate" : "jswrap_wifi_disconnect",
"params" : [
["callback", "JsVar", "[optional] An `callback()` function to be called back on disconnection. The callback function receives no argument."]
]
}
Disconnect the wifi station from an access point and disable the station mode.
It is OK to call `disconnect` to turn off station mode even if no connection
exists (for example, connection attempts may be failing). Station mode can be
re-enabled by calling `connect` or `scan`.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "stopAP",
"generate" : "jswrap_wifi_stopAP",
"params" : [
["callback", "JsVar", "[optional] An `callback()` function to be called back on successful stop. The callback function receives no argument."]
]
}
Stop being an access point and disable the AP operation mode. AP mode can be
re-enabled by calling `startAP`.
*/
// TODO TypeScript: Is authMode an option?
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "connect",
"generate" : "jswrap_wifi_connect",
"params" : [
["ssid", "JsVar", "The access point network id."],
["options", "JsVar", "[optional] Connection options."],
["callback", "JsVar", "A `callback(err)` function to be called back on completion. `err` is null on success, or contains an error string on failure."]
],
"typescript" : "function connect(ssid: string, options?: { password?: string, dnsServers?: string[], authMode?: string, channel?: number, bssid?: string }, callback?: (err: string | null) => void): void;"
}
Connect to an access point as a station. If there is an existing connection to
an AP it is first disconnected if the SSID or password are different from those
passed as parameters. Put differently, if the passed SSID and password are
identical to the currently connected AP then nothing is changed. When the
connection attempt completes the callback function is invoked with one `err`
parameter, which is NULL if there is no error and a string message if there is
an error. If DHCP is enabled the callback occurs once an IP address has been
obtained, if a static IP is set the callback occurs once the AP's network has
been joined. The callback is also invoked if a connection already exists and
does not need to be changed.
The options properties may contain:
* `password` - Password string to be used to access the network.
* `dnsServers` (array of String) - An array of up to two DNS servers in dotted
decimal format string.
* `channel` - Wifi channel of the access point (integer, typ 0..14, 0 means any
channel), only on ESP8266.
* `bssid` - Mac address of the access point (string, type "00:00:00:00:00:00"),
only on ESP8266.
Notes:
* the options should include the ability to set a static IP and associated
netmask and gateway, this is a future enhancement.
* the only error reported in the callback is "Bad password", all other errors
(such as access point not found or DHCP timeout) just cause connection
retries. If the reporting of such temporary errors is desired, the caller must
use its own timeout and the `getDetails().status` field.
* the `connect` call automatically enabled station mode, it can be disabled
again by calling `disconnect`.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "scan",
"generate" : "jswrap_wifi_scan",
"params" : [
["callback", "JsVar", "A `callback(err, ap_list)` function to be called back on completion. `err==null` and `ap_list` is an array on success, or `err` is an error string and `ap_list` is undefined on failure."]
]
}
Perform a scan for access points. This will enable the station mode if it is not
currently enabled. Once the scan is complete the callback function is called
with an array of APs found, each AP is an object with:
* `ssid`: SSID string.
* `mac`: access point MAC address in 00:00:00:00:00:00 format.
* `authMode`: `open`, `wep`, `wpa`, `wpa2`, or `wpa_wpa2`.
* `channel`: wifi channel 1..13.
* `hidden`: true if the SSID is hidden (ESP32/ESP8266 only)
* `rssi`: signal strength in dB in the range -110..0.
Notes:
* in order to perform the scan the station mode is turned on and remains on, use
Wifi.disconnect() to turn it off again, if desired.
* only one scan can be in progress at a time.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "startAP",
"generate" : "jswrap_wifi_startAP",
"params" : [
["ssid", "JsVar", "The network id."],
["options", "JsVar", "[optional] Configuration options."],
["callback", "JsVar", "Optional `callback(err)` function to be called when the AP is successfully started. `err==null` on success, or an error string on failure."]
],
"typescript" : "function startAP(ssid: string, options?: { password?: string, authMode?: \"open\" | \"wpa2\" | \"wpa\" | \"wpa_wpa2\", channel?: number, hidden?: boolean }, callback?: (err: string | null) => void): void;"
}
Create a WiFi access point allowing stations to connect. If the password is NULL
or an empty string the access point is open, otherwise it is encrypted. The
callback function is invoked once the access point is set-up and receives one
`err` argument, which is NULL on success and contains an error message string
otherwise.
The `options` object can contain the following properties.
* `authMode` - The authentication mode to use. Can be one of "open", "wpa2",
"wpa", "wpa_wpa2". The default is open (but open access points are not
recommended).
* `password` - The password for connecting stations if authMode is not open.
* `channel` - The channel to be used for the access point in the range 1..13. If
the device is also connected to an access point as a station then that access
point determines the channel.
* `hidden` - The flag if visible or not (0:visible, 1:hidden), default is
visible.
Notes:
* the options should include the ability to set the AP IP and associated
netmask, this is a future enhancement.
* the `startAP` call automatically enables AP mode. It can be disabled again by
calling `stopAP`.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getStatus",
"generate" : "jswrap_wifi_getStatus",
"#if" : "defined(ESP32) || defined(ESP8266)",
"return" : ["JsVar", "An object representing the current WiFi status, if available immediately."],
"params" : [
["callback", "JsVar", "Optional `callback(status)` function to be called back with the current Wifi status, i.e. the same object as returned directly."]
]
}
Retrieve the current overall WiFi configuration. This call provides general
information that pertains to both station and access point modes. The getDetails
and getAPDetails calls provide more in-depth information about the station and
access point configurations, respectively. The status object has the following
properties:
* `station` - Status of the wifi station: `off`, `connecting`, ...
* `ap` - Status of the wifi access point: `disabled`, `enabled`.
* `mode` - The current operation mode: `off`, `sta`, `ap`, `sta+ap`.
* `phy` - Modulation standard configured: `11b`, `11g`, `11n` (the esp8266 docs
are not very clear, but it is assumed that 11n means b/g/n). This setting
limits the modulations that the radio will use, it does not indicate the
current modulation used with a specific access point.
* `powersave` - Power saving mode: `none` (radio is on all the time), `ps-poll`
(radio is off between beacons as determined by the access point's DTIM
setting). Note that in 'ap' and 'sta+ap' modes the radio is always on, i.e.,
no power saving is possible.
* `savedMode` - The saved operation mode which will be applied at boot time:
`off`, `sta`, `ap`, `sta+ap`.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "setConfig",
"generate" : "jswrap_wifi_setConfig",
"#if" : "defined(ESP32) || defined(ESP8266)",
"params" : [
["settings", "JsVar", "An object with the configuration settings to change."]
]
}
Sets a number of global wifi configuration settings. All parameters are optional
and which are passed determines which settings are updated. The settings
available are:
* `phy` - Modulation standard to allow: `11b`, `11g`, `11n` (the esp8266 docs
are not very clear, but it is assumed that 11n means b/g/n).
* `powersave` - Power saving mode: `none` (radio is on all the time), `ps-poll`
(radio is off between beacons as determined by the access point's DTIM
setting). Note that in 'ap' and 'sta+ap' modes the radio is always on, i.e.,
no power saving is possible.
Note: esp8266 SDK programmers may be missing an "opmode" option to set the
sta/ap/sta+ap operation mode. Please use connect/scan/disconnect/startAP/stopAP,
which all set the esp8266 opmode indirectly.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getDetails",
"generate" : "jswrap_wifi_getDetails",
"#if" : "defined(ESP32) || defined(ESP8266)",
"return" : ["JsVar", "An object representing the wifi station details, if available immediately."],
"params" : [
["callback", "JsVar", "[optional] An `callback(details)` function to be called back with the wifi details, i.e. the same object as returned directly."]
]
}
Retrieve the wifi station configuration and status details. The details object
has the following properties:
* `status` - Details about the wifi station connection, one of `off`,
`connecting`, `wrong_password`, `no_ap_found`, `connect_fail`, or `connected`.
The off, bad_password and connected states are stable, the other states are
transient. The connecting state will either result in connected or one of the
error states (bad_password, no_ap_found, connect_fail) and the no_ap_found and
connect_fail states will result in a reconnection attempt after some interval.
* `rssi` - signal strength of the connected access point in dB, typically in the
range -110 to 0, with anything greater than -30 being an excessively strong
signal.
* `ssid` - SSID of the access point.
* `password` - the password used to connect to the access point.
* `authMode` - the authentication used: `open`, `wpa`, `wpa2`, `wpa_wpa2` (not
currently supported).
* `savedSsid` - the SSID to connect to automatically at boot time, null if none.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getAPDetails",
"generate" : "jswrap_wifi_getAPDetails",
"#if" : "defined(ESP32) || defined(ESP8266)",
"return" : ["JsVar", "An object representing the current access point details, if available immediately."],
"params" : [
["callback", "JsVar", "[optional] A `callback(details)` function to be called back with the current access point details, i.e. the same object as returned directly."]
]
}
Retrieve the current access point configuration and status. The details object
has the following properties:
* `status` - Current access point status: `enabled` or `disabled`
* `stations` - an array of the stations connected to the access point. This
array may be empty. Each entry in the array is an object describing the
station which, at a minimum contains `ip` being the IP address of the station.
* `ssid` - SSID to broadcast.
* `password` - Password for authentication.
* `authMode` - the authentication required of stations: `open`, `wpa`, `wpa2`,
`wpa_wpa2`.
* `hidden` - True if the SSID is hidden, false otherwise.
* `maxConn` - Max number of station connections supported.
* `savedSsid` - the SSID to broadcast automatically at boot time, null if the
access point is to be disabled at boot.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "save",
"generate" : "jswrap_wifi_save",
"#if" : "defined(ESP32) || defined(ESP8266)",
"params" : [
["what", "JsVar", "An optional parameter to specify what to save, on the esp8266 the two supported values are `clear` and `sta+ap`. The default is `sta+ap`"]
]
}
On boards where this is not available, just issue the `connect` commands you
need to run at startup from an `onInit` function.
Save the current wifi configuration (station and access point) to flash and
automatically apply this configuration at boot time, unless `what=="clear"`, in
which case the saved configuration is cleared such that wifi remains disabled at
boot. The saved configuration includes:
* mode (off/sta/ap/sta+ap)
* SSIDs & passwords
* phy (11b/g/n)
* powersave setting
* DHCP hostname
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "restore",
"generate" : "jswrap_wifi_restore",
"#if" : "defined(ESP32) || defined(ESP8266)"
}
Restores the saved Wifi configuration from flash. See `Wifi.save()`.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getIP",
"generate" : "jswrap_wifi_getIP",
"return" : ["JsVar", "An object representing the station IP information, if available immediately (**ONLY** on ESP8266/ESP32)."],
"params" : [
["callback", "JsVar", "[optional] A `callback(err, ipinfo)` function to be called back with the IP information."]
]
}
Return the station IP information in an object as follows:
* ip - IP address as string (e.g. "192.168.1.5")
* netmask - The interface netmask as string (ESP8266/ESP32 only)
* gw - The network gateway as string (ESP8266/ESP32 only)
* mac - The MAC address as string of the form 00:00:00:00:00:00
Note that the `ip`, `netmask`, and `gw` fields are omitted if no connection is established:
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getAPIP",
"generate" : "jswrap_wifi_getAPIP",
"return" : ["JsVar", "An object representing the esp8266's Access Point IP information, if available immediately (**ONLY** on ESP8266/ESP32)."],
"params" : [
["callback", "JsVar", "[optional] A `callback(err, ipinfo)` function to be called back with the the IP information."]
]
}
Return the access point IP information in an object which contains:
* ip - IP address as string (typ "192.168.4.1")
* netmask - The interface netmask as string
* gw - The network gateway as string
* mac - The MAC address as string of the form 00:00:00:00:00:00
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getHostByName",
"generate" : "jswrap_wifi_getHostByName",
"#if" : "defined(ESP8266) || defined(ESP32)",
"params" : [
["hostname", "JsVar", "The hostname to lookup."],
["callback", "JsVar", "The `callback(ip)` to invoke when the IP is returned. `ip==null` on failure."]
]
}
Lookup the hostname and invoke a callback with the IP address as integer
argument. If the lookup fails, the callback is invoked with a null argument.
**Note:** only a single hostname lookup can be made at a time, concurrent
lookups are not supported.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "getHostname",
"generate" : "jswrap_wifi_getHostname",
"#if" : "defined(ESP8266) || defined(ESP32)",
"return" : ["JsVar", "The currently configured hostname, if available immediately."],
"params" : [
["callback", "JsVar", "[optional] A `callback(hostname)` function to be called back with the hostname."]
]
}
Returns the hostname announced to the DHCP server and broadcast via mDNS when
connecting to an access point.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "setHostname",
"generate" : "jswrap_wifi_setHostname",
"#if" : "defined(ESP8266) || defined(ESPRUINOWIFI) || defined(ESP32)",
"params" : [
["hostname", "JsVar", "The new hostname."],
["callback", "JsVar", "[optional] A `callback()` function to be called back when the hostname is set"]
]
}
Set the hostname. Depending on implementation, the hostname is sent with every
DHCP request and is broadcast via mDNS. The DHCP hostname may be visible in the
access point and may be forwarded into DNS as hostname.local. If a DHCP lease
currently exists changing the hostname will cause a disconnect and reconnect in
order to transmit the change to the DHCP server. The mDNS announcement also
includes an announcement for the "espruino" service.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "setSNTP",
"generate" : "jswrap_wifi_setSNTP",
"#if" : "defined(ESP8266) || defined(ESP32)",
"params" : [
["server", "JsVar", "The NTP server to query, for example, `us.pool.ntp.org`"],
["tz_offset", "JsVar", "Local time zone offset in the range -11..13."]
]
}
Starts the SNTP (Simple Network Time Protocol) service to keep the clock
synchronized with the specified server. Note that the time zone is really just
an offset to UTC and doesn't handle daylight savings time. The interval
determines how often the time server is queried and Espruino's time is
synchronized. The initial synchronization occurs asynchronously after setSNTP
returns.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "setIP",
"generate" : "jswrap_wifi_setIP",
"#if" : "defined(ESP8266) || defined(ESPRUINOWIFI)",
"params" : [
["settings", "JsVar", "Configuration settings"],
["callback", "JsVar", "A `callback(err)` function to invoke when ip is set. `err==null` on success, or a string on failure."]
]
}
The `settings` object must contain the following properties.
* `ip` IP address as string (e.g. "192.168.5.100")
* `gw` The network gateway as string (e.g. "192.168.5.1")
* `netmask` The interface netmask as string (e.g. "255.255.255.0")
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "setAPIP",
"#if" : "defined(ESPRUINOWIFI) || defined(ESP8266)",
"generate" : "jswrap_wifi_setAPIP",
"params" : [
["settings", "JsVar", "Configuration settings"],
["callback", "JsVar", "A `callback(err)` function to invoke when ip is set. `err==null` on success, or a string on failure."]
]
}
The `settings` object must contain the following properties.
* `ip` IP address as string (e.g. "192.168.5.100")
* `gw` The network gateway as string (e.g. "192.168.5.1")
* `netmask` The interface netmask as string (e.g. "255.255.255.0")
*/
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "ping",
"#if" : "defined(ESPRUINOWIFI) || defined(ESP8266) || defined(ESP32)",
"generate" : "jswrap_wifi_ping",
"params" : [
["hostname", "JsVar", "The host to ping"],
["callback", "JsVar", "A `callback(time)` function to invoke when a ping is received"]
]
}
Issues a ping to the given host, and calls a callback with the time when the
ping is received.
*/
/*JSON{
"type" : "staticmethod",
"class" : "Wifi",
"name" : "turbo",
"#if" : "defined(ESPRUINOWIFI)",
"generate_full" : "",
"params" : [
["enable", "JsVar", "true (or a baud rate as a number) to enable, false to disable"],
["callback", "JsVar", "A `callback()` function to invoke when turbo mode has been set"]
]
}
Switch to using a higher communication speed with the WiFi module.
* `true` = 921600 baud
* `false` = 115200
* `1843200` (or any number) = use a specific baud rate. * e.g.
`wifi.turbo(true,callback)` or `wifi.turbo(1843200,callback)`
*/