SSID不会在ESP8826服务器上占据优势

时间:2018-03-04 18:50:02

标签: esp8266 arduino-ide nodemcu arduino-esp8266

提前...对不起这个问题太久了。我的问题的实质是了解两个ESP8266之间的客户端/服务器通信。目前的IDE是Arduino,但我更喜欢在Atmel Studio 7工作。我不是专业人士,我是一个业余爱好者。

Faster communication between two ESP8266 in client-server setup中的代码使Server-ESP8266能够将数据发送到Client-ESP8266。在使用此示例时,客户端似乎无法连接,因为我相信客户端无法看到服务器SSID,或者服务器SSID未被创建。

为了寻找网络,我修改了客户端代码以扫描和显示活动网络。客户端扫描结果不会显示我尝试在服务器代码中创建的新SSID。扫描结果中显示的是来自我几天前在同一组芯片上运行的服务器/客户端程序的旧SSID(下面显示的MyESPAP)。即使'断开连接也不会消除旧的SSID。结果是客户端永远不会连接并挂起"而... ... WL_CONNECTED"循环并打印" ......"到监视器,看起来像:

Nearby networks found  :4
List of surrounding Network SSIDs…:
MyESPAP
CellSpot_2.4GHz_0858*
DIRECT-ABWorkCentre 3215
NETGEAR43

Connecting..................... and on and on and on.... forever

其他研究/实验:拔掉服务器并单独运行客户端程序应该会在扫描结果中显示缺少新的或旧的SSID。但奇怪的是,在串行监视器中,客户端程序会生成重复的错误代码:

Fatal exception (0): 
epc1=0x40100003, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

首先,串行监视器结果全是乱码,直到我将波特率更改为74880 - 必须是某个默认速率。上面显示的两个响应之间的差异告诉我客户端正在感知服务器,因为行为是......不同的。再说一遍,我不知道为什么。

我已经在这里待了好几天了。最后,我想将服务器放在带有加速度计的网球拍上,并将客户端的SD卡放在边线上,以记录球拍上的G力。通过分离这两个设备,我可以将客户端/ SD卡与力隔离开来。但直到我联系起来......任何想法的朋友?

服务器代码:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
WiFiServer server(80);

void setup() 
  {
  WiFi.disconnect();
  WiFi.mode(WIFI_AP);
  WiFi.softAP("ESP123", "lol12345");//Fixed - Edited per Dan Davis comment below.
  server.begin();
  Serial.begin(9600);
  IPAddress IP = WiFi.softAPIP();
  //Serial.flush();
  Serial.println();
  Serial.print("Server IP is: ");
  Serial.println(IP);
  }

void loop() 
  {
  char ID, R, G, B, anim_ID;
  WiFiClient client = server.available();
  int data_outgoing[5] = {10, 128, 128, 123, 123};
  int mapFun[5];
  Serial.print("Sent data: ");
  Serial.print(ESP.getChipId());
  Serial.println();
  for(int i = 0; i < 5; i++)
    {
    mapFun[i] =data_outgoing[i];
    //mapFun[i] = map(mapFun[i], 0, 255, 0, 128); 
    client.print(mapFun[i]);
    Serial.print(mapFun[i]);
    }

  delay(10);
  }

客户代码:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>       //crl   If this is the Client, why not include wificlient.h?

const char* ssid = "ESP123";
const char* password = "lol12345";//Fixed - Edited per Dan Davis comment 
const char* host = "192.168.4.1";
WiFiServer server(80);

void setup(){
  int count = 0;
  Serial.begin(115200);
  delay(10);
  Serial.print("Connecting to: ");
  Serial.print(ssid);
  Serial.println();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  delay(10);
  WiFi.disconnect();      //disconnect any previous connections
  delay(1000);

  Serial.print("Nearby networks found  :");   //scan for number of nearby networks & print SSIDs
  Serial.println(WiFi.scanNetworks());
  delay(500);

  Serial.println("List of surrounding Network SSIDs…:");
  int n = WiFi.scanNetworks();
  for (int i = 0; i < n; i++)
    {
    Serial.println(WiFi.SSID(i));
    }
  Serial.println();

  WiFi.begin(ssid, password);       //connect to preferred SSID
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED)
    {
    delay(500);
    Serial.print(".");
    count++;
    }

  Serial.println();       // print SSID name,local IP allotted ,MAC address & signal strength  
  Serial.println();

  Serial.print("Connected to SSID          : ");
  Serial.println(WiFi.SSID());

  Serial.print("IP address allotted to ESP : ");
  Serial.println(WiFi.localIP());

  Serial.print("MAC Address of ESP         : ");
  Serial.println(WiFi.macAddress());

  Serial.print("Signal strength is         : ");
  Serial.println(WiFi.RSSI());

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("Time for connection(s): ");
  Serial.print(count);
  Serial.println();
  Serial.println("IP address: ");
  Serial.print(WiFi.localIP());
  Serial.println();
}

void loop()
  {
  WiFiClient client;

  if((client.connect(host, 80)))
    {
    //  Serial.println("Connected");
    //  Serial.print(host);
    //  Serial.println();
    }

  String data;
  data = client.readStringUntil('\n');
  //Serial.println(data);

 for(int i = 0; i< 100; i++)
    {
    Serial.write(data[i]);
    Serial.print(data[i]);
    }
  } 

0 个答案:

没有答案