For a project I'm working on, I've set up a microPython webserver on a Wemos d1 mini, with esp8266 chipset. The webserver takes GET requests when you're connected to the Wemos network.
I've also created a NativeScript mobile application to interact with the webserver, code below.
The problem is that both parts work fine individually, the webserver reads manual requests to address x just fine, and the NativeScript code has been tested using an httpdump, which gets the requests including parameters just fine. However, when sending a request to the webserver from the application, the webserver does not register any requests coming in. Since both parts work fine individually, I assumed it would have to be some problem in the way the NativeScript http module sends requests vs how a manual browser request is sent, as well as how the python server registers the requests, but I can't seem to figure out the problem here.
Any help would be much appreciated!
Relevant MicroPython code for the webserver:
def setup_http(host, port):
addr = socket.getaddrinfo(host, port)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(addr)
s.listen(1)
print("listening on:", addr)
return addr, s
def get_request(s):
conn, addr = s.accept()
request = str(conn.recv(1024))[2:-1].split('\r\n')
if request:
# get request variables
parameters = get_parameters(''.join(request))
# respond and close connection
response(request, conn, status)
conn.close()
return True, addr, parameters
else:
return False
Relevant NativeScript code:
function sendRequest() {
//link has been predefined to the correct url, including parameters
httpModule.getString(link).then((r) => {
viewModel.set("getStringResult", r);
}, (e) => {
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…