Chat freely about the open source Javascript projects for ESP8266

User avatar
By Erni
#32116 This example use the Net module to fetch a text file on my server.
The server is hosted in a cluster (I think that is what is called, when several domains are hosted with the same IP number)
Therefore it is not enough to just use an IPnumber.

Code: Select allESP8266WiFi.init();
var net = require('net');
var hostname="ernstc.dk";

ESP8266WiFi.getHostByName(hostname, function(ipAddress){

  var client=net.connect({host: ESP8266WiFi.getAddressAsString(ipAddress), port:80}, function() {
   print('Connected');
   client.write('GET /esp.txt HTTP/1.1\r\nHost:' +hostname+'\r\nAccept: */*\r\n\r\n');

client.on('data', function(data) {
   print(data);
});

client.on('close', function() {
   print('Connection closed');
});
});
});