jeelabs / el-client

Arduino client for esp-link's REST, MQTT, and command interface
BSD 2-Clause "Simplified" License
83 stars 46 forks source link

REST client does not seem to return data. #23

Open Bam4d opened 7 years ago

Bam4d commented 7 years ago

I've flashed an arduino wifi with esp-link and using the el-client libs.

I'm trying to do a small REST request to a python server which should simply display "Hello, world!"

from flask import Flask, Response

app = Flask(__name__)

@app.route('/')
def index():
    resp = Response("Hello, World!")
    resp.headers['Server'] = ""
    resp.headers['Date'] = ""
    resp.headers['Content-Type'] = "text/html"
    return resp

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=80, debug=True)

The response including headers is less than 100 chars.

my el-client code is the slightly modified REST example (to support arduino serial uart interface):

#define BUFLEN 512

void loop() {
  // process any callbacks coming from esp_link
  esp.Process();

  // if we're connected make an HTTP request
  if(wifiConnected) {
    rest.get("/");

    char response[BUFLEN];
    memset(response, 0, BUFLEN);
    uint16_t code = rest.waitResponse(response, BUFLEN);
    if(code == HTTP_STATUS_OK){
      Serial.println("ARDUINO: GET successful:");
      Serial.println(response);
    } else {
      Serial.print("ARDUINO: GET failed: ");
      Serial.println(code);
    }

    delay(1000);

  }
}

I can see the requests are being logged by the python flask server. I'm expecting to see "Hello world" in my console... but I only recieve:

ARDUINO: GET successful:
H

Not sure why I only see "H" here? but I'm guessing its either the first letter of Hello or the first letter of HTTP 200 OK in the response.

tve commented 7 years ago

(Dunno whether this is still of interest, but just in case...) I am wondering what you meant by to support arduino serial uart interface. If you are using the arduino software serial interface at 9600 baud to talk to esp-link, that is not going to work. Do you have any esp-link debug log output corresponding to your issue?