Chat freely about the open source Javascript projects for ESP8266

User avatar
By kolban
#32346 It is assumed (by most folks including me) that when I open a browser to that an HTTP GET request is made to that server. While this is indeed what happens, some browsers (eg. Chrome) also submit a second HTTP request which is for: This is the icon that shows in the tab bar of a browser for that site. The proper response is to return either an icon/image or to return 404 indicating not found. When we write ESP8266 web servers, we need to be cognizant of the extra request and accommodate it appropriately.

PS> I too had the 1K ZX81 and then the 16K ram-pack but I would always press too hard and the ram-pack would wobble and I'd lose my program. I then moved to the BBC model B and thought I was in heaven (colour AND sound!!!) Then the Amstrad CPC-464 ... and then the Amstrad PC512 ... then the Amiga ... and then the rest is history :-)
User avatar
By expertsetup
#43134 Hello and thank you for a great video that informed me of the Espruino runtime for ESP8266. After finding your youtube webserver video I immediately found the most current build and flashed my ESP8266 with 1v85. I was however unable to follow your link from the video as the github tree has changed since the video was posted.

In an effort to get started regardless I transcribed the code from your video and attempted to run it in 1v85.

here is the code transcript:
Code: Select allfunction beServer() {
   var http = require("http");
   var httpServer = http.createServer(function(request, response) {

      if(request.url == "/favicon.ico") {
      if(request.url == "/hello") {
        response.write("<b>Welcome</b> to ESP8266.");
      } else if(request.url == "/goodbye") {
          response.write("<b>Please</b> come back again soon.");
        } else{
          response.write("<>Sorry...</> request not valid.");
}); //end of on new browser request

  print("HTTP server active.");
} // end of beServer

var ssid = "####";
var password = "####";

// connect to access point
var wifi = require("Wifi");
print("Connecting to access point.");
wifi.connect(ssid, password, null, function(err, ipInfo) {
if (err) {
print("Error connecting.");
return;   }
   //var ESP8266 = require("ESP8266");
   print("Connected to AP.");
   //print("Webserver at http://" + ESP8266.getAddressAsString(ipInfo.ip) + ":80");

and the error:
Code: Select all>echo(0);
Connecting to access point.
Uncaught Error: Expecting options object but got String
 at line 9 col 2

Im just getting started with JS and so am unable to resolve the error source, perhaps you could offer some insight as to where I am going wrong as I just cant see it.

Im using a fresh install of 1v85 via the "combined" single flash file.
User avatar
By Bukvy
#48503 Hello, Kolban! Huge thanks for example. Can you enlight yet another detail. How to access webserver not by ip ( by hosname. I tryed wifi.setHostname("") it does not work. Thank.
User avatar
By kolban
#55384 See the following ...

It appears that setting the hostname informs your DHCP server of the hostname that the ESP8266 would "like" to have ... but this will be up to your DHCP server whether or not is made available. It is also the hostname used for "mDNS" and as such should not contain a "DNS" suffix ... so a simple hostname is what we want.