完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我想在 Android 手机和以 AP 模式运行的 ESP8266 之间设置一个 tcp 套接字连接。
这是我目前使用的代码: 代码:全选/* Create a WiFi access point and provide a web server on it. */ #include #include #include /* Set these to your desired credentials. */ const char *ssid = "JP_TestAP"; int status = WL_IDLE_STATUS; boolean alreadyConnected = false; // whether or not the client was connected previously WiFiServer server(23); void setup() { delay(1000); Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid); delay(10000); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); Serial.println("nStarting server..."); // start the server: server.begin(); } void loop() { // wait for a new client: WiFiClient client = server.available(); // when the client sends the first byte, say hello: if (client) { if (!alreadyConnected) { // clead out the input buffer: client.flush(); Serial.println("We have a new client"); client.println("Hello, client!"); alreadyConnected = true; } if (client.available() > 0) { // read the bytes incoming from the client: char thisChar = client.read(); // echo the bytes back to the client: server.write(thisChar); // echo the bytes to the server as well: Serial.write(thisChar); } } } 这段代码“几乎”有效…… 我的 Android 发现了 AP,我可以连接 我也可以在端口 23 上打开一个套接字,IP 为 192.168.4.1 ESP 将“Hello Client”消息发回 android。 问题是,如果我尝试从 Android 向 ESP 发送消息,则什么也没有发生…… 这是日志 代码:全选Configuring access point...AP IP address: 192.168.4.1 Starting server... We have a new client 应该有一个明显的错误,但我找不到在哪里...... |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
945 浏览 0 评论
1672 浏览 0 评论
请问一下我想用ESP8685直接替换ESP8266而不用写程序,可以让ESP8685直接通过之前ESP8266的外挂的flash运行程序吗
1330 浏览 1 评论
1233 浏览 1 评论
5021 浏览 2 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
1253浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
927浏览 3评论
2338浏览 3评论
ESP-IDF的VScode插件的build按钮点击会报错的原因?
2526浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
1052浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 05:16 , Processed in 1.015784 second(s), Total 69, Slave 52 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
494
