我在esp 8266中收到了未知数据

时间:2017-07-28 22:01:21

标签: reset esp8266 usart

我需要在esp8266上传我自己的程序,我试图上传一个程序进行测试,我看到esp重置可能是200毫秒,我接收了很多关于usart的数据,但不是我的程序中的数据。数据类似于异常和一些关于堆栈的字节以及一些关于加载和重置的数据

这是我的测试代码

#include <ESP8266WiFi.h>
#define MAX_SRV_CLIENTS 1
#define TCP_PORT (23)      

WiFiServer tcpServer(TCP_PORT);
WiFiClient tcpServerClients[MAX_SRV_CLIENTS];

IPAddress apIP(192, 168, 1, 1);
const char SSID[] = "TCPUARTBridge";  
const char PASSWORD[] = "12345678";

#define SerialDebug Serial1
#define SerialGPS   Serial

#ifndef min
#define min(x,y)  ((x)<(y)?(x):(y))
#endif

void setup() {
SerialDebug.begin(115200);
SerialDebug.println("TCP <-> UART bridge");

WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(SSID, PASSWORD);

SerialGPS.begin(9600);

tcpServer.begin();
tcpServer.setNoDelay(true);
SerialDebug.print("Ready! Use 'telnet or nc ");
SerialDebug.print(WiFi.localIP());
SerialDebug.print(' ');
SerialDebug.print(TCP_PORT);
SerialDebug.println("' to connect");
}

void loop() {
uint8_t i;
char buf[1024];
int bytesAvail, bytesIn;

if (tcpServer.hasClient()) {
  for (i = 0; i < MAX_SRV_CLIENTS; i++) {
    if (!tcpServerClients[i] || !tcpServerClients[i].connected()) {
      if (tcpServerClients[i]) 
        tcpServerClients[i].stop();
        tcpServerClients[i] = tcpServer.available();
        SerialDebug.print("New client: "); SerialDebug.print(i);
        continue;
    }
  }

  WiFiClient tcpServerClient = tcpServer.available();
  tcpServerClient.stop();
}

for (i = 0; i < MAX_SRV_CLIENTS; i++) {
  if (tcpServerClients[i] && tcpServerClients[i].connected()) {

    while ((bytesAvail = tcpServerClients[i].available()) > 0) {
      bytesIn = tcpServerClients[i].readBytes(buf, min(sizeof(buf), bytesAvail));
        if (bytesIn > 0) {
          SerialGPS.write(buf, bytesIn);
          delay(0);
        }
      }
    }
  }

  while ((bytesAvail = SerialGPS.available()) > 0) {
    bytesIn = SerialGPS.readBytes(buf, min(sizeof(buf), bytesAvail));

    if (bytesIn > 0) {

      for (i = 0; i < MAX_SRV_CLIENTS; i++) {
        if (tcpServerClients[i] && tcpServerClients[i].connected()) {
    tcpServerClients[i].write((uint8_t*)buf, bytesIn);
        delay(0);
        }
      }
    }
  }
}

感谢您阅读本文

0 个答案:

没有答案