server cause reboot

Hi, I'm trying to use one ESP like a server and another one like client connecting with the AP of the server one. After the response of the server, after 20 seconds, server reboot. Is this a timeout ? why cause a reboot?
I've used the simply example from the API reference to create server and client only to try, connecting the client to AP and send a Http.request(). I've try keeping enable and disable WIFI, but it's the same.
thanks

Comments

  • adminadmin Dublin, Ireland

    What firmware are you using? Could you try the latest version, please:
    https://backend.cesanta.com/devel/mongoose-iot-esp8266-last.zip

  • I've try the Beta3 and the last, it's the same.
    The last have also the problem that after the configuration of a Wifi connection make almost 10 reboot continuosly.
    I think the problem is client side and 'chunked '.
    After a simply post request sometimes the client lose connection( ip=undefined) and after 10 sec server reboot. Sometimes server trunk the answer and client side i receive a 'cb throw exception', server reboot and client reboot.
    I've try send post with an app and the connection is stable and the transfer-encoding is 'identify' and not 'chunked ' like mongoose-client.

  • Hi, I'm trying again to use one ESP like server and one like client to pass POST data, with the last fw. Server side is ok, if I try with an app that send POST I'm able to receive, but if I send POST from another ESP , I receive a truncated POST server side, after some second server reboot and client side I receive a cb throw exeption. Now I think it's a problem of a client script, but it's similar to your example and I'm able to send( only changing address and header like server require) to my server. It's strange that server reboot if it's a problem of client , what you think could be? Thanks
  • apmascalabsapmascalabs Italy
    edited July 2016

    Hi, I'm here again with the same problem:
    One NodeMCU board with AP enable and a wifi active connection to my modem.
    the other one is a ESP-12 connected to the AP of the first one.
    this is the script for the first (server):

    `print("Server start listening on port 69..");
    var server = Http.createServer(function(req, res){

    if (req.url == '/hello') {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    print('request');
    print(req);
    print('inizio response');
    print(res);
    res.end('res.end');
    print('end');
    

    } else {
    res.serve({ document_root: '/tmp' });
    }
    }).listen(69);`

    and this is the client side:

    var client = Http.request({
          hostname: '192.168.4.1',
          port: 69,
          path: '/hello',
          method: 'POST',
          headers: { MyHeader: 'hi there' }
        }, function(res) {
          print('in reply handler', res);
        }).end('this is POST data');

    the console of the client give me:

    [34900/1496] $ File.eval("prclient.js");
    undefined
    [33800/1336] $ in reply handler {"body":"res.end","url":"","method":"","headers":{"Content-Type":"text/plain","Transfer-Encoding":"chunked"}} 
    in reply handler {"body":"res.end","url":"","method":"","headers":{"Content-Type":"text/plain","Transfer-Encoding":"chunked"}}

    the console of the server give me:
    ``Server start listening on port 69..
    undefined
    [31524/1096] $ request
    {"body":"this is POST data","url":"/hello","method":"POST","headers":{"Transfer-Encoding":"chunked","MyHeader":"hi there","Host":"192.168.4.1"}}
    inizio response
    {"_whd":true,"_r":{"body":"this is POST data","url":"/hello","method":"POST","headers":{"Transfer-Encoding":"chunked","MyHeader":"hi there","Host":"192.168.4.1"}},"_c":[foreign_0x3fff4cf4]}
    end
    `
    The blue led on the board remains on, the client loose connecction to the AP and after about ten seconds server reboot.

    if I send POST with an app on iPhone to 'http://192.168.4.1:69/hello' after a connection to the AP of the server, I find this on the console of the server:

    [33532/944] $ File.eval("httpServer_ex.js");
    Server start listening on port 69.. 
    undefined
    [30120/1336] $ request 
    {"body":"","url":"/hello","method":"POST","headers":{"User-Agent":"Rest%20Client/1.2 CFNetwork/758.4.3 Darwin/15.5.0","Connection":"keep-alive","Accept":"*/*","Accept-Language":"it-it","Content-Length":"0","Content-Type":"application/x-www-form-urlencoded","Accept-Encoding":"gzip, deflate","Host":"192.168.4.1:69"}} 
    inizio response 
    {"_whd":true,"_r":{"body":"","url":"/hello","method":"POST","headers":{"User-Agent":"Rest%20Client/1.2 CFNetwork/758.4.3 Darwin/15.5.0","Connection":"keep-alive","Accept":"*/*","Accept-Language":"it-it","Content-Length":"0","Content-Type":"application/x-www-form-urlencoded","Accept-Encoding":"gzip, deflate","Host":"192.168.4.1:69"}},"_c":[foreign_0x3fff393c]} 
    end 
    request 
    {"body":"","url":"/hello","method":"POST","headers":{"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69","Connection":"keep-alive","Content-Length":"0","Origin":"null","Accept-Language":"it-it","Accept-Encoding":"gzip, deflate","Content-Type":"application/x-www-form-urlencoded","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host":"192.168.4.1:69"}} 
    inizio response 
    {"_whd":true,"_r":{"body":"","url":"/hello","method":"POST","headers":{"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69","Connection":"keep-alive","Content-Length":"0","Origin":"null","Accept-Language":"it-it","Accept-Encoding":"gzip, deflate","Content-Type":"application/x-www-form-urlencoded","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host":"192.168.4.1:69"}},"_c":[foreign_0x3fff4fd4]} 
    end

    and on the phone(client) I can see:
    '
    http://192.168.4.1:69/hello
    Status Code: 200
    Response Headers
    Transfer-Encoding=Identity
    Content-Type=text/plain
    '
    and the response is the response writed on the server script: res.end (used for debug).

    with this POST from the phone client app the server not reboot.
    I really don't understand where s the problem.
    Could you help me ,please?
    Thanks!

  • Hi, have someone see something about my problem?

    I've try also send POST with 'postman' and everything it's ok.
    I've try to not connect to the AP but using the IP of my modem but it's the same: the POST arrive and the server respond , but the blue led of the server stay on, the client loose connection and server reboot. Only with other ESP used like client.
    It's maybe something wrong with the client script?
    Strange because I'm able to send POST to other server.
    Thanks

  • apmascalabsapmascalabs Italy
    edited August 2016

    Hi Sergey, how You told me I post the netcat results:

    if I use Postman I obtain this answer on a netcat server:

    andrea@debian:~$ nc -l -p 9999 
    POST / HTTP/1.1
    Host: 192.168.0.10:9999
    Connection: keep-alive
    Content-Length: 12
    Cache-Control: no-cache
    Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
    Content-Type: text/plain;charset=UTF-8
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36
    Postman-Token: 25a15a0c-a2fd-48e1-dcd4-0102d7daecd9
    Accept: */*
    Accept-Encoding: gzip, deflate
    Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
    
    postman test
    

    --
    if I use nodeMCU board with this script:

    Http.request({
          hostname:'192.168.0.10',
         port: 9999,
        //  path: '/hello',
          method: 'POST',
          headers: { 
                     MyHeader:'Hi'
                    }
        }, function(res) {
          print('in reply handler', res);
        }).end('this is POST data');`
    
    I receive this:
    `andrea@debian:~$ nc -l -p 9999 
    POST / HTTP/1.1
    Host: 192.168.0.10
    MyHeader: Hi
    Transfer-Encoding: chunked
    
    11
    this is POST data
    0
    

    --

    if I use this script:

    function send(){
    var post_data = "test";
    var post_data_length = post_data.length;
    
    var post_options = {    
                hostname:"192.168.0.10",
                            port:9999,
                            //path:"/hello",
                method:"POST",
                headers:{
                    "Content-Type":"text/plain",
                            "Content-Length":""+post_data_length }
                       };
    
    client_obj = Http.request(post_options, function(cb){print(cb);});
    
    client_obj.write(post_data);
    
    client_obj.end();
    
    
    console.log("*** CONSOLE LOG START ***");
    console.log("post_data_length: " + post_data_length);
    console.log(post_options,post_data);
    console.log("*** CONSOLE LOG END ***");
    };
    send();
    

    I receive this:

    andrea@debian:~$ nc -l -p 9999 
    POST / HTTP/1.1
    Host: 192.168.0.10
    Content-Length: 4
    Content-Type: text/plain
    Transfer-Encoding: chunked
    
    4
    test
    0
    

    Maybe I'm wrong, but the only thing that I did not expect was to find 'Transfer-Encoding: chunked' also with the second script.
    Is not true that giving the data-length , transfer is not chunked?

    thanks !

  • Hi Sergey, have you find something for the solution of my reboot problem? Thanks!
  • Hi,have you some news?

    thanks!

  • Hi , I've tried also the last fw but nothing change: if the client is another ESP , the other device with the server script , reboot. Client script work right with every other server , Server script work right with every other client. Thanks
  • SergeySergey Dublin, Ireland

    Thanks Andrea.
    Could you post the server script please?

  • Hi Sergey, this is the simple server script, already posted on 18 of July:

    print("Server start listening on port 69..");
var server = Http.createServer(function(req, res){
    if (req.url == '/hello') {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    print('request');
    print(req);
    print('inizio response');
    print(res);
    res.end('res.end');
    print('end');
    } else {
res.serve({ document_root: '/tmp' });
}
}).listen(69);

    If I use postman and I send to this server there is no problem.
    If I use an app with the POST options there is no problem .

    Only If I send with a Mongoose client with the script described in my other post server reboot. The client script is the same used for netcat test.

    Thanks!

  • Hi,
    again I take this discussion to say that I found the problem of restarting the ESP server.
    I removed the "response_obj.serve (optional_conf_obj)" from the server device script and now the esp8266 will no longer reset after sending the response to the client.
    The link for this struct is not correct , in your doc where I've find the example , at :
    https://github.com/cesanta/mongoose-os/blob/1.1/docs/javascript-api/http.md
    you give this address:
    https://docs.cesanta.com/mongoose/latest/#/c-api/http.h/struct_mg_serve_http_opts/
    but the doc is in :
    /c-api/http_server.h/struct_mg_serve_http_opts.md,

    anyway in "mongoose" , not in "mongoose-os" , so is not for mongoose-os,right?

    thanks

Sign In or Register to comment.