MCU没有响应服务器请求,Android和NodeMCU,从服务器接收响应无法正常工作?

我在 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)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值