nodemcu v2 espruino wifi problem

Posted on
  • Hi, I have a small app with rest api deployed on NodeMcu with Espruino. App works fine and is able to successfully reconnect NodeMcu to wifi router after turning router off and on. I tested it several times. I use console.log to log all important information. The problem is that after some time (for example one day) NodeMcu loses wifi connection and is not able to reconnect to wifi. I would like to find the root cause of this problem. When the problem occurs I'm not able to connect to NodeMcu using telnet. I need to disconnect usb power supply and connect my laptop to this board. Is it possible to read/display somehow logs written earlier using console.log? If not maybe I could use some physical file instead of console.log for logging information and display its content later? Is it possible to use "fs" module?

  • hi @Michal,

    wifi tries to reconnect if connection is lost.
    maybe you are running into a out of socket error or something else
    do you like to share your code?

    fs is to large for ESP8266 boards, use Storage and same name or use a numeric like 00000001 to 99999999. for numeric name use esptool.py to dump save area to file and analyse with strings or hexdump.

  • Hi @MaBe

    Thank you very much for your precise reply. I added log functionality to my application using recommended by you Storage module. Thanks to it when I'm connecting using telnet I'm able to:

    • printLog() - display all logged information (even logged before nodemcu restart)
    • clearLog() - clear all log entries
      I'm attaching my application code. Now I'm able to check what is going on when the problem occurs. Thanks a lot for your help.

    1 Attachment

  • Nice, thanks for sharing, will run some test and let you know how it works on my side

    There are some technical details you might like to add log too:

    // free heap space
    require('ESP8266').getState().freeHeap
    // free jVars
    process.memory().free
    
  • Thanks. I will add this memory info to my log and additionally timestamp at the beginning of each line.
    Below sample curl calls (in my app I have D1 and D2 configured as relays and D5 as temperature sensor):
    1) curl -X GET http://nodemcuip -H "Content-Type: application/json"
    result:
    {"error":"","result":{"D1":0,"D2":0,"D5"­:22.75}}
    2) curl -X POST http://nodemcuip -H "Content-Type: application/json" -d '{"D1":"1", "D2": "0"}'
    turns on D1 relay and turns off D2 relay.

  • here is my suggestion: extend your header like this to be sure that the client is not blocking a socket

    header = {}; 
    //tell client  to close the connection
    header['Connection'] =  'close' ;   
     .....
    res.writeHead(200, header);
    res.end();
    

    You can also send a tiny page to let the browser know that there is no need to call for a favicon.

    page = `<!DOCTYPE html>
      <head><link rel="icon" href="data:,"></head>
    <body></body></html>`;
    ....
    res.end(page);
    

    Hope this is helpful to make your Espruino app more stable and think about how cool it would be to have a label (Donated/Patreon) below your tag ;-)

  • Here is the reason why 'close' is helpful when connection via browser

    printing details on Espruino site for calling by browser

    req.headers {
      "Host": "192.168.194.139",
      "Connection": "keep-alive",       <--- reason for sending close
      "Cache-Control": "max-age=0",
      "Upgrade-Insecure-Requests": "1",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
      "Sec-Metadata": "cause=\"forced\", destination=\"document\", site=\"cross-site\"",
      "Accept": "text/html,application/xhtml+xml,applica­tion/xml;q=0.9,image/webp,image/apng,*/*­;q=0.8",
      "Accept-Encoding": "gzip, deflate",
      "Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
     }
    > 
    

    I realized this when trying to upload the code again and got a port in use error

    this is how curl handles it:

    curl -v  192.168.194.139?led1=1
    * Rebuilt URL to: 192.168.194.139/?led1=1
    *   Trying 192.168.194.139...
    * TCP_NODELAY set
    * Connected to 192.168.194.139 (192.168.194.139) port 80 (#0)
    > GET /?led1=1 HTTP/1.1
    > Host: 192.168.194.139
    > User-Agent: curl/7.54.0
    > Accept: */*
    > 
    < HTTP/1.1 200 OK
    < Server: Espruino 2v00.101
    * no chunk, no close, no size. Assume close to signal end   <----
    < 
    * Closing connection 0
    
    
  • missed E.getErrorFlags() might be of interest too.

  • As of cutting edge builds or Espruino 2v02 (when released) Connection:close is added automatically

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

nodemcu v2 espruino wifi problem

Posted by Avatar for Michal @Michal

Actions