Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

HTTP Request response unreliable

mobilefirstmobilefirst Germany
edited August 2016 in Mongoose OS

Hi Cesanta Team,

we use a function like below. Sometimes the request works as expected
but sometimes the response is kind of broken and the device start to reboot. Any idea what the problem is ?

function HttpRequest(body, cb) {
        Http.request({
            hostname: 'xx.196.8.xx',                        
            port: 8545,
            path: '/',
            method: 'POST',
            headers: { 
                "Content-Type": "application/json", 
                "Content-Length": body.length    
            }
        }, function(response) {    
            print('response: ', response);                                                           
            try {
                respobj = JSON.parse(response.body);
                cb(respobj)
            } catch(err) {
                print('error in response. can not parse reponse: ', response);
                cb([])
            }            
        })
        .write(body, "utf8")        
        .end(print('HttpRequest finished'))
        .setTimeout(5000, function() {
            print('HttpRequest aborted after timeout')
            this.abort(); 
            cb([]);  
        });
     }

Best regards

Juergen

Comments

  • SergeySergey Dublin, Ireland

    Hi,
    This is most probably a memory issue. HTTP reply gets fully buffered, and if it's big, it OOMs the device.
    Can you reproduce a problem with a very small responses, sent unfrequently?

    Anyway, I suggest you to build a firmware with JavaScript off. You can see an example at https://github.com/cesanta/mongoose-iot/tree/master/fw/examples/c_network

  • Hi Sergey,

    the first reply from the server is very small. What is very weird is the fact than sometimes it works well and if it works we get much more data from the server.

    What do you mean "I suggest you to build a firmware with JavaScript off" ? We nedd to develop in javascript.

  • SergeySergey Dublin, Ireland

    C API gives you better control on memory usage, you can track available RAM as data comes in from the network. JS API does not provide that ability.

  • We can not develop in C if we started to develop in JS. Why Cesanta offer a JS Framework if you recommend to use C. We just call a JSON RPC und the amount of data is very small. The same code work on Node JS very well. Why the module with Mongoose IoT crashes unintentionally remains a mystery.

  • SergeySergey Dublin, Ireland

    If you share your JS code, we can show the corresponding C code and build a respective binary firmware - just to test to make sure JS engine is not responsible for the crash.

Sign In or Register to comment.