You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Getting the Tessel device's IP address is useful for debugging and enhancing connectivity.
OS library adds this functionality.
Refactored Tutorial Code: (rename to .js to run) webserver.js.txt
Added os interface and simple loop to push the ip addresses to an array.
Added ip address to response to display the actual IP address.
Added:
var os = require('os');
// Get a list of network interfaces:
var interfaces = os.networkInterfaces();
var addresses = [];
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}
// Log the address []
console.log(addresses);
Changed:
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with "Hello from Tessel!" to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello from Tessel!\n" + addresses.join('\n'));
});
// Listen on port 8080, IP defaults to 192.168.1.101. Also accessible through [tessel-name].local
server.listen(8080);
// Put a friendly message in the terminal showing first address:
console.log("Server running at http://" +addresses[0]+ ":8080/");
The text was updated successfully, but these errors were encountered:
I'd like to suggest a modification to this page in the t2-start docs:
http://tessel.github.io/t2-start/webserver.html
Getting the Tessel device's IP address is useful for debugging and enhancing connectivity.
OS library adds this functionality.
Refactored Tutorial Code: (rename to .js to run)
webserver.js.txt
Added os interface and simple loop to push the ip addresses to an array.
Added ip address to response to display the actual IP address.
The text was updated successfully, but these errors were encountered: