Skip to content

Commit

Permalink
Espruino WiFi & ESP8266 module tweaks to allow an HTTP client while r…
Browse files Browse the repository at this point in the history
…esponding to a server
  • Loading branch information
gfwilliams committed Apr 28, 2017
1 parent 9af6dba commit b0db655
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
14 changes: 14 additions & 0 deletions boards/WiFi.md
Expand Up @@ -109,6 +109,20 @@ However *you can't use the `WiFi` module directly*, for example by using `requir
* APPEND_JSDOC: ../devices/EspruinoWiFi.js


Access Point Mode
-----------------

Espruino WiFi can be made into a WiFi access point with:

```
wifi.startAP('EspruinoAP', { password: '0123456789', authMode: 'wpa2' }, function(err) {
if (err) throw err;
});
```

See the documentation above for more information. `startAP` and `connect` can be used together to make Espruino become an access point while also connecting to another WiFi network. In that case, it'll have the DHCP-assigned IP address on the WiFi network it is connected to, and the IP address `192.168.4.1` on the access point it has created.


Tutorials
---------

Expand Down
8 changes: 5 additions & 3 deletions devices/ESP8266WiFi_0v25.js
Expand Up @@ -63,9 +63,9 @@ var netCallbacks = {
return cb;
}
if (d=="OK") {
at.registerLine(sckt+",CLOSED", function() {
at.unregisterLine(sckt+",CLOSED");
socks[sckt] = undefined;
at.registerLine(sckt+",CLOSED", function(ln) {
socks[sckt] = sockData[sckt].length?"ClosedWithData":undefined;
at.unregisterLine(ln);
});
} else {
socks[sckt] = undefined;
Expand Down Expand Up @@ -109,6 +109,8 @@ var netCallbacks = {
} else {
r = sockData[sckt];
sockData[sckt] = "";
if (socks[sckt]=="ClosedWithData")
socks[sckt] = undefined;
}
return r;
}
Expand Down
22 changes: 17 additions & 5 deletions devices/EspruinoWiFi.js
Expand Up @@ -43,10 +43,10 @@ var netCallbacks = {
socks[sckt] = true;
return cb;
}
if (d=="OK") {
at.registerLine(sckt+",CLOSED", function() {
at.unregisterLine(sckt+",CLOSED");
socks[sckt] = undefined;
if (d=="OK") {
at.registerLine(sckt+",CLOSED", function(ln) {
socks[sckt] = sockData[sckt].length?"ClosedWithData":undefined;
at.unregisterLine(ln);
});
} else {
socks[sckt] = undefined;
Expand All @@ -72,7 +72,7 @@ var netCallbacks = {
// console.log("Accept",sckt);
for (var i=0;i<MAXSOCKETS;i++)
if (sockData[i] && socks[i]===undefined) {
//console.log("Socket accept "+i,JSON.stringify(sockData[i]),socks[i]);
//console.log("Socket accept "+i,JSON.stringify(sockData),JSON.stringify(socks));
socks[i] = true;
return i;
}
Expand All @@ -90,6 +90,8 @@ var netCallbacks = {
} else {
r = sockData[sckt];
sockData[sckt] = "";
if (socks[sckt]=="ClosedWithData")
socks[sckt] = undefined;
}
return r;
}
Expand Down Expand Up @@ -299,3 +301,13 @@ exports.scan = function(callback) {
);
});
};

/** This function returns some of the internal state of the WiFi module, and can be used for debugging */
exports.debug = function() {
return {
wifiMode : wifiMode,
socks : socks,
sockData : sockData
};
};

0 comments on commit b0db655

Please sign in to comment.