I am new in Arduino with the Esp8266 and wanted to build a very simple project in which I have a Heroku App. Then an Arduino ESP8266 calls an API on this Web-App and reads the data. My API is working without any problems:
from flask import Flask, request, jsonify
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def hello():
return str(datetime.utcnow())
@app.route('/api', methods=['GET'])
def api():
return jsonify({"time":str(datetime.utcnow())})
Now i want to read the data from this API on an Arduino. I don't know how to do that the right way so that's my main problem. Could anybody show me an example? What i did so far was an very simple Arduino Code based on the HTTPRequests Example in the ESP8266 library. I didn't change anything besides my wifi credentials and the host and the url and the thumprint. This is the GET-Requests:
url=/api host=https://wbot0707.herokuapp.com/api
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
The output i get in the Serial Monitor is:
09:48:41.982 -> WiFi connected
09:48:41.982 -> IP address:
09:48:41.982 -> 192.168.178.46
09:48:41.982 -> connecting to https://wbot0707.herokuapp.com
09:48:41.982 -> Using fingerprint '08:3B:71:72:02:43:6E:CA:ED:42:86:93:BA:7E:DF:81:C4:BC:62:30'
09:48:43.424 -> requesting URL: /api/
09:48:43.543 -> request sent
09:48:43.543 -> headers received
09:48:48.560 -> esp8266/Arduino CI has failed
09:48:48.560 -> reply was:
09:48:48.560 -> ==========
09:48:48.560 -> -1
09:48:48.560 -> ==========
09:48:48.560 -> closing connection
Thanks for anykind of help! And any suggtions to my code or my question (my first one ever