I have an esp8266 connected to wifi and I want it to send/get data from a Flask webserver hosted by eu.pythonanywhere.com.
I am using the Arduino IDE to communicate with the esp8266 via a USB to UART converter.
When using AT+CIPSTART to create a tcp connection, it connects correctly but when i try to send a get request : GET / HTTP/1.1 or GET /?data=2 HTTP/1.1using AT+CIPSEND i get "SEND OK" but then no answer from the server. Adding "\r\n" to the end of the request gets me a 400 Bad Request error.
I also tried using AT+HTTPCLIENT but the esp8266 just gives me "ERROR"
Here is my python code for the server:
from flask import Flask,request
app = Flask(__name__)
@app.route('/',methods = ['POST','GET','PUT'])
def hello_world():
data = '0'
if request.method == 'PUT':
data='1'
#data = request.json['data']
elif request.method == 'GET' :
data = request.args.get('data')
#return "0"
return data
I have tried the PUT,POST, and GET methods but i didn't manage to get any of them working. I've also tried to send a GET request to other websites such as www.google.com with no response.
However when i send something like "hello" or smth that is not a http request, i get a 400 Bad Request response from the server.
I should mention that I'm not really used to deal with http requests.
Thank you for your time.