概述
我在 Android 上编写了一个应用程序,它实现了向服务器发送简单的请求(使用 Volley ) . 服务器站在NodeMCU(ESP8266)微控制器上,用 Lua 编写 . 问题是,在发送请求后,应用程序并不总是能够打印响应 . 如果地址是例如“http://www.google.com " it correctly sends request and receive and display response, but if it is the address from the code below - it correctly sends request (the server reacts) but does not (?) receive response (does not display it, displays: "那没用!”) . 您有任何想法,我该如何解决它并能够打印回复?
Android (part responsible for sending requests):
buttonSynchro.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Instantiate the RequestQueue.
String url = "http://192.168.1.12/";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
testTextView.setText("Response is: "+ response.substring(0,500));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
testTextView.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(SettingsActivity.this);
queue.add(stringRequest);
}
});
NodeMCU, Lua:
station_cfg={}
station_cfg.ssid="Dom"
station_cfg.pwd="lalala"
wifi.sta.config(station_cfg)
function receive(conn, request)
print(request)
print()
local buf = "";
buf = buf.."";
buf = buf.."
ESP8266 Web Server
";buf = buf.."";
conn:send(buf);
conn:on("sent", function(sck) sck:close() end);
collectgarbage();
end
function connection(conn)
conn:on("receive", receive)
end
srv=net.createServer(net.TCP, 30)
srv:listen(80, connection)
最后
以上就是苗条月饼为你收集整理的MCU没有响应服务器请求,Android和NodeMCU,从服务器接收响应无法正常工作? ESP8266 Web Server的全部内容,希望文章能够帮你解决MCU没有响应服务器请求,Android和NodeMCU,从服务器接收响应无法正常工作? ESP8266 Web Server所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复