• Hi there,
    I have problem sending a http response back to the client.
    My setup is as follows: Since the WiFi module on my EspruinoWiFi is broken, I wired an external ESP8266 module to the board. I create an access point and after that an http server by calling http.createServer((req, res) => {...}).listen(80)

    Now my problem:
    When I connect to the AccessPoint and send a http GET request to my Esprunino, it gets the request data.
    But when I call res.writeHead(200, { 'Content-Type': 'text/plain'}); res.write('Foo'); res.end(); in succession the client never gets any response and the connection seems to stay open forever. Am I doing s.th. wrong?

    For debug purposes I registered Event listeners on req.on('end', () => {...}), req.on('close', () => {...}), res.on('end', () => {...}) and res.on('close', () => {...}).

    The events are getting called in the following order:

    Seems to me, that nothing is going wrong. I'm using the latest firmware (v95). Does anyone has a solution for this? Thank you in advance

  • Please could you post up the full code you used for testing, and I'll give it a try here and see if it works on a normal WiFi board.

    Recent EspruinoWiFi software now uses flow control, so you'd need to have that connected to the external module as well.

    Out of interest, what happened to your on-board ESP8266? It might be possible to re-flash it if it's a software issue.

  • Hi Gordon,
    thank you for your reply. There is no serial connection possible anymore (Over Serial2 --> Serial2.setup(9600, { rx: A3, tx : A2 });). Any AT+* command could not be sent to the board since there seem to be no connection.
    I did not try to reflash the ESP8266 onboard module.(Is there a manual for that?)
    Is there any documentation of how to connect the flow control to the external WiFi module?

    The full code is as follows:

      Serial1.setup(115200, { rx: B7, tx : B6 });
      var esp8266 = require('ESP8266WiFi');
      console.log("Connecting to ESP8266");
      var wifi = esp8266.connect(Serial1, function() {
      console.log("Connecting to WiFi");
        wifi.reset(() => {
         /*Does not close all sockets, I assume --> CIPServer creation fails after some restarts of the Espruino*/
          console.log('Reset WiFi');
          console.log('Creating access point');
          wifi.createAP('BLA', '12345678', 1, 0, (err) => {
            if (err) {
              console.log('An error occured:');
            console.log('Access Point created');
            require('http').createServer((req, res) => {
              req.on('end', function() {
                console.log('request stream end (http.incomingMessage stream)');
              res.on('end', function() {
                console.log('response finish (http.serverResponse)');
              req.on('close', function() {
                console.log('request close (http.incomingMessage)');
              res.on('close', function() {
                console.log('response close (http.ServerResponse)');
              console.log('Request Headers:');
              console.log('Request Method:');
              var a = url.parse(req.url, true);
              res.writeHead(200, {'Content-Type': 'text/plain'});
            console.log('Http server created');
  • Do you have any idea what happened to the ESP8266 module to make it nonresponsive? If you're using Serial2 yourself you'd have to power the on-board ESP8266 on with digitalWrite(A13,1);digitalWrite(A14,1).

    There is some info about firmware upgrades here: http://www.espruino.com/ESP8266#firmware­-versions


    If you're using ESP8266WiFi then you don't have to worry about flow control. Are you sure you shouldn't be using ESP8266WiFi_0v25? It seems like it'd be rare than anyone is using the older module firmwares now.

  • Hi Gordon,
    I used the ESP8266WiFi_0v25 module and it works once now :) So when I power down my Espruino and power it up again, one request gets executed flawlessly. Any succeeding request gets stuck as before. But it's more than before. I will try whether I powered the integrated board down accidentially.

  • Hi Gordon, the A13 and A14 set to high seemed to work for the WiFi module. But now I get the following error: "Pin A3 is not capable of USART1 RX". It does not make any difference when I do the Serial setup by myself or just take the EspruinoWifi module. Do you have any idea, what happened here?

  • Hi Gordon, I got it working.
    What did I do:

    • Use the ESP8266WiFi_0v25 library and connect to the onboard wifi controller. (Do manual Serial configuration as stated above)
    • Moved from latest travis build to normal v95 build.
    • Reinstalled the WebIDE since it was somehow responsible for not being able to load any module anymore (checked offline mode - it was off)
    • And now: it works like a charm.

    My problem with this HTTP stuff was related to the external ESP8266 in my opinion.

    Thank you very much for your immediate help.

  • No problem - glad you got it sorted! So the onboard ESP8266 is fine? Wouldn't it work with the normal EspruinoWiFi library? http://www.espruino.com/WiFi#using-wifi

    Thanks for letting me know about the Pin A3 is not capable of USART1 RX error on latest builds. I just fixed it, so latest builds should work again.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

EspruinoWifi + ESP8266 external board http server sends nothing

Posted by Avatar for llakie @llakie