Nicely spotted indeed! All working now - thanks...
For my future reference here's the final code that works (note that the res.on() events are only triggered if the server actually returns something:
var WIFI_NAME = "";
var WIFI_OPTIONS = { password : "" };
var wifi = require("EspruinoWiFi");
wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
if (err) {
console.log("Connection error: "+err);
return;
}
console.log("Connected!");
sendData();
});
function sendData() {
var content = "{module:'espruino'}";
var options = {
host: '192.168.1.66', // host ip (host name works as well)
port: 8081, // (optional) port, defaults to 80
path: '/stats/login/', // path sent to server
method: 'POST',
headers: { "Content-type" : "application/json",
"Content-length": content.length}
};
var req = require("http").request(options, function(res) {
console.log('res',res);
res.on('data', function(data) {
console.log("HTTP> "+data);
});
res.on('close', function(data) {
console.log("Connection closed");
});
});
req.on('error',function(err){
console.log(err);
});
req.end(content);
console.log("Request sent");
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Nicely spotted indeed! All working now - thanks...
For my future reference here's the final code that works (note that the res.on() events are only triggered if the server actually returns something: