mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Add better docs for the form of Wifi callback functions
Modify ESP8266/ESP32 callbacks to match the node.js style used elsewhere
This commit is contained in:
parent
08dabc3204
commit
eaef9c1440
@ -1,4 +1,6 @@
|
||||
Allow Crypto SHA1 without SHA256/512 (for Original & ESP8266 where flash is scarce)
|
||||
Add better docs for the form of Wifi callback functions
|
||||
Modify ESP8266/ESP32 callbacks to match the node.js style used elsewhere
|
||||
|
||||
1v97 : nRF52: fix NRF.on('connect',...) issue
|
||||
STM32: Fix setDeviceClockCmd error for USB.setConsole()
|
||||
|
||||
24
libs/js/espruino_wifi/Wifi.min.js
vendored
24
libs/js/espruino_wifi/Wifi.min.js
vendored
@ -1,15 +1,15 @@
|
||||
function z(a){return{ip:a.charCodeAt(0)+"."+a.charCodeAt(1)+"."+a.charCodeAt(2)+"."+a.charCodeAt(3),port:a.charCodeAt(5)<<8|a.charCodeAt(4),len:a.charCodeAt(7)<<8|a.charCodeAt(6)}}function D(a){var b=a.indexOf(":");if(0>b)return a;var d=a.substring(5,b).split(",");d[1]|=0;var c=a.length-(b+1),e=d[0];if(v[e]){var m=(d[2]||"0.0.0.0").split(".").map(function(a){return 0|a}),A=0|d[3];g[e]+=String.fromCharCode(m[0],m[1],m[2],m[3],A&255,A>>8,c&255,c>>8)}if(c>=d[1])return g[e]+=a.substr(b+1,
|
||||
d[1]),a.substr(b+d[1]+1);g[e]+=a.substr(b+1,c);f.getData(d[1]-c,function(a){g[e]+=a});return""}function w(a,b){if(b)return a(b);f.cmd("AT+CWMODE="+p+"\r\n",1E3,function(b){"no change"!=b&&"OK"!=b&&"WIFI DISCONNECT"!=b?a("CWMODE failed: "+(b?b:"Timeout")):a(null)})}function q(a){var b=a[0];void 0===e[b]&&e[5]?e[b]="Accept":"Wait"==e[b]?e[b]=!0:f.cmd("AT+CIPCLOSE="+b+"\r\n",1E3,function(a){e[b]=void 0})}function r(a){e[a[0]]=""!=g[a[0]]?"DataClose":void 0}function u(a,b){var d=0==p;p|=a;d?("1v91"==
|
||||
function z(a){return{ip:a.charCodeAt(0)+"."+a.charCodeAt(1)+"."+a.charCodeAt(2)+"."+a.charCodeAt(3),port:a.charCodeAt(5)<<8|a.charCodeAt(4),len:a.charCodeAt(7)<<8|a.charCodeAt(6)}}function D(a){var b=a.indexOf(":");if(0>b)return a;var c=a.substring(5,b).split(",");c[1]|=0;var d=a.length-(b+1),e=c[0];if(v[e]){var m=(c[2]||"0.0.0.0").split(".").map(function(a){return 0|a}),A=0|c[3];g[e]+=String.fromCharCode(m[0],m[1],m[2],m[3],A&255,A>>8,d&255,d>>8)}if(d>=c[1])return g[e]+=a.substr(b+1,
|
||||
c[1]),a.substr(b+c[1]+1);g[e]+=a.substr(b+1,d);f.getData(c[1]-d,function(a){g[e]+=a});return""}function w(a,b){if(b)return a(b);f.cmd("AT+CWMODE="+p+"\r\n",1E3,function(b){"no change"!=b&&"OK"!=b&&"WIFI DISCONNECT"!=b?a("CWMODE failed: "+(b?b:"Timeout")):a(null)})}function q(a){var b=a[0];void 0===e[b]&&e[5]?e[b]="Accept":"Wait"==e[b]?e[b]=!0:f.cmd("AT+CIPCLOSE="+b+"\r\n",1E3,function(a){e[b]=void 0})}function r(a){e[a[0]]=""!=g[a[0]]?"DataClose":void 0}function u(a,b){var c=0==p;p|=a;c?("1v91"==
|
||||
process.version?(x.reset(),t.setup(115200,{rx:A3,tx:A2})):t.setup(115200,{rx:A3,tx:A2,cts:x}),f=require("AT").connect(t),f.register("+IPD",D),f.registerLine("0,CONNECT",q),f.registerLine("1,CONNECT",q),f.registerLine("2,CONNECT",q),f.registerLine("3,CONNECT",q),f.registerLine("4,CONNECT",q),f.registerLine("0,CLOSED",r),f.registerLine("1,CLOSED",r),f.registerLine("2,CLOSED",r),f.registerLine("3,CLOSED",r),f.registerLine("4,CLOSED",r),f.registerLine("WIFI CONNECTED",function(){n|=k.CLIENT;exports.emit("associated")}),
|
||||
f.registerLine("WIFI GOT IP",function(){exports.emit("connected")}),f.registerLine("WIFI DISCONNECTED",function(){n&=~k.CLIENT;exports.emit("disconnected")}),exports.at=f,require("NetworkJS").create(B),f.cmd("\r\nAT+RST\r\n",1E4,function m(a){if("ready"==a||"Ready."==a)setTimeout(function(){f.cmd("ATE0\r\n",1E3,function F(a){if("ATE0"==a)return F;"OK"==a?f.cmd("AT+CIPDINFO=1\r\n",1E3,function(a){if("OK"!=a)return b("CIPDINFO failed: "+(a?a:"Timeout"));f.cmd("AT+CIPMUX=1\r\n",1E3,function(a){if("OK"!=
|
||||
a)return b("CIPMUX failed: "+(a?a:"Timeout"));f.cmd("AT+UART_CUR=115200,8,1,0,2\r\n",500,function(a){if("OK"!=a)return b("UART_CUR failed: "+(a?a:"Timeout"));w(b)})})}):b("ATE0 failed: "+(a?a:"Timeout"))})},500);else if(void 0===a)b("No 'ready' after AT+RST");else return m}),digitalWrite(G,1),digitalWrite(y,1)):w(b)}function C(a,b){b=b||function(){};(p&=~a)?w(b,null):(t.removeAllListeners(),f=void 0,exports.at=void 0,digitalWrite(y,0),e=[],setTimeout(b,1))}var G=A13,y=A14,x=A15,t=Serial2;digitalWrite(y,
|
||||
0);var k={CLIENT:1,AP:2},H=["open","wep","wpa_psk","wpa2_psk","wpa_wpa2_psk"],p=0,n=0,f,e=[],v=[],g=["","","","",""],B={create:function(a,b,d){if(!f||!n)return-1;if(void 0===a&&2!=d)return c=5,e[c]="Wait",g[c]="",f.cmd("AT+CIPSERVER=1,"+b+"\r\n",1E4,function(a){"OK"==a?e[c]=!0:(e[c]=void 0,setTimeout(function(){throw Error("CIPSERVER failed ("+(a?a:"Timeout")+")");},0))}),5;for(var c=0;void 0!==e[c];)c++;if(5<=c)return-7;g[c]="";e[c]="Wait";var h;2==d?(b?h="AT+CIPSTART="+c+',"UDP","255.255.255.255",'+
|
||||
b+","+b+",2\r\n":e[c]="UDP",v[c]=!0):(h="AT+CIPSTART="+c+',"TCP",'+JSON.stringify(a)+","+b+"\r\n",delete v[c]);h&&f.cmd(h,1E4,function l(a){if("ALREADY CONNECTED"==a)return l;if("OK"!=a||!0!==e[c])e[c]=-6});return c},close:function(a){"Wait"==e[a]?e[a]="WaitClose":void 0!==e[a]&&(0>e[a]||"UDP"==e[a]?e[a]=void 0:f.cmd((5==a?"AT+CIPSERVER=0":"AT+CIPCLOSE="+a)+"\r\n",1E3,function(b){e[a]=void 0}))},accept:function(a){for(a=0;5>a;a++)if("Accept"==e[a])return e[a]=!0,a;return-1},recv:function(a,b,d){return g[a]?
|
||||
(g[a].length>b?(d=g[a].substr(0,b),g[a]=g[a].substr(b)):(d=g[a],g[a]="","DataClose"==e[a]&&(e[a]=void 0)),d):0>e[a]?e[a]:e[a]?"":-1},send:function(a,b,d){if(!f)return-1;if(f.isBusy()||"Wait"==e[a])return 0;if(0>e[a])return e[a];if(!e[a])return-1;if("UDP"==e[a])return d=z(b),e[a]="Wait",f.cmd("AT+CIPSTART="+a+',"UDP","'+d.ip+'",'+d.port+","+d.port+",2\r\n",1E4,function(b){"OK"!=b&&(e[a]=-6)}),0;var c=b.length,h="";2==d&&(d=z(b),h=',"'+d.ip+'",'+d.port,b=b.substr(8,d.len),c=8+d.len);f.cmd("AT+CIPSEND="+
|
||||
a+","+b.length+h+"\r\n",1E4,function l(c){if("OK"==c)return f.register("> ",function(){f.unregister("> ");f.write(b);return""}),l;if(c=="Recv "+b.length+" bytes"||"busy s..."==c)return l;"SEND OK"==c?("WaitClose"==e[a]&&B.close(a),e[a]=!0):(e[a]=void 0,f.unregister("> "))});e[a]="Wait";return c}};exports.connect=function(a,b,d){var c="";d=d||function(){};void 0!==b.password&&(c=b.password);u(k.CLIENT,function(b){if(b)return d(b);f.cmd("AT+CWJAP="+JSON.stringify(a)+","+JSON.stringify(c)+"\r\n",2E4,
|
||||
function l(a){if(0<=["WIFI DISCONNECT","WIFI CONNECTED","WIFI GOT IP","+CWJAP:1"].indexOf(a))return l;"OK"!=a?setTimeout(d,0,"WiFi connect failed: "+(a?a:"Timeout")):setTimeout(d,0,null)})})};exports.disconnect=function(a){C(k.CLIENT,a)};exports.startAP=function(a,b,d){b=b||{};if(!b.password||8>b.password.length)throw Error("Password must be at least 8 characters");var c=b.password?"3":"0";if(b.authMode&&(c={open:0,wpa:2,wpa2:3,wpa_wpa2:4}[b.authMode],void 0===c))throw Error("Unknown authMode "+b.authMode);
|
||||
void 0===b.channel&&(b.channel=5);u(k.AP,function(e){if(e)return d(e);f.cmd("AT+CWSAP="+JSON.stringify(a)+","+JSON.stringify(b.password)+","+b.channel+","+c+"\r\n",5E3,function(a){"OK"!=a?d("CWSAP failed: "+(a?a:"Timeout")):(n|=k.AP,d(null))})})};exports.stopAP=function(a){n&=~k.AP;C(k.AP,a)};exports.scan=function(a){var b=[];u(k.CLIENT,function(d){if(d)return a(d);f.cmdReg("AT+CWLAP\r\n",5E3,"+CWLAP:",function(a){a=a.slice(8,-1).split(",");b.push({ssid:JSON.parse(a[1]),authMode:H[a[0]],rssi:parseInt(a[2]),
|
||||
mac:JSON.parse(a[3]),channel:JSON.parse(a[4])})},function(c){a(null,b)})})};exports.getIP=function(a){var b={};f.cmd("AT+CIFSR\r\n",1E3,function h(c){if(void 0===c)a("Timeout");else{if("+CIFSR:STAIP"==c.substr(0,12))b.ip=c.slice(14,-1);else if("+CIFSR:STAMAC"==c.substr(0,13))b.mac=c.slice(15,-1);else if("OK"==c){a(null,b);return}return h}})};exports.setIP=function(a,b){if("object"==typeof a&&a.ip){var d=[JSON.stringify(a.ip)];a.gw&&(d.push(JSON.stringify(a.gw)),d.push(JSON.stringify(a.netmask||"255.255.255.0")));
|
||||
d="AT+CIPSTA_CUR="+d.join(",")+"\r\n";var c=3E3}else d="AT+CWDHCP_CUR=1,1\r\n",c=2E4;f.cmd(d,c,function(a){if("OK"==a)b(null);else return b("setIP failed: "+(a?a:"Timeout"))})};exports.getAPIP=function(a){var b={};f.cmd("AT+CIPAP_CUR?\r\n",1E3,function h(c){if(void 0===c)a("Timeout");else if("OK"==c)f.cmd("AT+CIPAPMAC_CUR?\r\n",1E3,function l(c){if(void 0===c)a("Timeout");else if("OK"==c)a(null,b);else return"+CIPAPMAC_CUR"==c.substr(0,14)&&(b.mac=JSON.parse(c.substr(10))),l});else return"+CIPAP_CUR"==
|
||||
c.substr(0,10)&&(c=c.split(":"),"gateway"==c[1]&&"gw"==c[1],b[c[1]]=JSON.parse(c[2])),h})};exports.setAPIP=function(a,b){var d=[JSON.stringify(a.ip)];a.gw&&(d.push(JSON.stringify(a.gw)),d.push(JSON.stringify(a.netmask||"255.255.255.0")));f.cmd("AT+CIPAP_CUR="+d.join(",")+"\r\n",3E3,function(a){if("OK"==a)b(null);else return b("setAPIP failed: "+(a?a:"Timeout"))})};exports.setHostname=function(a,b){u(k.CLIENT,function(d){if(d)return b(d);f.cmd("AT+CWHOSTNAME="+JSON.stringify(a)+"\r\n",500,b)})};exports.ping=
|
||||
function(a,b){var d;f.cmd('AT+PING="'+a+'"\r\n',1E3,function m(a){if(a&&"+"==a[0])return d=a.substr(1),m;"OK"==a?b(d):b()})};exports.turbo=function(a,b){var d=a?!0===a?921600:a:115200;f.cmd("AT+UART_CUR="+d+",8,1,0,2\r\n",500,function(a){"OK"!=a?b&&b("Baud rate switch to "+d+" failed: "+(a?a:"Timeout")):(t.setup(d,{rx:A3,tx:A2,cts:x}),b&&b(null))})};exports.debug=function(){return{wifiMode:p,connected:n,socks:e,sockData:g}}
|
||||
0);var k={CLIENT:1,AP:2},H=["open","wep","wpa_psk","wpa2_psk","wpa_wpa2_psk"],p=0,n=0,f,e=[],v=[],g=["","","","",""],B={create:function(a,b,c){if(!f||!n)return-1;if(void 0===a&&2!=c)return d=5,e[d]="Wait",g[d]="",f.cmd("AT+CIPSERVER=1,"+b+"\r\n",1E4,function(a){"OK"==a?e[d]=!0:(e[d]=void 0,setTimeout(function(){throw Error("CIPSERVER failed ("+(a?a:"Timeout")+")");},0))}),5;for(var d=0;void 0!==e[d];)d++;if(5<=d)return-7;g[d]="";e[d]="Wait";var h;2==c?(b?h="AT+CIPSTART="+d+',"UDP","255.255.255.255",'+
|
||||
b+","+b+",2\r\n":e[d]="UDP",v[d]=!0):(h="AT+CIPSTART="+d+',"TCP",'+JSON.stringify(a)+","+b+"\r\n",delete v[d]);h&&f.cmd(h,1E4,function l(a){if("ALREADY CONNECTED"==a)return l;if("OK"!=a||!0!==e[d])e[d]=-6});return d},close:function(a){"Wait"==e[a]?e[a]="WaitClose":void 0!==e[a]&&(0>e[a]||"UDP"==e[a]?e[a]=void 0:f.cmd((5==a?"AT+CIPSERVER=0":"AT+CIPCLOSE="+a)+"\r\n",1E3,function(b){e[a]=void 0}))},accept:function(a){for(a=0;5>a;a++)if("Accept"==e[a])return e[a]=!0,a;return-1},recv:function(a,b,c){return g[a]?
|
||||
(g[a].length>b?(c=g[a].substr(0,b),g[a]=g[a].substr(b)):(c=g[a],g[a]="","DataClose"==e[a]&&(e[a]=void 0)),c):0>e[a]?e[a]:e[a]?"":-1},send:function(a,b,c){if(!f)return-1;if(f.isBusy()||"Wait"==e[a])return 0;if(0>e[a])return e[a];if(!e[a])return-1;if("UDP"==e[a])return c=z(b),e[a]="Wait",f.cmd("AT+CIPSTART="+a+',"UDP","'+c.ip+'",'+c.port+","+c.port+",2\r\n",1E4,function(b){"OK"!=b&&(e[a]=-6)}),0;var d=b.length,h="";2==c&&(c=z(b),h=',"'+c.ip+'",'+c.port,b=b.substr(8,c.len),d=8+c.len);f.cmd("AT+CIPSEND="+
|
||||
a+","+b.length+h+"\r\n",1E4,function l(d){if("OK"==d)return f.register("> ",function(){f.unregister("> ");f.write(b);return""}),l;if(d=="Recv "+b.length+" bytes"||"busy s..."==d)return l;"SEND OK"==d?("WaitClose"==e[a]&&B.close(a),e[a]=!0):(e[a]=void 0,f.unregister("> "))});e[a]="Wait";return d}};exports.connect=function(a,b,c){var d="";c=c||function(){};void 0!==b.password&&(d=b.password);u(k.CLIENT,function(b){if(b)return c(b);f.cmd("AT+CWJAP="+JSON.stringify(a)+","+JSON.stringify(d)+"\r\n",2E4,
|
||||
function l(a){if(0<=["WIFI DISCONNECT","WIFI CONNECTED","WIFI GOT IP","+CWJAP:1"].indexOf(a))return l;"OK"!=a?setTimeout(c,0,"WiFi connect failed: "+(a?a:"Timeout")):setTimeout(c,0,null)})})};exports.disconnect=function(a){C(k.CLIENT,a)};exports.startAP=function(a,b,c){c=c||function(){};b=b||{};if(!b.password||8>b.password.length)throw Error("Password must be at least 8 characters");var d=b.password?"3":"0";if(b.authMode&&(d={open:0,wpa:2,wpa2:3,wpa_wpa2:4}[b.authMode],void 0===d))throw Error("Unknown authMode "+
|
||||
b.authMode);void 0===b.channel&&(b.channel=5);u(k.AP,function(e){if(e)return c(e);f.cmd("AT+CWSAP="+JSON.stringify(a)+","+JSON.stringify(b.password)+","+b.channel+","+d+"\r\n",5E3,function(a){"OK"!=a?c("CWSAP failed: "+(a?a:"Timeout")):(n|=k.AP,c(null))})})};exports.stopAP=function(a){n&=~k.AP;C(k.AP,a)};exports.scan=function(a){var b=[];u(k.CLIENT,function(c){if(c)return a(c);f.cmdReg("AT+CWLAP\r\n",5E3,"+CWLAP:",function(a){a=a.slice(8,-1).split(",");b.push({ssid:JSON.parse(a[1]),authMode:H[a[0]],
|
||||
rssi:parseInt(a[2]),mac:JSON.parse(a[3]),channel:JSON.parse(a[4])})},function(d){a(null,b)})})};exports.getIP=function(a){var b={};f.cmd("AT+CIFSR\r\n",1E3,function h(d){if(void 0===d)a("Timeout");else{if("+CIFSR:STAIP"==d.substr(0,12))b.ip=d.slice(14,-1);else if("+CIFSR:STAMAC"==d.substr(0,13))b.mac=d.slice(15,-1);else if("OK"==d){a(null,b);return}return h}})};exports.setIP=function(a,b){if("object"==typeof a&&a.ip){var c=[JSON.stringify(a.ip)];a.gw&&(c.push(JSON.stringify(a.gw)),c.push(JSON.stringify(a.netmask||
|
||||
"255.255.255.0")));c="AT+CIPSTA_CUR="+c.join(",")+"\r\n";var d=3E3}else c="AT+CWDHCP_CUR=1,1\r\n",d=2E4;f.cmd(c,d,function(a){if("OK"==a)b(null);else return b("setIP failed: "+(a?a:"Timeout"))})};exports.getAPIP=function(a){var b={};f.cmd("AT+CIPAP_CUR?\r\n",1E3,function h(d){if(void 0===d)a("Timeout");else if("OK"==d)f.cmd("AT+CIPAPMAC_CUR?\r\n",1E3,function l(d){if(void 0===d)a("Timeout");else if("OK"==d)a(null,b);else return"+CIPAPMAC_CUR"==d.substr(0,14)&&(b.mac=JSON.parse(d.substr(10))),l});
|
||||
else return"+CIPAP_CUR"==d.substr(0,10)&&(d=d.split(":"),"gateway"==d[1]&&"gw"==d[1],b[d[1]]=JSON.parse(d[2])),h})};exports.setAPIP=function(a,b){var c=[JSON.stringify(a.ip)];a.gw&&(c.push(JSON.stringify(a.gw)),c.push(JSON.stringify(a.netmask||"255.255.255.0")));f.cmd("AT+CIPAP_CUR="+c.join(",")+"\r\n",3E3,function(a){if("OK"==a)b(null);else return b("setAPIP failed: "+(a?a:"Timeout"))})};exports.setHostname=function(a,b){u(k.CLIENT,function(c){if(c)return b(c);f.cmd("AT+CWHOSTNAME="+JSON.stringify(a)+
|
||||
"\r\n",500,function(a){b("OK"==a?null:a)})})};exports.ping=function(a,b){var c;f.cmd('AT+PING="'+a+'"\r\n',1E3,function m(a){if(a&&"+"==a[0])return c=a.substr(1),m;"OK"==a?b(c):b()})};exports.turbo=function(a,b){var c=a?!0===a?921600:a:115200;f.cmd("AT+UART_CUR="+c+",8,1,0,2\r\n",500,function(a){"OK"!=a?b&&b("Baud rate switch to "+c+" failed: "+(a?a:"Timeout")):(t.setup(c,{rx:A3,tx:A2,cts:x}),b&&b(null))})};exports.debug=function(){return{wifiMode:p,connected:n,socks:e,sockData:g}}
|
||||
@ -1200,9 +1200,11 @@ static JsVar *getIPInfo(JsVar *jsCallback, tcpip_adapter_if_t interface) {
|
||||
|
||||
// Schedule callback if a function was provided
|
||||
if (jsvIsFunction(jsCallback)) {
|
||||
JsVar *params[1];
|
||||
params[0] = jsIpInfo;
|
||||
jsiQueueEvents(NULL, jsCallback, params, 1);
|
||||
JsVar *params[2];
|
||||
params[0] = jsvNewWithFlags(JSV_NULL);
|
||||
params[1] = jsIpInfo;
|
||||
jsiQueueEvents(NULL, jsCallback, params, 2);
|
||||
jsvUnLock(params[0]);
|
||||
}
|
||||
|
||||
return jsIpInfo;
|
||||
|
||||
@ -966,9 +966,11 @@ static JsVar *getIPInfo(JsVar *jsCallback, int interface) {
|
||||
|
||||
// Schedule callback if a function was provided
|
||||
if (jsvIsFunction(jsCallback)) {
|
||||
JsVar *params[1];
|
||||
params[0] = jsIpInfo;
|
||||
jsiQueueEvents(NULL, jsCallback, params, 1);
|
||||
JsVar *params[2];
|
||||
params[0] = jsvNewWithFlags(JSV_NULL);
|
||||
params[1] = jsIpInfo;
|
||||
jsiQueueEvents(NULL, jsCallback, params, 2);
|
||||
jsvUnLock(params[0]);
|
||||
}
|
||||
|
||||
return jsIpInfo;
|
||||
@ -1390,15 +1392,12 @@ static void setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) {
|
||||
|
||||
DBG(">> rc: %s\n", rc ? "true" : "false");
|
||||
|
||||
// Schedule callback
|
||||
// Schedule callback
|
||||
if (jsvIsFunction(jsCallback)) {
|
||||
JsVar *jsRC = jsvNewObject();
|
||||
jsvObjectSetChildAndUnLock(jsRC, "success",jsvNewFromBool(rc));
|
||||
JsVar *params[1];
|
||||
params[0] = jsRC;
|
||||
params[0] = rc ? jsvNewWithFlags(JSV_NULL) : jsvNewFromString("Failure");
|
||||
jsiQueueEvents(NULL, jsCallback, params, 1);
|
||||
jsvUnLock(params[0]);
|
||||
jsvUnLock(jsRC);
|
||||
}
|
||||
else {
|
||||
jsExceptionHere(JSET_ERROR, "Callback is not a function.");
|
||||
|
||||
@ -186,7 +186,7 @@ The details include:
|
||||
"name" : "disconnect",
|
||||
"generate" : "jswrap_wifi_disconnect",
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back on disconnection. The callback function receives no argument."]
|
||||
["callback", "JsVar", "An optional `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`.
|
||||
@ -198,10 +198,10 @@ Disconnect the wifi station from an access point and disable the station mode. I
|
||||
"name" : "stopAP",
|
||||
"generate" : "jswrap_wifi_stopAP",
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back on successful stop. The callback function receives no argument."]
|
||||
["callback", "JsVar", "An optional `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`.
|
||||
Stop being an access point and disable the AP operation mode. AP mode can be re-enabled by calling `startAP`.
|
||||
*/
|
||||
|
||||
/*JSON{
|
||||
@ -212,7 +212,7 @@ Stop being an access point and disable the AP operation mode. Ap mode can be re-
|
||||
"params" : [
|
||||
["ssid", "JsVar", "The access point network id."],
|
||||
["options", "JsVar", "Connection options (optional)."],
|
||||
["callback", "JsVar", "A function to be called back on completion (optional)."]
|
||||
["callback", "JsVar", "A `callback(err)` function to be called back on completion. `err` is null on success, or contains an error string on failure."]
|
||||
]
|
||||
}
|
||||
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.
|
||||
@ -237,7 +237,7 @@ Notes:
|
||||
"name" : "scan",
|
||||
"generate" : "jswrap_wifi_scan",
|
||||
"params" : [
|
||||
["callback", "JsVar", "A function to be called back on completion."]
|
||||
["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:
|
||||
@ -263,7 +263,7 @@ Notes:
|
||||
"params" : [
|
||||
["ssid", "JsVar", "The network id."],
|
||||
["options", "JsVar", "Configuration options (optional)."],
|
||||
["callback", "JsVar", "Optional function to be called when the AP is successfully started."]
|
||||
["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."]
|
||||
]
|
||||
}
|
||||
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.
|
||||
@ -291,7 +291,7 @@ Notes:
|
||||
"#if" : "defined(ESP32) || defined(ESP8266)",
|
||||
"return" : ["JsVar", "An object representing the current WiFi status, if available immediately."],
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back with the current Wifi status, i.e. the same object as returned directly. The callback function is more portable than the direct return value."]
|
||||
["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:
|
||||
@ -333,7 +333,7 @@ Note: esp8266 SDK programmers may be missing an "opmode" option to set the sta/a
|
||||
"#if" : "defined(ESP32) || defined(ESP8266)",
|
||||
"return" : ["JsVar", "An object representing the wifi station details, if available immediately."],
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back with the wifi details, i.e. the same object as returned directly. The callback function is more portable than the direct return value."]
|
||||
["callback", "JsVar", "An optional `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:
|
||||
@ -355,7 +355,7 @@ Retrieve the wifi station configuration and status details. The details object h
|
||||
"#if" : "defined(ESP32) || defined(ESP8266)",
|
||||
"return" : ["JsVar", "An object representing the current access point details, if available immediately."],
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back with the current access point details, i.e. the same object as returned directly. The callback function is more portable than the direct return value."]
|
||||
["callback", "JsVar", "An optional `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:
|
||||
@ -410,7 +410,7 @@ Restores the saved Wifi configuration from flash. See `Wifi.save()`.
|
||||
"generate" : "jswrap_wifi_getIP",
|
||||
"return" : ["JsVar", "An object representing the station IP information, if available immediately (**ONLY** on ESP8266/ESP32)."],
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back with the IP information, i.e. the same object as returned directly. The callback function is more portable than the direct return value."]
|
||||
["callback", "JsVar", "An optional `callback(err, ipinfo)` function to be called back with the IP information."]
|
||||
]
|
||||
}
|
||||
Return the station IP information in an object as follows:
|
||||
@ -430,7 +430,7 @@ Note that the `ip`, `netmask`, and `gw` fields are omitted if no connection is e
|
||||
"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", "An optional function to be called back with the the IP information, i.e. the same object as returned directly. The callback function is more portable than the direct return value."]
|
||||
["callback", "JsVar", "An optional `callback(err, ipinfo)` function to be called back with the the IP information."]
|
||||
]
|
||||
}
|
||||
Return the access point IP information in an object which contains:
|
||||
@ -450,7 +450,7 @@ Return the access point IP information in an object which contains:
|
||||
"#if" : "defined(ESP8266)",
|
||||
"params" : [
|
||||
["hostname", "JsVar", "The hostname to lookup."],
|
||||
["callback", "JsVar", "The callback to invoke when the hostname is returned."]
|
||||
["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.
|
||||
@ -466,7 +466,7 @@ Lookup the hostname and invoke a callback with the IP address as integer argumen
|
||||
"#if" : "defined(ESP8266)",
|
||||
"return" : ["JsVar", "The currently configured hostname, if available immediately."],
|
||||
"params" : [
|
||||
["callback", "JsVar", "An optional function to be called back with the hostname, i.e. the same string as returned directly. The callback function is more portable than the direct return value."]
|
||||
["callback", "JsVar", "An optional `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.
|
||||
@ -480,7 +480,7 @@ Returns the hostname announced to the DHCP server and broadcast via mDNS when co
|
||||
"#if" : "defined(ESP8266) || defined(ESPRUINOWIFI)",
|
||||
"params" : [
|
||||
["hostname", "JsVar", "The new hostname."],
|
||||
["callback", "JsVar", "An optional function to be called back when the hostname is set"]
|
||||
["callback", "JsVar", "An optional `callback()` function to be called back when the hostname is set"]
|
||||
]
|
||||
}
|
||||
Set the hostname. Depending on implemenation, 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.
|
||||
@ -513,7 +513,7 @@ The interval determines how often the time server is queried and Espruino's time
|
||||
"#if" : "defined(ESP8266) || defined(ESPRUINOWIFI)",
|
||||
"params" : [
|
||||
["settings", "JsVar", "Configuration settings"],
|
||||
["callback", "JsVar", "The callback to invoke when ip is set"]
|
||||
["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.
|
||||
@ -532,7 +532,7 @@ The `settings` object must contain the following properties.
|
||||
"generate" : "jswrap_wifi_setAPIP",
|
||||
"params" : [
|
||||
["settings", "JsVar", "Configuration settings"],
|
||||
["callback", "JsVar", "The callback to invoke when ip is set"]
|
||||
["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.
|
||||
@ -553,7 +553,7 @@ The `settings` object must contain the following properties.
|
||||
"generate" : "jswrap_wifi_ping",
|
||||
"params" : [
|
||||
["hostname", "JsVar", "The host to ping"],
|
||||
["callback", "JsVar", "A callback(time) function to invoke when a ping is received"]
|
||||
["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.
|
||||
@ -567,7 +567,7 @@ Issues a ping to the given host, and calls a callback with the time when the pin
|
||||
"generate_full" : "",
|
||||
"params" : [
|
||||
["enable", "JsVar", "true (or a baud rate as a number) to enable, false to disable"],
|
||||
["callback", "JsVar", "A callback(time) function to invoke when a ping is received"]
|
||||
["callback", "JsVar", "A `callback()` function to invoke when turbo mode has been set"]
|
||||
]
|
||||
}
|
||||
Switch to using a higher communication speed with the WiFi module.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user