首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在两个ESP8266之间传输数据

无法在两个ESP8266之间传输数据
EN

Stack Overflow用户
提问于 2016-06-29 12:01:41
回答 1查看 1.5K关注 0票数 1

我试图使用E 8266 (Wi-fi)模块作为热点(服务器)模块,使用ESP12 E 模块8266e 29连接,而其他is (客户机).I使用e 110Arduino IDEe 211进行编程。

我的服务器正常启动,客户端连接到服务器,但是当我将数据从客户端发送到服务器时,我什么也得不到。我谷歌关于客户端和服务器之间的数据传输,但没有任何客户端数据传输使用Arduino编码。

这是我在Arduino中的代码

服务器端代码

代码语言:javascript
复制
#include <ESP8266WiFi.h>

WiFiServer server(80);        //Initialize the server on Port 80

void setup() 
{

  WiFi.mode(WIFI_AP);                              // ESP8266-12E is an AccessPoint 
  WiFi.softAP("11111111", "12345678");            // Provide the (SSID, password)  
  server.begin();                                // Start the Server
  Serial.begin(115200);                         //Start communication between the ESP8266-12E and the monitor window
  IPAddress HTTPS_ServerIP= WiFi.softAPIP();   // Obtain the IP of the Server 
  Serial.print("Server IP is: ");             // Print the IP to the monitor window 
  Serial.println(HTTPS_ServerIP);

}

void loop()
{
   WiFiClient client = server.available();
   if (!client)
    { 
       return; 
    } 
   //Looking under the hood 
   Serial.println("Somebody has connected :)"); 
}

客户端代码

代码语言:javascript
复制
#include <ESP8266WiFi.h>


const char *ssid = "11111111";
const char *password = "12345678";
const char *host = "192.168.4.2";
const int httpPort = 80;

void setup() 
{
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid); 
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


void loop()
{
  delay(8000);
  Serial.print("connecting to ");
  Serial.println(host);
  WiFiClient client;
  client.connect(host,httpPort);
  if (!client.connect(host,httpPort))
  {
    Serial.println("connection failed");
    return;
  }
  else
   client.print("connected");
}

有谁能建议我如何将数据从客户端传输到服务器?

EN

回答 1

Stack Overflow用户

发布于 2016-06-29 16:55:17

Arduino ESP8266类WiFiClient继承自Stream,因此所有流函数都可供您使用。您可以找到该类这里的文档。

您可以使用readBytesreadString或普通的read来做您想做的事情。

此外,如果您确实计划使用HTTP,您可能会对使用随您的ESP8266WebServer Arduino环境附带的库ESP8266和ESP8266HTTPClient感兴趣,并实现许多您正在尝试编写的低级代码。您可以找到服务器这里和客户机这里的示例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38098951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档