Chat freely about the open source Javascript projects for ESP8266

User avatar
By kolban
#32254 Howdy @jankop,
A new build is now available at https://github.com/espruino/EspruinoBui ... er/ESP8266 which hopefully addresses the issue of no callback when either a bad AP password or a bad AP SSID was supplied. If all has gone well, the callback will now be called in these instances and the `err` parameter will not be null and contain a reason description.

To know exactly which build you are using, see the README.md at the builds page to learn how to find "BUILD_DATE" and "BUILD_TIME". Please don't hesitate to post back if you still have problems or questions ... we are very much here to help as we can.
User avatar
By tj4shee
#34203 Hi, I am new to using (attempts anyway) Espruino on the ESP.... I am using an ESP-01.. and loaded the 11/14 binaries into it....

I am also using the Espruino Web IDE on Win 10.... in a virtual machine (Web IDE not working for me on OS X).

I have the following code...... it seems to compile and load.... maybe .... I get 'module not found' for all of the 3... ESP8266, wifi and http..... and I cannot connect to the ESP-01 over the network... even though it shows connected (from my router)

Code: Select allvar esp8266 = require("ESP8266");

var wifi = require("wifi");
wifi.connect("BGDigital", "brewstergizmo");
var ipInfo = wifi.getIP();
print(esp8266.getAddressAsString(ipInfo.ip));

var http = require("http");
var httpSrv = http.createServer
(
  function(request, response)
  {
    response.write("<html><body>");
    if (request.url == "/hello")
    {
        response.write("<b>Welcome</b> to the ESP8266 test.");
    }
    else if (request.url == "/goodbye")
    {
        response.write("<b>Please</b> come back again soon.");
    }
    else
    {
        response.write("Sorry ... I didn't understand!");
    }
    response.end("</body></html>");
  }
);
httpSrv.listen(80);


I noticed one comment someplace mentioning loading main.js at 0x60000 ? but don't remember where.....

Thanks for any help ..... TJ
User avatar
By kolban
#34206 Howdy TJ,
Here is my current "be a web server" ... sample ...

Code: Select allfunction beServer() {
  var http = require("http");
  var httpServer = http.createServer(function(request, response) {
    print(request);
   
    if (request.url == "/favicon.ico") {
      response.writeHead(404);
      response.end("");
      return;
    }

    response.write("<html><body>");
    if (request.url == "/hello") {
      response.write("<b>Welcome</b> to the ESP8266 test.");
    } else if (request.url == "/goodbye") {
      response.write("<b>Please</b> come back again soon.");
    } else {
      response.write("Sorry ... I didn't understand!");
    }
    response.end("</body></html>");
  }); // End of on new browser request
 
  httpServer.listen(80);
  print("Now being an HTTP server!");
} // End of beServer

var ssid     = "sweetie";
var password = "kolbanpassword";

// Connect to the access point
var wifi = require("wifi");
print("Connecting to access point.");
wifi.connect(ssid, password, null, function(err, ipInfo) {
  if (err) {
    print("Error connecting to access point.");
    return;
  }
  var ESP8266 = require("ESP8266");
  print("Connect says that we are now connected!!!");
  print("Starting web server at http://" + ESP8266.getAddressAsString(ipInfo.ip) + ":80");
  beServer();
});


Reading through your code, I think the immediate thing I see is that you are calling

wifi.connect(SSID, Password)

and assuming that you are connected to the access point immediately onwards from there. In JavaScript, nothing blocks. What that means is the when you call "wifi.connect()" you get control back immediately and it may be some time later that the connection finally succeeds. This is why wifi.connect() can take additional parameters including a callback function which will be invoked to indicate that the outcome of the connection is known. In that callback function, you can then register a Web Server and do work. See also:

https://github.com/espruino/Espruino/bl ... r_Guide.md

If this hasn't completely solved the puzzle, post back and we can pick it up again.
User avatar
By tj4shee
#34217
kolban wrote:Howdy TJ,
Here is my current "be a web server" ... sample ...
.........

If this hasn't completely solved the puzzle, post back and we can pick it up again.



Thanks for the response and code sample.... I used your code sample as is.... except of course for changing the ssid and passkey.....

I also changed to a different usb comm adapter.... low and behold ! It compiled and loaded with NO adverse messages !

But..... when I tried to open a browser now.... it breaks.....

Here are the console messages.... hopefully it means something to you....

>echo(0);
Connecting to access point.
=undefined
Connect says that we are now connected!!!
Starting web server at http://192.168.1.103:80
Now being an HTTP server!
>
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 32412, room 16
tail 12
chksum 0xa5
ho 0 tail 12 room 4
load 0x3ffe8000, len 2140, room 12
tail 0
chksum 0xdb
load 0x3ffe8860, len 30012, room 8
tail 4
chksum 0x3d
csum 0x3d
don't use rtc mem data
Disconnected
>