-->
Page 1 of 1

ESP8266 don't receive GET response from Node.js

PostPosted: Tue Oct 18, 2016 1:31 pm
by Luiz Henrique
0
down vote
favorite
i don't response from GET request, send from ESP8266 + Arduino Mega to Node.js. My code in node receive the request, but i don't get nothing in Arduino Code.

Node.js

Code: Select allapp.get('/StatusSaidas', function(req,res){
    res.charset = 'UTF-8';
    console.log('Send to Arduino: ' + statusArdu);
    res.send(statusArdu);
});


Console log from Node.js
http://imgur.com/a/rKxYy

Code in Arduino

Code: Select alluint8_t buffer[1024] = {0};
  if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
    Serial.print("Connection with Host OK!\r\n");
  } else {
    Serial.print("Error to connected to Host!\r\n");
  }
  char *ComandoGET = "GET /StatusSaidas HTTP/1.1\r\nHost: SmartHouse\r\nConnection: close\r\n\r\n";
  wifi.send((const uint8_t*)ComandoGET, strlen(ComandoGET));

  uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
  char *resposta = buffer;
  for (int i = 0; i < len; i++)
  {
    if (strncmp(resposta++, "\r\n\r\n", 4) == 0) break;
  }
  resposta += 3;
  receive = resposta;
  Serial.print(receive);
  Serial.print("\n\r");


Then the esp don't receive the answer, but the Node.js send strings like a: {QTD1LAMP, ON}
I don't know what is the problem with my code. Using ESP8266 with Arduino Mega

Re: ESP8266 don't receive GET response from Node.js

PostPosted: Tue Oct 18, 2016 3:14 pm
by popcorn
Code: Select allres.end()


In your node.js??

Re: ESP8266 don't receive GET response from Node.js

PostPosted: Tue Oct 18, 2016 3:31 pm
by Luiz Henrique
popcorn wrote:
Code: Select allres.end()


In your node.js??


Srry, i don't understand

Re: ESP8266 don't receive GET response from Node.js

PostPosted: Wed Oct 19, 2016 6:07 am
by popcorn
I think your node.js is not closing the http connection and 'thinks' your not ready with sending your data. I'm not sure

Code: Select allapp.get('/StatusSaidas', function(req,res){
    res.charset = 'UTF-8';
    console.log('Send to
ARDUINO
: ' + statusArdu);
    res.send(statusArdu);
/// ADD THIS
    res.end();
/// ADD THIS ?
});


Did you try this code?

And did you try to get the page with your webbrowser from youre node.js program?