Skip to content

responseBody() doesn't work when the lenght of the response is larger than 1500 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexandreKueny opened this issue Nov 10, 2016 · 11 comments · Fixed by arduino-libraries/WiFi101#116

Comments

@AlexandreKueny
Copy link

AlexandreKueny commented Nov 10, 2016

It produces various results like adding parts of the header at the end of the response, or not giving the entire response.

@AlexandreKueny AlexandreKueny changed the title s responseBody() doesn't work when response's lenght larger than 1500 Nov 10, 2016
@AlexandreKueny AlexandreKueny changed the title responseBody() doesn't work when response's lenght larger than 1500 responseBody() doesn't work when the lenght of the response is larger than 1500 Nov 10, 2016
@sandeepmistry
Copy link

Hi @creends,

Could you please provide a sketch to reproduce this issues? As well as let us know what board you are using.

@AlexandreKueny
Copy link
Author

AlexandreKueny commented Nov 11, 2016

Thank's for your reply, @sandeepmistry

I'm using an Arduino MKR1000.
Also, in my case, response is a JSON.

The sketch i'm using : demo.ino.txt

@sandeepmistry
Copy link

@creends thanks.

One more question, could you please provide more details of the server you are connecting to. Maybe a Wireshark capture of the response, or the code that is is running.

PR #7 might also help with the issues you are seeing.

@AlexandreKueny
Copy link
Author

AlexandreKueny commented Nov 11, 2016

I'm connecting to my Philips Hue bridge, I don't know more usefull information about the server.
Here is a Wireshark capture : capture.zip
I noticed that it's a chunked response, maybe the problem is here.

responseBody give me that : response.txt

@sandeepmistry
Copy link

sandeepmistry commented Nov 11, 2016

Thanks!

I noticed that it's a chunked response, maybe the problem is here.

I don't think it chunk per say, they just didn't include a content length header in the response.

Did you get a chance to try the changes in PR #7?

@AlexandreKueny
Copy link
Author

AlexandreKueny commented Nov 11, 2016

Just tried #7, doesn't change anything.

Maybe chunked was not the appropriate word.
If you look in the capture file, the response is divided into 2 lines (47 and 48), that's what I was trying to say.

@sandeepmistry
Copy link

sandeepmistry commented Nov 24, 2016

I'm able to reproduce it with the master version of this library and the following Node.js code to simulate the server:

var net = require('net');

var response =
'HTTP/1.1 200 OK\r\n' +
'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n' +
'Pragma: no-cache\r\n' +
'Expires: Mon, 1 Aug 2011 09:00:00 GMT\r\n' +
'Connection: close\r\n' +
'Access-Control-Max-Age: 3600\r\n' +
'Access-Control-Allow-Origin: *\r\n' +
'Access-Control-Allow-Credentials: true\r\n' +
'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, HEAD\r\n' +
'Access-Control-Allow-Headers: Content-Type\r\n' +
'Content-type: application/json\r\n' +
'\r\n' +
'{"3":{"state":{"on":true,"bri":238,"hue":988,"sat":234,"effect":"none","xy":[0.6424,0.3332],"ct":153,"alert":"select","colormode":"xy","reachable":true},"type":"Extended color light","name":"Hue color lamp plafond","modelid":"LCT007","manufacturername":"Philips","uniqueid":"00:17:88:01:10:4b:b9:61-0b","swversion":"5.50.1.19085"},"4":{"state":{"on":true,"bri":238,"hue":988,"sat":234,"effect":"none","xy":[0.6424,0.3332],"ct":153,"alert":"none","colormode":"xy","reachable":true},"type":"Extended color light","name":"Hue color lamp mur","modelid":"LCT007","manufacturername":"Philips","uniqueid":"00:17:88:01:10:5d:96:ff-0b","swversion":"5.50.1.19085"},"5":{"state":{"on":true,"bri":238,"hue":3468,"sat":221,"effect":"none","xy":[0.6414,0.3353],"alert":"none","colormode":"xy","reachable":true},"type":"Color light","name":"Hue bloom","modelid":"LLC011","manufacturername":"Philips","uniqueid":"00:17:88:01:00:c1:c6:fa-0b","swversion":"5.23.1.13452"},"6":{"state":{"on":false,"bri":126,"hue":14957,"sat":141,"effect":"none","xy":[0.4576,0.4099],"ct":366,"alert":"none","colormode":"xy","reachable":true},"type":"Extended color light","name":"Hue color lamp entree","modelid":"LCT007","manufacturername":"Philips","uniqueid":"00:17:88:01:10:5d:91:82-0b","swversion":"5.50.1.19085"}}';

net.createServer(function (socket) {
  var request = new Buffer(0);

  socket.on('data', function (data) {
    request = Buffer.concat([request, data]);

    if (request.toString().indexOf('\r\n\r\n') !== -1) {
      console.log(request.toString());

      socket.write(response, function() {
        socket.end();
      });
    }
  });
}).listen(5000);

@sandeepmistry
Copy link

So far, I think the issue actually lies in the WiFi101 library ...

@sandeepmistry
Copy link

Definitely caused by the WiFi101 library, arduino-libraries/WiFi101#116 has a potential fix. @creends please try it out and provide your feedback.

@AlexandreKueny
Copy link
Author

So arduino-libraries/WiFi101#116 works fine for me too.
No more unwanted characters at the end of the answers, and whole responses for the longer ones.
Thank you for your help.

@sandeepmistry
Copy link

Great, there will be a new v0.11.1 release of the WiFi101 shortly that includes the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants